调用 keras的plot_model 函数ImportError: Failed to import `pydot`.
调用 keras的plot_model 函数
import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
from keras import backend as K
from keras.callbacks import TensorBoard
from keras.utils import plot_model
plot_model(model,to_file=‘model.png’)
问题1:未安装pydot
ImportError: Failed to import `pydot`. Please install `pydot`. For example with `pip install pydot`.
python 中安装pydot, graphviz
C:\Users\dd>pip install pydot
Requirement already satisfied: pydot in d:\programdata\anaconda3\lib\site-packages (1.4.1)
Requirement already satisfied: pyparsing>=2.1.4 in d:\programdata\anaconda3\lib\site-packages (from pydot) (2.2.0)
C:\Users\dd>pip install graphviz
Collecting graphviz
Downloading https://files.pythonhosted.org/packages/1f/e2/ef2581b5b86625657afd32030f90cf2717456c1d2b711ba074bf007c0f1a/graphviz-0.10.1-py2.py3-none-any.whl
Installing collected packages: graphviz
Successfully installed graphviz-0.10.1
问题2:未安装GraphViz 软件
提示错误GraphViz 软件未安装 :
OSError: `pydot` failed to call GraphViz.Please install GraphViz (https://www.graphviz.org/) and ensure that its executables are in the $PATH.
根据提示下载 graphviz-2.38
https://graphviz.gitlab.io/download/
windows系统的话从下面地址下载:
https://graphviz.gitlab.io/_pages/Download/windows/graphviz-2.38.msi
安装好后, 设置环境变量:
Path中添加软件可执行文件所在目录。我的是
“D:\Program Files (x86)\Graphviz2.38\bin”
仍然报同样的错。
根据文章pydot 停止更新,不适用于python3.6 以上版本了。卸载,安装pydotplus。
1)首先执行如下命令:
pip uninstall pydot
pip install pydotplus
2)再打开 tensorflow ,keras , utils 目录,修改vis_utils.py 文件,将 pydot 全部替换为pydotplus。
D:\ProgramData\Anaconda3\Lib\site-packages\tensorflow\python\keras\utils
再执行不再报错。