【填坑记】使用keras绘制(plot_model)网络结构图总是出错的解决办法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_27825451/article/details/89338222

本人使用的开发环境

python3.6.8+tensorflow1.9+keras2.2.4

前提:已经正确安装pydot和graphviz的python软件包,并且安装windows的graphviz安装包,并且配置好了环境变量

错误:pydot不能够正确调用graphviz,请确保已经安装了graphviz并配置了环境变量

网络上其它的解决方案:

(1)确保安装顺序正确:graphviz->grapphviz软件本身并配置环境变量->pydot

         尝试失败

(2)改用pydot_ng,于是安装 pip install pydot_ng

    尝试失败

(3)环境变量要这样配置

添加GRAPHVIZ_DOT=“D:\Program Files (x86)\Graphviz2.38\bin”(这是我的graphviz的安装路径)

给系统的PATH环境变量添加值,“D:\Program Files (x86)\Graphviz2.38\bin”

给用户的PATH环境变量添加值,“D:\Program Files (x86)\Graphviz2.38\bin”

     尝试失败

我的解决办法:

问题其实是pydot的锅。pydot已经停止开发了,python3.5、python3.6、python3.7已经不能使用了,由于我的环境是python3.6.8,自然会出错,于是我安装了pydot的新版本pydotplus

即:

pip install pydotplus

然后在自己安装的keras文件夹里面找到keras里面的  utils\vis_utils.py  这个文件,把代码里面的的pydot的都替换成pydotplus(直接使用批量替换即可,手动替换也行,这个文件代码量很少)

  尝试成功!

下面来看一下这个pydototplus到底是个啥?

PyDotPlus is an improved version of the old pydot project that provides a Python Interface to Graphviz’s Dot language.

(pyplotplus是pyplot的升级版本)

http://pydotplus.readthedocs.org/

Differences with pydot(与pyplot的不同点):

  • Compatible with PyParsing 2.0+.
  • Python 2.7 - Python 3 compatible.
  • Well documented.
  • CI Tested.

Installation

pip install pydotplus

Documentation

User guide and API Reference can be found in:

http://pydotplus.readthedocs.org/

Requirements

  • pyparsing: pydot requires the pyparsing module in order to be able to load DOT files.
  • GraphViz: is needed in order to render the graphs into any of the plethora of output formats supported.
  • 依赖于graphviz和pyparsing这两个包。

猜你喜欢

转载自blog.csdn.net/qq_27825451/article/details/89338222