Video classification with a 3D convolutional neural network Tutorial Error

Hello, I was using the colab notebook in the link below and it was working fine, I also used my own data and train the same network without any problem.

Now I am trying to use it again and I am getting the error below when I start fitting the model.

“TypeError:Tensor is unhashable. Instead, use tensor.ref() as the key.”

You can see the details of the error below;

/usr/local/lib/python3.9/dist-packages/einops/einops.py in tf__reduce(tensor, pattern, reduction, **axes_lengths)
61 try:
62 hashable_axes_lengths = ag__.converted_call(ag__.ld(tuple), (ag__.converted_call(ag__.ld(sorted), (ag__.converted_call(ag__.ld(axes_lengths).items, (), None, fscope),), None, fscope),), None, fscope)
—> 63 recipe = ag__.converted_call(ag__.ld(prepare_transformation_recipe), (ag_.ld(pattern), ag__.ld(reduction)), dict(axes_lengths=ag__.ld(hashable_axes_lengths)), fscope)
64 try:
65 do_return = True

TypeError: in user code:

File "/usr/local/lib/python3.9/dist-packages/keras/engine/training.py", line 1284, in train_function  *
    return step_function(self, iterator)
File "/usr/local/lib/python3.9/dist-packages/keras/engine/training.py", line 1268, in step_function  **
    outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/usr/local/lib/python3.9/dist-packages/keras/engine/training.py", line 1249, in run_step  **
    outputs = model.train_step(data)
File "/usr/local/lib/python3.9/dist-packages/keras/engine/training.py", line 1050, in train_step
    y_pred = self(x, training=True)
File "/usr/local/lib/python3.9/dist-packages/keras/utils/traceback_utils.py", line 70, in error_handler
    raise e.with_traceback(filtered_tb) from None
File "/tmp/__autograph_generated_file01sh7f7r.py", line 22, in tf__call
    videos = ag__.converted_call(ag__.ld(einops).rearrange, (ag__.ld(images), '(b t) h w c -> b t h w c'), dict(t=ag__.ld(old_shape)['t']), fscope)
File "/tmp/__autograph_generated_filefu2t6yqk.py", line 95, in tf__rearrange
    retval_ = ag__.converted_call(ag__.ld(reduce), (ag__.converted_call(ag__.ld(cast), (ag__.ld(Tensor), ag__.ld(tensor)), None, fscope), ag__.ld(pattern)), dict(reduction='rearrange', **ag__.ld(axes_lengths)), fscope)
File "/tmp/__autograph_generated_filerptbnnwp.py", line 63, in tf__reduce
    recipe = ag__.converted_call(ag__.ld(_prepare_transformation_recipe), (ag__.ld(pattern), ag__.ld(reduction)), dict(axes_lengths=ag__.ld(hashable_axes_lengths)), fscope)

TypeError: Exception encountered when calling layer 'resize_video_2' (type ResizeVideo).

in user code:

    File "<ipython-input-4-99a2af494be2>", line 23, in call  *
        videos = einops.rearrange(
    File "/usr/local/lib/python3.9/dist-packages/einops/einops.py", line 483, in rearrange  *
        return reduce(cast(Tensor, tensor), pattern, reduction='rearrange', **axes_lengths)
    File "/usr/local/lib/python3.9/dist-packages/einops/einops.py", line 411, in reduce  *
        recipe = _prepare_transformation_recipe(pattern, reduction, axes_lengths=hashable_axes_lengths)

    TypeError: Tensor is unhashable. Instead, use tensor.ref() as the key.


Call arguments received by layer 'resize_video_2' (type ResizeVideo):
  • video=tf.Tensor(shape=(None, None, None, None, 16), dtype=float32)

@umit_akkaya,

Welcome to the Tensorflow Forum!

Thank you for reporting.

Same here! Any clue?

@NunoCGarcia, @umit_akkaya,

The issue seems to be with Tensorflow 2.12 version.

Currently as a workaround please try with TF 2.11.

Thank you!

@chunduriv i am using Tensorflow 2.11 version but still facing same issue.

did you find any clue?

The issue seems to arise from dependency hell.

A work around is to add version restriction to libraries , from trial and error, I found this to be working:

!pip install remotezip tqdm einops tensorflow==2.10.0 google-auth==2.17.3 requests==2.27.1 jedi opencv-python==4.5.5.64 -U

Note: Be sure to restart your kernel after installing these updates!

Hello I’m a beginner in deep learning could you help me with a error that I got on my code please ! This is my code
from tensorflow import keras

train_ds = keras.utils.image_dataset_from_directory(
directory=‘drive/MyDrive/LetrasVarias’,
labels=‘inferred’,
label_mode=‘categorical’,
batch_size=32,
image_size=(256, 256))
validation_ds = keras.utils.image_dataset_from_directory(
directory=‘drive/MyDrive/CarpetaCuadros’,
labels=‘inferred’,
label_mode=‘categorical’,
batch_size=32,
image_size=(256, 256))

model = keras.applications.Xception(
weights=None, input_shape=(256, 256, 3), classes=6)
model.compile(optimizer=‘rmsprop’, loss=‘categorical_crossentropy’)
model.fit(train_ds, epochs=10, validation_data=validation_ds)

And this is what a get

Epoch 1/10
19/19 [==============================] - ETA: 0s - loss: 1.3570

ValueError Traceback (most recent call last)
in <cell line: 4>()
2 weights=None, input_shape=(256, 256, 3), classes=6)
3 model.compile(optimizer=‘rmsprop’, loss=‘categorical_crossentropy’)
----> 4 model.fit(train_ds, epochs=10, validation_data=validation_ds)

1 frames
/usr/local/lib/python3.10/dist-packages/keras/engine/training.py in tf__test_function(iterator)
13 try:
14 do_return = True
—> 15 retval_ = ag__.converted_call(ag__.ld(step_function), (ag__.ld(self), ag__.ld(iterator)), None, fscope)
16 except:
17 do_return = False

ValueError: in user code:

File "/usr/local/lib/python3.10/dist-packages/keras/engine/training.py", line 1852, in test_function  *
    return step_function(self, iterator)
File "/usr/local/lib/python3.10/dist-packages/keras/engine/training.py", line 1836, in step_function  **
    outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/usr/local/lib/python3.10/dist-packages/keras/engine/training.py", line 1824, in run_step  **
    outputs = model.test_step(data)
File "/usr/local/lib/python3.10/dist-packages/keras/engine/training.py", line 1790, in test_step
    self.compute_loss(x, y, y_pred, sample_weight)
File "/usr/local/lib/python3.10/dist-packages/keras/engine/training.py", line 1109, in compute_loss
    return self.compiled_loss(
File "/usr/local/lib/python3.10/dist-packages/keras/engine/compile_utils.py", line 265, in __call__
    loss_value = loss_obj(y_t, y_p, sample_weight=sw)
File "/usr/local/lib/python3.10/dist-packages/keras/losses.py", line 142, in __call__
    losses = call_fn(y_true, y_pred)
File "/usr/local/lib/python3.10/dist-packages/keras/losses.py", line 268, in call  **
    return ag_fn(y_true, y_pred, **self._fn_kwargs)
File "/usr/local/lib/python3.10/dist-packages/keras/losses.py", line 1984, in categorical_crossentropy
    return backend.categorical_crossentropy(
File "/usr/local/lib/python3.10/dist-packages/keras/backend.py", line 5559, in categorical_crossentropy
    target.shape.assert_is_compatible_with(output.shape)

ValueError: Shapes (None, 5) and (None, 6) are incompatible

any idea ? :thinking:

@Mendoza_Perez_Cesar,

Welcome to the Tensorflow Forum!

Ensure that the number of input classes and number of classes defined in the model are same.

Thank you!

@umit_akkaya, @NunoCGarcia, @raghdah_hussain,

You can use Tensorflow 2.10 to run this tutorial. Versions above Tensorflow 2.10 may not run successfully.

!pip install remotezip tqdm opencv-python einops 
# Install TensorFlow 2.10
!pip install tensorflow==2.10.0

Please refer to the gist for more information.

Thank you!