OSError: `pydot` failed to call GraphViz.Please install GraphViz (https://www.graphviz.org/) an

# 可视化模型结构运行出错
from keras.utils import plot_model

if __name__ == "__main__":
    model = 
    model.summary()
    plot_model(model, to_file='model.png', show_shapes=True)

首先:

  1. pip install graphviz

  2. pip install pydot

  3. pip install pydot-ng

  4. 下载 graphviz-2.38.msi,存放到C:\Program Files (x86)\Graphviz2.38  :https://graphviz.gitlab.io/_pages/Download/Download_windows.html

  5. 找到安装环境的pydot.py文件,例如D:\ana\envs\tf1.15\Lib\site-packages\pydot.py

pydot.py具体操作:

大概1793行,set_prog函数修改

    def set_prog(self, prog):
        """Sets the default program.

        Sets the default program in charge of processing
        the dot file into a graph.
        """
        #self.prog = prog  #原方法就该句话
        path = r'C:/Program Files (x86)/Graphviz2.38/bin'  # 例如我的:F:\Program File\Anaconda\envs\python3.5\Lib\site-packages\bin
        prog = os.path.join(path, prog)
        prog += '.exe'
        return prog

大概1845行,create函数添加一句prog = self.set_prog('dot'):

        if prog is None:
            prog = self.prog

        assert prog is not None

        prog = self.set_prog('dot')  # 此处为添加的语句

        if isinstance(prog, (list, tuple)):
            prog, args = prog[0], prog[1:]
        else:
            args = []

再次运行即成功解决问题。

参考:https://blog.csdn.net/weixin_41864878/article/details/81095885

参考:https://blog.csdn.net/weixin_40977054/article/details/104714576

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值