我尝试可视化我的神经网络的架构(参见下面的代码)。可视化方面的 I want to get something like this。
但我没能做到。我应该使用什么包,或者任何人都可以说明我的网络会产生什么结果?
这是我的网络的代码:
new_img_size = 128
nbr_img = 3
delta_t = 10
min_pred = 10
image1 = Input(shape=(new_img_size, new_img_size, 3))
image2 = Input(shape=(new_img_size, new_img_size, 3))
y1 = BatchNormalization()(image1)
y1 = Flatten()(y1)
y1 = Dense(1024, activation='relu')(y1)
cnn1 = Model(inputs=image1, outputs=y1)
input_sequence1 = Input(shape=(nbr_img, new_img_size, new_img_size, 3))
lstm1 = TimeDistributed(cnn1)(input_sequence1)
lstm1 = LSTM(1024, activation='relu', return_sequences=False)(lstm1)
lstm1 = Dense(48, activation='relu')(lstm1)
y2 = BatchNormalization()(image2)
y2 = Flatten()(y2)
y2 = Dense(1024, activation='relu')(y2)
cnn2 = Model(inputs=image2, outputs=y2)
input_sequence2 = Input(shape=(nbr_img, new_img_size, new_img_size, 3))
lstm2 = TimeDistributed(cnn2)(input_sequence2)
lstm2 = LSTM(1024, activation='relu', return_sequences=False)(lstm2)
lstm2 = Dense(48, activation='relu')(lstm2)
merged = concatenate([lstm1, lstm2])
mlp = Dense(96, activation='relu')(merged)
mlp = Dense(48, activation='relu')(merged)
mlp = Dense(int(min_pred/delta_t), activation='linear')(mlp)
model = Model(inputs=[input_sequence1, input_sequence2], outputs=mlp)
model.compile(optimizer="Adam", loss='mse', metrics=['mae'])谢谢你的帮助
编辑
我试过tf.keras.utils.plot_model和netron,这两个都给了我这个

我确实发现这很有用,但因为我有一层TimeDistributed,所以我希望在我的绘图中也能看到这一点。我不想只看到“时间分布”这个名字,我想看看这个层是如何为每个输入图像创建单独的CNN层的。
发布于 2021-10-03 19:05:55
您可以使用plot_model以编程方式可视化体系结构https://www.tensorflow.org/api_docs/python/tf/keras/utils/plot_model
tf.keras.utils.plot_model(
model, to_file='model.png', show_shapes=False, show_dtype=False,
show_layer_names=True, rankdir='TB', expand_nested=False, dpi=96,
layer_range=None
)或者,您可以使用netron来可视化模型的权重,包括架构。
https://stackoverflow.com/questions/69427492
复制相似问题