Windows操作系统下,运行pydot相关程序时(我的是keras.utils.plot_model)报错,提示没有安装GraphViz,事实上并不都是因为GraphViz没有安装,本文记录错误解决方法。
操作系统:Win10 keras版本:2.2.4 在Win10系统下(Windows系列都可能出这个问题)keras建立简单的模型,执行 plot_model,报错:
import keras
from keras.models import Model
from keras.layers import Input
from keras.layers import Conv2D
from keras.layers import GlobalAveragePooling2D
from keras.layers import Dense
import numpy as np
from keras.utils import plot_model
import os
os.environ["PATH"] += os.pathsep + r'E:\Program Files (x86)\Graphviz2.38\bin'
A = Input(shape=(16,16,3))
x = Conv2D(filters=10, kernel_size=(3,3), padding='same', activation='relu')(A)
x = Conv2D(filters=10, kernel_size=(3,3), padding='same', activation='relu')(x)
x = GlobalAveragePooling2D()(x)
x = Dense(units = 5, activation='softmax')(x)
model = Model(A,x)
model.summary()
test_input = np.random.rand(1,16,16,3)
results = model.predict(test_input)
plot_model(model)
错误信息:
builtins.OSError: `pydot` failed to call GraphViz.Please install GraphViz (https://www.graphviz.org/) and ensure that its executables are in the $PATH.
pip install pydot-ng
pip install graphviz
pip install pydot
如果问题没有排除,可能是GraphViz程序没有加入到系统路径,考虑情况2
E:\Program Files (x86)\Graphviz2.38\bin
目前为止是网上大多数存在的解决方案,相信大部分的同学到此为止已经解决了问题。 如果错误继续,那么我和你一样,进入情况3。
pydot
在建立Dot
类时查找的dot
程序的名字是 ’dot‘ 而不是我们 Windows 里的可执行程序文件名 ‘dot.exe’
pydot
class Dot(Graph):
"""A container for handling a dot language file.
This class implements methods to write and process
a dot language file. It is a derived class of
the base class 'Graph'.
"""
self.prog = 'dot'
import platform
system = platform.system()
if system == 'Windows':
self.prog = 'dot.exe'
else:
self.prog = 'dot'