Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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.

What should I do?

like image 503
Sabito 錆兎 stands with Ukraine Avatar asked Nov 09 '19 11:11

Sabito 錆兎 stands with Ukraine


1 Answers

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.

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
like image 72
magiclantern Avatar answered Sep 30 '22 18:09

magiclantern