kears可视化模块keras.utils.visualize_util 的安装配置与错误解决办法-Windows系统

一、错误提示:ImportError: Failed to import pydot. You must install pydot and graphviz for pydotprint to work.

提示加载pydot模块失败,必须安装pydot、graphviz模块

方法1.安装pydot、graphviz 模块,使用豆瓣镜像源可以加速安装;

pip install -i https://pypi.doubanio.com/simple/ pydot
pip install -i https://pypi.doubanio.com/simple/ graphviz

方法2.上述模块安装后依然提示错误,可以进入代码查看一下,路径anaconda->env(虚拟环境)->tensorflow(你的环境名字)->lib->sit-packages->keras->utils->vis_utils.py

try:
    # pydot-ng is a fork of pydot that is better maintained.
    import pydot_ng as pydot
except ImportError:
    # pydotplus is an improved version of pydot
    try:
        import pydotplus as pydot
    except ImportError:
        # Fall back on pydot if necessary.
        try:
            import pydot
        except ImportError:
            pydot = None

从代码可以看到pydot_ngpydotplus都可以替代pydot,小白就都安装一遍吧

pip install -i https://pypi.doubanio.com/simple/ pydot_ng
pip install -i https://pypi.doubanio.com/simple/ pydotplus

方法3 依然报错,在上述两种办法的基础上,安装graphviz软件

1.直接点击下载并安装:graphviz-2.38-win32.msi
上述网址失效就手动点击下载吧
https://graphviz.gitlab.io/_pages/Download/
点击
点击后会进入一个文件路径
然后依次点击
10**/msbuild/Release/Win32/graphviz-2.38-win32.msi
等待下载安装就可以了,一定要记住自己安装的地址!!

2.配置环境变量,不会的自行百度
在这里插入图片描述

3 .进入CMD,检查graphviz是否安装成功
在这里插入图片描述

二、Keras可视化安装与使用

安装过程同上
输入代码就可以使用了

from keras.utils.vis_utils import plot_model  #导入可视化头文件
# 输出可视化图片
# 参数:model为你的模型,to_file保存文件名,show_shapes是否显示输入输出尺寸
plot_model(model,to_file='model1.png',show_shapes=True) #显示尺寸

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_40076022/article/details/107970509