我刚开始学习,正在尝试构建一个简单的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')
结果如下
感觉有点空,是否有其他方法可以使用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即可。
你的模型应该看起来像这样: