gpt4 book ai didi

python - 尝试使用 keras.utils.plot_model 时出错

转载 作者:行者123 更新时间:2023-11-28 19:02:30 25 4
gpt4 key购买 nike

我正在尝试使用 Keras 包在 Python 中制作深度学习模型的绘图/图形,但不幸的是它一直给我一个错误信息,该错误信息不是很丰富。

我在 Linux 上使用 Python 3.5.2、Anaconda 4.2.0、Keras 2.1.6 运行 python,我使用 tensorflow-gpu 1.7.0 后端。

这是错误信息:

keras.utils.plot_model(unet, to_file='model.png', show_shapes=False, show_layer_names=True, rankdir='TB')

['dot', '-Tps', '/tmp/tmphesl1j0c'] return code: 127

stdout, stderr:
b''
b'dot: error while loading shared libraries: libexpat.so.0: cannot open shared object file: No such file or directory\n'

---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-9-60bb0e3b97bd> in <module>()
----> 1 keras.utils.plot_model(unet, to_file='model.png', show_shapes=False, show_layer_names=True, rankdir='TB')

/.../anaconda3-4.2.0/lib/python3.5/site-packages/keras/utils/vis_utils.py in plot_model(model, to_file, show_shapes, show_layer_names, rankdir)
132 'LR' creates a horizontal plot.
133 """
--> 134 dot = model_to_dot(model, show_shapes, show_layer_names, rankdir)
135 _, extension = os.path.splitext(to_file)
136 if not extension:

/.../anaconda3-4.2.0/lib/python3.5/site-packages/keras/utils/vis_utils.py in model_to_dot(model, show_shapes, show_layer_names, rankdir)
53 from ..models import Sequential
54
---> 55 _check_pydot()
56 dot = pydot.Dot()
57 dot.set('rankdir', rankdir)

/.../anaconda3-4.2.0/lib/python3.5/site-packages/keras/utils/vis_utils.py in _check_pydot()
24 # Attempt to create an image of a blank graph
25 # to check the pydot/graphviz installation.
---> 26 pydot.Dot.create(pydot.Dot())
27 except OSError:
28 raise OSError(

/.../anaconda3-4.2.0/lib/python3.5/site-packages/pydot.py in create(self, prog, format, encoding)
1882 out=stdout_data,
1883 err=stderr_data))
-> 1884 assert p.returncode == 0, p.returncode
1885 return stdout_data

AssertionError: 127

如果有人能帮我解决这个错误,我将不胜感激。

注意:pydot和graphviz都安装了

最佳答案

对我来说,解决方案是这样导入:

from keras.utils.vis_utils import plot_model

关于python - 尝试使用 keras.utils.plot_model 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50996574/

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