- 投稿日:2020-05-21T22:44:39+09:00
TensorFlow 2.0 で tf.keras.utils.plot_model() を使った時 AttributeError: 'dict' object has no attribute 'name' になるエラーとその解決法
概要
tf.keras.utils.plot_model()
使用時に以下のエラーが発生する。AttributeError: 'dict' object has no attribute 'name'マルチモデルで発生しがちらしい。以前はこんなエラー出なかったはず。
自分は GAN の Generator, Discriminator, Generator+Discriminator(combined) の三つをプロットしようとしたところ、最初の二つはエラーが出なかったが、三つ目でエラーが出た(なんで?)修正方法
通常、以下のようになっているはず。
tf.keras.utils.plot_model(model, to_file='model_img.png', show_shapes=True)これを、以下のようにリスト内包表記で一気に名前をつけ直すことで治る。
model._layers = [ layer for layer in model._layers if isinstance(layer, tf.keras.layers.Layer) ] tf.keras.utils.plot_model(model)参考
- AttributeError: 'dict' object has no attribute 'name' #38988: https://github.com/tensorflow/tensorflow/issues/38988