keras Tensorflow教程错误,“Tensor不可散列,请使用tensor.ref()作为键”

wqsoz72f  于 2023-04-12  发布在  其他
关注(0)|答案(1)|浏览(177)

我正在使用下面链接中的colab笔记本,它工作正常。
https://www.tensorflow.org/tutorials/video/video_classification
现在我试图再次使用它,当我开始拟合模型时,我得到了下面的错误。

----> 3 history = model.fit(x = train_ds,
      4                     epochs = 5,
      5                     validation_data = val_ds, )

4 frames
/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)

我尝试禁用eager execution(代码如下),这是一个类似的错误建议,但它没有工作。我试图重新安装和导入einops也失败了。

import tensorflow.compat.v1.keras.backend as K
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
kognpnkq

kognpnkq1#

我发现TensorFlow发布了一个新版本(2.12.0)。似乎einops与新版本不兼容。
我将TensorFlow降级到2.11.0,现在它又可以工作了。
!pip install tensorflow==2.11.0

相关问题