如何使用plot_model将模型转换为png?

问题描述 投票:0回答:2

我对此很陌生,仍在学习如何为时间序列预测构建一个简单的 BiLSTM 模型,我以某种方式设法创建了一个模型,现在我想将模型摘要转换为 png 文件。

这是我的代码

from tensorflow.keras.models import Sequential

model_opendf=Sequential()
model_opendf.add(Bidirectional(LSTM(100, activation='relu', input_shape=(100,1))))
model_opendf.add(Dense(1))
model_opendf.compile(loss="mean_squared_error", optimizer="adam")

from keras.utils.vis_utils import plot_model
model_opendf.build(input_shape=(100,1))
model_opendf.summary()
plot_model(model_opendf, to_file='lstm_model.jpg')

结果是这样的

picture

感觉很空,还有什么可以用来填充plot_model吗?以及如何立即将图像转换为png?

keras artificial-intelligence bilstm
2个回答
1
投票

这里是plot_model的参考link,您可以像这样添加show_shapes和show_layer_names:

from keras.utils.vis_utils import plot_model
model_opendf.build(input_shape=(100,1))
model_opendf.summary()
plot_model(model_opendf, to_file='lstm_model.png', show_shapes=True, show_layer_names=True)

如果您想将输出从 jpg 转换为 png 或任何其他图像文件,在这种情况下,您只需键入所需的图像格式,将其从 jpg 更改为 png。

您的模型应如下所示:

image


0
投票

在tensorflow版本2.15中,我必须使用keras.utils使其像下面一样工作

from keras.utils import plot_model
plot_model(model, to_file='model.png', show_shapes=True, show_layer_names=True)
© www.soinside.com 2019 - 2024. All rights reserved.