TypeError:如果启用了Tensor相等,则Tensor无法散列.而是使用tensor.experimental_ref()作为键 [英] TypeError: Tensor is unhashable if Tensor equality is enabled. Instead, use tensor.experimental_ref() as the key

查看:542
本文介绍了TypeError:如果启用了Tensor相等,则Tensor无法散列.而是使用tensor.experimental_ref()作为键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I was trying to apply transfer learning to the InceptionV3. Here is my code:

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()

运行此代码时,在final_model = Model(inception_model.input,output=predictions)行出现以下错误:

When i run this code I am getting following error at the final_model = Model(inception_model.input,output=predictions) line:

TypeError: Tensor is unhashable if Tensor equality is enabled. Instead, use tensor.experimental_ref() as the key.

我该怎么办?

推荐答案

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

I had a similar error. In my case it was due to using an old version of Keras and Tensorflow 2 from conda. There currently is some issues preventing the use of Tensorflow 2 with current Keras via conda.

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

I created a new environment and installed using according to the Keras/Tensorflow websites (CPU only version in my case):

pip install tensorflow
pip install keras

这篇关于TypeError:如果启用了Tensor相等,则Tensor无法散列.而是使用tensor.experimental_ref()作为键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆