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/ 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/", line 1284, in train_function  *
    return step_function(self, iterator)
File "/usr/local/lib/python3.9/dist-packages/keras/engine/", line 1268, in step_function  **
    outputs =, args=(data,))
File "/usr/local/lib/python3.9/dist-packages/keras/engine/", line 1249, in run_step  **
    outputs = model.train_step(data)
File "/usr/local/lib/python3.9/dist-packages/keras/engine/", line 1050, in train_step
    y_pred = self(x, training=True)
File "/usr/local/lib/python3.9/dist-packages/keras/utils/", line 70, in error_handler
    raise e.with_traceback(filtered_tb) from None
File "/tmp/", 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/", 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/", 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/", line 483, in rearrange  *
        return reduce(cast(Tensor, tensor), pattern, reduction='rearrange', **axes_lengths)
    File "/usr/local/lib/python3.9/dist-packages/einops/", 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)


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== -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(
image_size=(256, 256))
validation_ds = keras.utils.image_dataset_from_directory(
image_size=(256, 256))

model = keras.applications.Xception(
weights=None, input_shape=(256, 256, 3), classes=6)
model.compile(optimizer=‘rmsprop’, loss=‘categorical_crossentropy’), 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, epochs=10, validation_data=validation_ds)

1 frames
/usr/local/lib/python3.10/dist-packages/keras/engine/ 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/", line 1852, in test_function  *
    return step_function(self, iterator)
File "/usr/local/lib/python3.10/dist-packages/keras/engine/", line 1836, in step_function  **
    outputs =, args=(data,))
File "/usr/local/lib/python3.10/dist-packages/keras/engine/", line 1824, in run_step  **
    outputs = model.test_step(data)
File "/usr/local/lib/python3.10/dist-packages/keras/engine/", line 1790, in test_step
    self.compute_loss(x, y, y_pred, sample_weight)
File "/usr/local/lib/python3.10/dist-packages/keras/engine/", line 1109, in compute_loss
    return self.compiled_loss(
File "/usr/local/lib/python3.10/dist-packages/keras/engine/", line 265, in __call__
    loss_value = loss_obj(y_t, y_p, sample_weight=sw)
File "/usr/local/lib/python3.10/dist-packages/keras/", line 142, in __call__
    losses = call_fn(y_true, y_pred)
File "/usr/local/lib/python3.10/dist-packages/keras/", line 268, in call  **
    return ag_fn(y_true, y_pred, **self._fn_kwargs)
File "/usr/local/lib/python3.10/dist-packages/keras/", line 1984, in categorical_crossentropy
    return backend.categorical_crossentropy(
File "/usr/local/lib/python3.10/dist-packages/keras/", line 5559, in categorical_crossentropy

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

any idea ? :thinking:


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!