1.前言:在运行Keras框架上的可视化代码时,遇到如下问题:
OSError: pydot failed to call GraphViz.Please install GraphViz (https://www.graphviz.org/) and ensure that its executables are in the $PATH.
2.解决方法:
(1)安装相关模块:
pip install pydot-ng
pip install graphviz
pip install pydot==1.2.3 #这个很关键
(2)下载文件:raphviz-2.38.msi
链接:https://pan.baidu.com/s/19IwMBJC33LApbi_lU0YUVg 提取码:4r22
(3)下载完成后直接安装到自己的指定目录,然后将安装目录添加到电脑的系统环境变量中。
(4)完成。
3.举例:
from keras.models import Sequential
from keras.layers import Dense, Activation
from keras.utils import plot_model
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)
参考文献: