keep-loving-pythonのブログ

Pythonを愛し続けたいです(Pythonが流行っている限りですが。。。)

解決策。TypeError: Variable is unhashable. Instead, use variable.ref() as the key.

解決策。TypeError: Variable is unhashable. Instead, use variable.ref() as the key.

エラーの内容

TypeError: Variable is unhashable. Instead, use variable.ref() as the key.

エラー詳細

Traceback (most recent call last):
  File "tf_trans.py", line 28, in <module>
    hub.KerasLayer(classifier_model, input_shape=IMAGE_SHAPE+(3,))
  File "C:\Users\XYZZ0\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_hub\keras_layer.py", line 119, in __init__
    trainable_variables = set(self._func.trainable_variables)
  File "C:\Users\XYZZ0\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\ops\variables.py", line 1082, in __hash__
    "Variable is unhashable. "
TypeError: Variable is unhashable. Instead, use variable.ref() as the key. (Variable: <tf.Variable 'MobilenetV2/expanded_conv_14/depthwise/depthwise_weights:0' shape=(3, 3, 960, 1) dtype=float32, numpy=

解決策

tensorflow-hubが古いのが原因でした。 修正前。

tensorflow                        2.9.1

tensorflow-hub                    0.5.0   <---えらく古い!!!

解決したバージョン

tensorflow                        2.9.1

tensorflow-hub                    0.12.0  <---2022/08/20 Windows10にて。

コメント

もしも、この情報が、役立ったら、、、、コメントとかいいねとか宜しくーーー。 シンプルに検索にかかるようにしておきたい、、、この記事は。