1

I was trying to print the model summary of VGG16 model and also plot the model and save it in a .png file.

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')

I also installed the below packages as suggested here.

pip install pydot
pip install graphviz
pip install pydot-ng

This was run on Python3.5 on a Windows10 machine.

Below is the error:

Traceback (most recent call last):

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.
mohanakrishnavh
  • 129
  • 1
  • 10
  • 1
    You forgot to post the actual error! – Amin Etesamian Jan 29 '18 at 18:27
  • updated the error received – mohanakrishnavh Jan 29 '18 at 18:31
  • 1
    Read that documentation page. Did you install `graphviz`? "To render the generated DOT source code, you also need to install Graphviz (download page). Make sure that the directory containing the dot executable is on your systems’ path." – Jongware Jan 29 '18 at 18:38
  • 1
    Possible duplicate of [Keras: "RuntimeError: Failed to import pydot." after installing graphviz and pydot](https://stackoverflow.com/questions/36886711/keras-runtimeerror-failed-to-import-pydot-after-installing-graphviz-and-pyd) – Dr. Snoopy Jan 29 '18 at 20:25

1 Answers1

2

I had the same problem. For whatever reason on Windows 10 it doesn't want to find graphviz even if I added to path. So finally I solved by adding

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

to my project.

Manngo
  • 829
  • 7
  • 24