类型错误:如果启用了张量相等,张量是不可散列的。相反,使用 tensor.experimental_ref() 作为关键

Sab*_* 錆兎 7 python keras tensorflow

我试图将迁移学习应用于 InceptionV3。这是我的代码:

inception_model = InceptionV3(weights='imagenet',include_top=False)
output_inception = inception_model.output
output_globalavgpooling = GlobalAveragePooling2D()(output_inception)
output_dense = Dense(1024,activation='relu')(output_globalavgpooling)
predictions = Dense(1,activation='sigmoid')(output_dense)

final_model = Model(inception_model.input,output=predictions)

final_model.compile()

inception_model.summary()
Run Code Online (Sandbox Code Playgroud)

当我运行此代码时,我在该final_model = Model(inception_model.input,output=predictions)行收到以下错误:

TypeError: Tensor is unhashable if Tensor equality is enabled. Instead, use tensor.experimental_ref() as the key.
Run Code Online (Sandbox Code Playgroud)

我该怎么办?

mag*_*ern 3

我有类似的错误。就我而言,这是由于使用了旧版本的 Keras 和 conda 的 Tensorflow 2。目前存在一些问题,无法通过 conda 将 Tensorflow 2 与当前 Keras 一起使用。

我创建了一个新环境并根据 Keras/Tensorflow 网站进行安装(在我的情况下仅使用 CPU 版本):

pip install tensorflow
pip install keras
Run Code Online (Sandbox Code Playgroud)

  • 此解决方案适用于仅 CPU 版本。但不适用于支持 GPU 的版本 (4认同)