gpt4 book ai didi

python - 无法在keras中执行plot_model

转载 作者:行者123 更新时间:2023-11-28 22:09:25 25 4
gpt4 key购买 nike

我正在尝试可视化我的模型,但是当我使用 keras 的 plot_model 函数时,出现错误提示“'InputLayer' 对象不可迭代”我附上了我的代码和错误。请帮忙

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

最佳答案

尝试直接从 tensorflow 导入:

从 tensorflow.keras.utils 导入 plot_model

关于python - 无法在keras中执行plot_model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57681910/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com