问题复现代码语言:javascript代码运行次数:0
运行 复制import keras from keras.models import Modelfrom keras.layers import Inputfrom keras.layers import Conv2Dfrom keras.layers import GlobalAveragePooling2Dfrom keras.layers import Denseimport numpy as npfrom keras.utils import plot_modelimport osos.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)
代码语言:JavaScript代码运行次数:0
运行 复制builtins.OSError: `pydot` failed to call GraphViz.Please install GraphViz (https://www.graphviz.org/) and ensure that its executables are in the $PATH.
问题原因与解决方案:
情况 1
原因:未安装GraphViz。
解决方案:安装相应模块。
代码语言:JavaScript代码运行次数:0
运行 复制pip install pydot-ng pip install graphviz pip install pydot
情况 2
原因:GraphViz程序未加入到系统路径。
解决方案:下载
graphviz-2.38.msi,可在此处下载:https://www.php.cn/link/e61d2ed0329c7be9a1cc46faed9b9a27 Files (x86)\Graphviz2.38\bin`,并将路径加入到系统变量。

情况 3
原因:依赖模块已安装、程序已加入系统变量,但仍出现上述提示,因为
pydot在建立
Dot类时查找的
Dot程序名称是'dot'而不是Windows中的可执行程序文件名'dot.exe'。
解决方案:修改代码。在报错位置找到
pydot,然后找到
Dot类。

找到
Dot类的开头代码:
代码语言:JavaScript代码运行次数:0
运行 复制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',将其替换为:
代码语言:JavaScript代码运行次数:0
运行 复制import platformsystem = platform.system() if system == 'Windows': self.prog = 'dot.exe'else: self.prog = 'dot'
保存并再次运行程序。











