keras框架下使用Graphviz报错(jupyter环境)
安装pydot与Graphviz方法
- 打开Anaconda Prompt
- pip install pydot
- pip install graphviz
- 官网下载Graphviz:https://www.graphviz.org/download/ ,下载后安装,并将安装路径(如E:\Program Files (x86)\Graphviz2.38\bin)加入环境变量PATH中
问题再现
在jupyter中调用
plot_model(happyModel, to_file='HappyModel.png')
SVG(model_to_dot(happyModel).create(prog='dot', format='svg'))
运行错误,显示错误信息为:
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last)
<ipython-input-16-94e567feb269> in <module>
----> 1 plot_model(happyModel, to_file='HappyModel.png')
2 SVG(model_to_dot(happyModel).create(prog='dot', format='svg'))
D:\Anaconda3\lib\site-packages\keras\utils\vis_utils.py in plot_model(model, to_file, show_shapes, show_layer_names, rankdir)
132 'LR' creates a horizontal plot.
133 """
--> 134 dot = model_to_dot(model, show_shapes, show_layer_names, rankdir)
135 _, extension = os.path.splitext(to_file)
136 if not extension:
D:\Anaconda3\lib\site-packages\keras\utils\vis_utils.py in model_to_dot(model, show_shapes, show_layer_names, rankdir)
55 from ..models import Sequential
56
---> 57 _check_pydot()
58 dot = pydot.Dot()
59 dot.set('rankdir', rankdir)
D:\Anaconda3\lib\site-packages\keras\utils\vis_utils.py in _check_pydot()
29 except OSError:
30 raise OSError(
---> 31 '`pydot` failed to call GraphViz.'
32 'Please install GraphViz (https://www.graphviz.org/) '
33 'and ensure that its executables are in the $PATH.')
OSError: `pydot` failed to call GraphViz.Please install GraphViz (https://www.graphviz.org/) and ensure that its executables are in the $PATH.
但是Graphviz已经正确安装,并且环境变量也已配置正确。
原因分析
在Anaconda安装目录keras包中的…\Anaconda3\Lib\site-packages\keras\utils\vis_utils.py文件中有:
# `pydot` is an optional dependency,
# see `extras_require` in `setup.py`.
try:
import pydot
except ImportError:
pydot = None
def _check_pydot():

最低0.47元/天 解锁文章





