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

我刚开始学习,正在尝试构建一个简单的BiLSTM模型用于时间序列预测,我已经设法创建了一个模型,现在我想将模型摘要转换为png文件。

这是我的代码

from tensorflow.keras.models import Sequentialmodel_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_modelmodel_opendf.build(input_shape=(100,1))model_opendf.summary()plot_model(model_opendf, to_file='lstm_model.jpg')

结果如下

picture

感觉有点空,是否有其他方法可以使用plot_model来填充内容?以及如何立即将图像转换为png格式?


回答:

这里有一个关于plot_model的参考链接,你可以添加show_shapes和show_layer_names参数,像这样:

from keras.utils.vis_utils import plot_modelmodel_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,或者其他任何图像文件格式,你只需在to_file参数中指定你想要的图像格式,在这种情况下,将其从jpg改为png即可。

你的模型应该看起来像这样:

image

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注