keras模型可视化

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/dcrmg/article/details/81532608

1. 安装pydot

pip install pydot

2. 安装 graphviz

sudo apt-get install graphviz

3. 使用keras中 plot_model 函数画出模型图

#encoding=utf-8

from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation
from keras.layers.embeddings import Embedding

from keras.utils import plot_model

model = Sequential()
model.add(Embedding(input_dim=1024, output_dim=256, input_length=50))
model.add(Dropout(0.5))
model.add(Dense(1))
model.add(Activation('sigmoid'))

plot_model(model, to_file='model_test.png',show_shapes=True)

模型结构可视化结果:

plot_model函数中show_shapes参数设为True,会在结构图中显示出输出数据的形状,默认为False

猜你喜欢

转载自blog.csdn.net/dcrmg/article/details/81532608