我试图将转移学习应用于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.
我该怎么办?
答案 0 :(得分:1)
我有一个类似的错误。就我而言,这是由于使用了conda的Keras和Tensorflow 2的旧版本。当前存在一些问题,无法通过conda在当前的Keras中使用Tensorflow 2。
我创建了一个新环境,并根据Keras / Tensorflow网站(在我的情况下,仅使用CPU版本)进行安装:
pip install tensorflow
pip install keras
答案 1 :(得分:1)
添加到magiclantern答案中,如果您使用的是GPU,则可以使用以下命令。
pip install tensorflow-gpu
pip install keras-gpu
或者,如果您要使用某些版本,请使用以下命令
pip install tensorflow-gpu==1.15.0
pip install keras-gpu==2.3.1
这应该工作正常。
答案 2 :(得分:0)
您尝试过吗?
final_model = tf.compat.v1.keras.Model(inception_model.input,output=predictions)