TypeError:如果启用了Tensor相等,则Tensor无法散列。而是使用tensor.experimental_ref()作为键

我试图将转移学习应用于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()

运行此代码时,我在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.

我该怎么办?

weijinyang9 回答:TypeError:如果启用了Tensor相等,则Tensor无法散列。而是使用tensor.experimental_ref()作为键

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

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

pip install tensorflow
pip install keras
,

添加到magiclantern答案中,如果您使用的是GPU,则可以使用以下命令。

pip install tensorflow-gpu 
pip install keras-gpu

或者,如果您要使用某些版本,请使用以下命令

pip install tensorflow-gpu==1.15.0
pip install keras-gpu==2.3.1 

这应该工作正常。

,

您尝试过吗?

final_model = tf.compat.v1.keras.Model(inception_model.input,output=predictions)
本文链接:https://www.f2er.com/3133056.html

大家都在问