Keras网络训练可视化调用plot_model ,ImportError: Failed to import `pydot`.

调用 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

再执行不再报错。

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值