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

问题描述 投票:1回答:1

我正在尝试将转移学习应用于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.

我该怎么办?

python tensorflow keras
1个回答
0
投票

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

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

pip install tensorflow
pip install keras
© www.soinside.com 2019 - 2024. All rights reserved.