簡體   English   中英

如何使用 plot_model 將模型轉換為 png?

[英]How to use plot_model to convert a model as png?

我是新手,仍在學習如何為我的時間序列預測構建一個簡單的 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')

結果是這樣的

圖片

感覺很空,還有什么可以用來填充 plot_model 的嗎? 以及如何將圖像立即轉換為 png?

這是 plot_model 的參考鏈接,您可以像這樣添加 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。

您的模型應如下所示:

圖片

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM