i'm trying to visualise my model, but when i'm using plot_model function of keras it's giving me error saying "'InputLayer' object is not iterable" i'm attaching my code as well as error. please help
model = tf.keras.models.Sequential([
tf.keras.layers.Conv2D(96, (5, 5), activation='relu', input_shape=(28, 28, 3), padding = 'same'),
tf.keras.layers.Conv2D(96, (5, 5), activation='relu', padding = 'same'),
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Conv2D(256, (5, 5), activation='relu', padding = 'same'),
tf.keras.layers.Conv2D(256, (5, 5), activation='relu', padding = 'same'),
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Conv2D(384, (3, 3), activation='relu', padding = 'same'),
tf.keras.layers.Conv2D(384, (3, 3), activation='relu', padding = 'same'),
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Conv2D(256, (3, 3), activation='relu', padding = 'same'),
tf.keras.layers.Conv2D(256, (3, 3), activation='relu', padding = 'same'),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(2304, activation='relu'),
tf.keras.layers.Dense(2304, activation='relu'),
tf.keras.layers.Dense(10, activation=tf.nn.softmax)
])
model.compile(optimizer=Adam(lr=0.001), loss='sparse_categorical_crossentropy', metrics=['acc'])
plot_model(model, to_file='model_plot.png', show_shapes=True, show_layer_names=True)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-92-2aa57a1383be> in <module>()
----> 1 plot_model(model, to_file='model_plot.png', show_shapes=True, show_layer_names=True)
1 frames
/usr/local/lib/python3.6/dist-packages/keras/utils/vis_utils.py in plot_model(model, to_file, show_shapes, show_layer_names, rankdir)
130 'LR' creates a horizontal plot.
131 """
--> 132 dot = model_to_dot(model, show_shapes, show_layer_names, rankdir)
133 _, extension = os.path.splitext(to_file)
134 if not extension:
/usr/local/lib/python3.6/dist-packages/keras/utils/vis_utils.py in model_to_dot(model, show_shapes, show_layer_names, rankdir)
107 node_key = layer.name + '_ib-' + str(i)
108 if node_key in model._network_nodes:
--> 109 for inbound_layer in node.inbound_layers:
110 inbound_layer_id = str(id(inbound_layer))
111 dot.add_edge(pydot.Edge(inbound_layer_id, layer_id))
TypeError: 'InputLayer' object is not iterable
Try importing from tensorflow directly:
from tensorflow.keras.utils import plot_model
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With