I have a dataset of tfrecords of shape (TensorShape([None, None, None, None, None]), TensorShape([None])) in which the first tensor is a video and the second tensor is the label of the video
I have 50 labels so I want to fine-tune movinet to predict the data I tried to follow the movinet tutorial but I got (ValueError: Shapes (None, 1) and (None, 50) are incompatible) when running .fit()
because I changed the num_classes to 50
HI Muhammed,
which movinet tutorial exactly did you use?
this one models/official/projects/movinet/movinet_tutorial.ipynb at master · tensorflow/models · GitHub
and the full error is
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
d:\final final code\records train.ipynb Cell 18' in <cell line: 1>()
----> 1 results = model.fit(
2 train_dataset,
3 validation_data=test_dataset,
4 epochs=1,
5 steps_per_epoch=train_steps,
6 validation_steps=test_steps,
7 callbacks=callbacks,
8 validation_freq=1,
9 verbose=1)
File d:\final final code\env\lib\site-packages\keras\utils\traceback_utils.py:67, in filter_traceback.<locals>.error_handler(*args, **kwargs)
65 except Exception as e: # pylint: disable=broad-except
66 filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67 raise e.with_traceback(filtered_tb) from None
68 finally:
69 del filtered_tb
File d:\final final code\env\lib\site-packages\tensorflow\python\framework\func_graph.py:1147, in func_graph_from_py_func.<locals>.autograph_handler(*args, **kwargs)
1145 except Exception as e: # pylint:disable=broad-except
1146 if hasattr(e, "ag_error_metadata"):
-> 1147 raise e.ag_error_metadata.to_exception(e)
1148 else:
1149 raise
ValueError: in user code:
File "d:\final final code\env\lib\site-packages\keras\engine\training.py", line 1021, in train_function *
return step_function(self, iterator)
File "d:\final final code\env\lib\site-packages\keras\engine\training.py", line 1010, in step_function **
outputs = model.distribute_strategy.run(run_step, args=(data,))
File "d:\final final code\env\lib\site-packages\keras\engine\training.py", line 1000, in run_step **
outputs = model.train_step(data)
File "d:\final final code\env\lib\site-packages\keras\engine\training.py", line 860, in train_step
loss = self.compute_loss(x, y, y_pred, sample_weight)
File "d:\final final code\env\lib\site-packages\keras\engine\training.py", line 918, in compute_loss
return self.compiled_loss(
File "d:\final final code\env\lib\site-packages\keras\engine\compile_utils.py", line 201, in __call__
loss_value = loss_obj(y_t, y_p, sample_weight=sw)
File "d:\final final code\env\lib\site-packages\keras\losses.py", line 141, in __call__
losses = call_fn(y_true, y_pred)
File "d:\final final code\env\lib\site-packages\keras\losses.py", line 245, in call **
return ag_fn(y_true, y_pred, **self._fn_kwargs)
File "d:\final final code\env\lib\site-packages\keras\losses.py", line 1789, in categorical_crossentropy
return backend.categorical_crossentropy(
File "d:\final final code\env\lib\site-packages\keras\backend.py", line 5083, in categorical_crossentropy
target.shape.assert_is_compatible_with(output.shape)
ValueError: Shapes (None, 1) and (None, 50) are incompatible
My code is here
By a brief look (can’t test it all right now) can you verify that the input you are using is the same shape as expected?
you can find this by printing the shape of your inputs and what is used in the official tutorial.
I think the problem is on the labels array
My dataset shape is (TensorShape([None, None, None, None, None]), TensorShape([None])) of types (tf.float32, tf.int64) what is the expected shape?
I one hot encoded the labels and it worked
Thanks for your help
1 Like