LoginSignup
3
1

More than 3 years have passed since last update.

TensorFlow 2.0 で tf.keras.utils.plot_model() を使った時 AttributeError: 'dict' object has no attribute 'name' になるエラーとその解決法

Last updated at Posted at 2020-05-21

概要

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)

参考

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1