Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error when trying to use keras.utils.plot_model

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.

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.

Here is the error message:

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.

Note: both pydot and graphviz are intalled

like image 775
Sabrina Avatar asked Dec 06 '22 11:12

Sabrina


2 Answers

For me solution was to import like this:

from keras.utils.vis_utils import plot_model
like image 108
DomagojM Avatar answered Dec 10 '22 19:12

DomagojM


I changed keras.utils to tensorflow.keras.utils and it helped me

like image 24
Kymbat Taalaibekova Avatar answered Dec 10 '22 17:12

Kymbat Taalaibekova