问题描述
我正在尝试使用Keras软件包在Python中绘制深度学习模型的图/图,但不幸的是,它一直给我一个错误,信息不多.
I am trying to make a plot/graph of deep learning model in Python using Keras package but unfortunately it keeps giving me an error which is not very informative.
我在使用Python 3.5.2,Anaconda 4.2.0,Keras 2.1.6的Linux上运行python,并使用tensorflow-gpu 1.7.0后端.
I run python on Linux with Python 3.5.2, Anaconda 4.2.0, Keras 2.1.6 and I use tensorflow-gpu 1.7.0 Backend.
这是错误消息:
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
如果有人可以帮助我解决这个错误,我将不胜感激.
I would really appreciate if somebody could help me with this error.
注意:pydot和graphviz均已安装
Note: both pydot and graphviz are intalled
推荐答案
对我来说,解决方案是:
For me the solution was:
-
conda install pydotplus
(pydot-ng不能与tensorflow-gpu一起安装). - 在anaconda目录中搜索viz_utils.py并将其全部打开.确保在所有地方都导入了pydot,方法如下:
conda install pydotplus
(pydot-ng was not installable with tensorflow-gpu it said).- Search for viz_utils.py in anaconda directory and open all of them. Make sure everywhere pydot is imported, it is done the following way:
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
其中一个文件只是说 import pyplot
.更改之后,它对我有用.
There was one of the files where it just said import pyplot
. After changing that, it worked for me.
这篇关于尝试使用keras.utils.plot_model时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!