0
点赞
收藏
分享

微信扫一扫

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

爱薇Ivy趣闻 2022-02-05 阅读 37
# 可视化模型结构运行出错
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

举报

相关推荐

0 条评论