gpt4 book ai didi

python - 导入 pydot 失败

转载 作者:行者123 更新时间:2023-12-01 02:14:05 25 4
gpt4 key购买 nike

我试图打印 VGG16 模型的模型摘要,并绘制模型并将其保存在 .png 文件中。

from keras.applications.vgg16 import VGG16
from keras.utils.vis_utils import plot_model

#Creating the object of VGG16 model
model=VGG16()
print(model.summary())
plot_model(model,to_file='vgg.png')

我还按照建议安装了以下软件包 here .

pip install pydot
pip install graphviz
pip install pydot-ng

这是在 Windows10 计算机上的 Python3.5 上运行的。

下面是错误:

回溯(最近一次调用最后一次):

File "<ipython-input-4-d5d9b64127c4>", line 1, in <module>
runfile('C:/Users/Mohanakrishna/Desktop/Work/ObjectDetection.py',
wdir='C:/Users/Mohanakrishna/Desktop/Work')

File "c:\users\mohanakrishna\appdata\local\programs\python\python35\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
execfile(filename, namespace)

File "c:\users\mohanakrishna\appdata\local\programs\python\python35\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/Mohanakrishna/Desktop/Work/ObjectDetection.py", line 14, in <module>
plot_model(model,to_file='vgg.png')

File "c:\users\mohanakrishna\appdata\local\programs\python\python35\lib\site-packages\keras\utils\vis_utils.py", line 135, in plot_model
dot = model_to_dot(model, show_shapes, show_layer_names, rankdir)

File "c:\users\mohanakrishna\appdata\local\programs\python\python35\lib\site-packages\keras\utils\vis_utils.py", line 56, in model_to_dot
_check_pydot()

File "c:\users\mohanakrishna\appdata\local\programs\python\python35\lib\site-packages\keras\utils\vis_utils.py", line 31, in _check_pydot
raise ImportError('Failed to import pydot. You must install pydot'

ImportError: Failed to import pydot. You must install pydot and graphviz for `pydotprint` to work.

最佳答案

我也遇到了同样的问题。无论出于何种原因,在 Windows 10 上,即使我添加到路径,它也不想找到 graphviz。所以最后我通过添加解决了

os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin/'

到我的项目。

关于python - 导入 pydot 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48507679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com