keras
keras copied to clipboard
Value Error
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[244], line 1
----> 1 training_history = Plant_Detector.fit(x= training_set, validation_data = validation_set, epochs = 10)
File ~\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\keras\engine\training.py:1193, in Model.fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)
1186 with trace.Trace(
1187 'train',
1188 epoch_num=epoch,
1189 step_num=step,
1190 batch_size=batch_size,
1191 _r=1):
1192 callbacks.on_train_batch_begin(step)
-> 1193 tmp_logs = self.train_function(iterator)
1194 if data_handler.should_sync:
1195 context.async_wait()
File ~\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\eager\def_function.py:885, in Function.__call__(self, *args, **kwds)
882 compiler = "xla" if self._jit_compile else "nonXla"
884 with OptionalXlaContext(self._jit_compile):
--> 885 result = self._call(*args, **kwds)
887 new_tracing_count = self.experimental_get_tracing_count()
888 without_tracing = (tracing_count == new_tracing_count)
File ~\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\eager\def_function.py:933, in Function._call(self, *args, **kwds)
930 try:
931 # This is the first call of __call__, so we have to initialize.
932 initializers = []
--> 933 self._initialize(args, kwds, add_initializers_to=initializers)
934 finally:
935 # At this point we know that the initialization is complete (or less
936 # interestingly an exception was raised) so we no longer need a lock.
937 self._lock.release()
File ~\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\eager\def_function.py:759, in Function._initialize(self, args, kwds, add_initializers_to)
756 self._lifted_initializer_graph = lifted_initializer_graph
757 self._graph_deleter = FunctionDeleter(self._lifted_initializer_graph)
758 self._concrete_stateful_fn = (
--> 759 self._stateful_fn._get_concrete_function_internal_garbage_collected( # pylint: disable=protected-access
760 *args, **kwds))
762 def invalid_creator_scope(*unused_args, **unused_kwds):
763 """Disables variable creation."""
File ~\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\eager\function.py:3066, in Function._get_concrete_function_internal_garbage_collected(self, *args, **kwargs)
3064 args, kwargs = None, None
3065 with self._lock:
-> 3066 graph_function, _ = self._maybe_define_function(args, kwargs)
3067 return graph_function
File ~\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\eager\function.py:3463, in Function._maybe_define_function(self, args, kwargs)
3459 return self._define_function_with_shape_relaxation(
3460 args, kwargs, flat_args, filtered_flat_args, cache_key_context)
3462 self._function_cache.missed.add(call_context_key)
-> 3463 graph_function = self._create_graph_function(args, kwargs)
3464 self._function_cache.primary[cache_key] = graph_function
3466 return graph_function, filtered_flat_args
File ~\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\eager\function.py:3298, in Function._create_graph_function(self, args, kwargs, override_flat_arg_shapes)
3293 missing_arg_names = [
3294 "%s_%d" % (arg, i) for i, arg in enumerate(missing_arg_names)
3295 ]
3296 arg_names = base_arg_names + missing_arg_names
3297 graph_function = ConcreteFunction(
-> 3298 func_graph_module.func_graph_from_py_func(
3299 self._name,
3300 self._python_function,
3301 args,
3302 kwargs,
3303 self.input_signature,
3304 autograph=self._autograph,
3305 autograph_options=self._autograph_options,
3306 arg_names=arg_names,
3307 override_flat_arg_shapes=override_flat_arg_shapes,
3308 capture_by_value=self._capture_by_value),
3309 self._function_attributes,
3310 function_spec=self.function_spec,
3311 # Tell the ConcreteFunction to clean up its graph once it goes out of
3312 # scope. This is not the default behavior since it gets used in some
3313 # places (like Keras) where the FuncGraph lives longer than the
3314 # ConcreteFunction.
3315 shared_func_graph=False)
3316 return graph_function
File ~\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\framework\func_graph.py:1007, in func_graph_from_py_func(name, python_func, args, kwargs, signature, func_graph, autograph, autograph_options, add_control_dependencies, arg_names, op_return_value, collections, capture_by_value, override_flat_arg_shapes, acd_record_initial_resource_uses)
1004 else:
1005 _, original_func = tf_decorator.unwrap(python_func)
-> 1007 func_outputs = python_func(*func_args, **func_kwargs)
1009 # invariant: `func_outputs` contains only Tensors, CompositeTensors,
1010 # TensorArrays and `None`s.
1011 func_outputs = nest.map_structure(convert, func_outputs,
1012 expand_composites=True)
File ~\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\eager\def_function.py:668, in Function._defun_with_scope.<locals>.wrapped_fn(*args, **kwds)
664 with default_graph._variable_creator_scope(scope, priority=50): # pylint: disable=protected-access
665 # __wrapped__ allows AutoGraph to swap in a converted function. We give
666 # the function a weak reference to itself to avoid a reference cycle.
667 with OptionalXlaContext(compile_with_xla):
--> 668 out = weak_wrapped_fn().__wrapped__(*args, **kwds)
669 return out
File ~\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\framework\func_graph.py:994, in func_graph_from_py_func.<locals>.wrapper(*args, **kwargs)
992 except Exception as e: # pylint:disable=broad-except
993 if hasattr(e, "ag_error_metadata"):
--> 994 raise e.ag_error_metadata.to_exception(e)
995 else:
996 raise
ValueError: in user code:
C:\Users\Luvolwethu Tokwe\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\keras\engine\training.py:862 train_function *
return step_function(self, iterator)
C:\Users\Luvolwethu Tokwe\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\keras\engine\training.py:852 step_function **
outputs = model.distribute_strategy.run(run_step, args=(data,))
C:\Users\Luvolwethu Tokwe\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:1286 run
return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
C:\Users\Luvolwethu Tokwe\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:2849 call_for_each_replica
return self._call_for_each_replica(fn, args, kwargs)
C:\Users\Luvolwethu Tokwe\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:3632 _call_for_each_replica
return fn(*args, **kwargs)
C:\Users\Luvolwethu Tokwe\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\keras\engine\training.py:845 run_step **
outputs = model.train_step(data)
C:\Users\Luvolwethu Tokwe\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\keras\engine\training.py:803 train_step
loss = self.compiled_loss(
C:\Users\Luvolwethu Tokwe\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\keras\engine\compile_utils.py:204 __call__
loss_value = loss_obj(y_t, y_p, sample_weight=sw)
C:\Users\Luvolwethu Tokwe\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\keras\losses.py:155 __call__
losses = call_fn(y_true, y_pred)
C:\Users\Luvolwethu Tokwe\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\keras\losses.py:259 call **
return ag_fn(y_true, y_pred, **self._fn_kwargs)
C:\Users\Luvolwethu Tokwe\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\util\dispatch.py:206 wrapper
return target(*args, **kwargs)
C:\Users\Luvolwethu Tokwe\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\keras\losses.py:1679 categorical_crossentropy
return backend.categorical_crossentropy(
C:\Users\Luvolwethu Tokwe\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\util\dispatch.py:206 wrapper
return target(*args, **kwargs)
C:\Users\Luvolwethu Tokwe\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\keras\backend.py:4875 categorical_crossentropy
target.shape.assert_is_compatible_with(output.shape)
C:\Users\Luvolwethu Tokwe\anaconda3\envs\TFNew\lib\site-packages\tensorflow\python\framework\tensor_shape.py:1161 assert_is_compatible_with
raise ValueError("Shapes %s and %s are incompatible" % (self, other))
ValueError: Shapes (None, 9) and (None, 1024) are incompatible
Could you please provide the sample reproducible code to replicate the reported behavior. Thanks
This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.
This issue was closed because it has been inactive for 28 days. Please reopen if you'd like to work on this further.