【Keras实战】使用 plot_model 出现的问题

问题描述

在使用 keras 的plot_model 函数时,需要安装 pydot,但是当我 “pip install pydot” 后运行程序时,程序报出如下错误
OSError: pydot failed to call GraphViz.Please install GraphViz (https://www.graphviz.org/) 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.

在经过多次试验后,得出如下解决方案,希望对大家有所帮助,少走弯路!

解决方案

环境:Windows 7 64位
编译器:Anaconda3, Spyder (tensorflow)

1、打开 GraphViz 官网

官网地址: GraphViz
官网界面:
在这里插入图片描述

2、下载 GraphViz

(1)、在官网首页下拉,找到 Download,点击 Download:
在这里插入图片描述
(2)、进入下载界面,找到 Windows,点击 “Stable 2.38 Windows install packages”:
在这里插入图片描述
(3)、进入 Windows Packages 下载界面, 点击 “graphviz-2.38.msi” 下载:
在这里插入图片描述
(4)、双击默认安装即可。

注意

(1)、安装成功后,将路径 “C:\Program Files (x86)\Graphviz2.38\bin” 添加到环境变量!!!
(2)、最好能重启变脑!!!

3、安装 pygraphViz 和 pydot

打开 Anaconda Prompt,激活 tensorflow,使用 pip 安装:

# 第一步,然后回车
activate tensorflow

# 第二步,然后回车
pip install graphViz

# 第三步,然后回车
pip install pydot==1.2.4
本人安装的 graphViz 的版本默认是0.10.1,如果 pydot 的版本不是 1.2.4 的话,可能依然会报错。

4、运行成功

from keras.utils import plot_model

plot_model(model, to_file='*.png')

运行成功,会在当前文件夹下生成模型的拓扑图。
如果依然报错,请重启电脑!!!重启电脑可解决 80% 的问题!!!

祝您浏览愉快!

  • 6
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值