keras 模型可视化和遇到的坑

1.安装相应模块
pip install pydot-ng
pip install graphviz
pip install pydot
2.安装了以上模块,但是还是报错误,发现GraphViz的可执行文件没有:
OSError: pydot failed to call GraphViz.Please install GraphViz (https://www.graphviz.org/) and ensure that its executables are in the $PATH.
3.百度搜索,下载graphviz-2.38.msi,安装完以后相应的d:/Graphviz2.38/bin目录地下就有可执行文件了。
4.将d:/Graphviz2.38/bin目录加到系统环境变量中就OK啦
5.代码

# coding=utf-8
'''
@author: admin
'''
from keras.models import Sequential
from keras.layers import Dense, Activation
from keras.utils import plot_model

import pydot

model = Sequential()
model.add(Dense(32, activation='relu', input_dim=100))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='rmsprop',
              loss='binary_crossentropy',
              metrics=['accuracy'])

# Generate dummy data
import numpy as np
data = np.random.random((1000, 100))
labels = np.random.randint(2, size=(1000, 1))
plot_model(model, to_file='model.png',show_shapes=True)
# Train the model, iterating on the data in batches of 32 samples
# model.fit(data, labels, epochs=10, batch_size=32)

6.输出的模型图
这里写图片描述

猜你喜欢

转载自blog.csdn.net/u011311291/article/details/80298563
今日推荐