Как запустить plot_model Керы в сеансе Google Colaboratory?

Следующие команды настройки работают (ноутбук настроен для работы с Python 3):

!pip3 install pydotplus
!pip3 install pydot
!apt-get -qq install -y graphviz && pip3 install -q pydot
!pip3 install pydot-ng
!pip3 install graphviz
!apt-get install python-pydot python-pydot-ng graphviz 
import pydot

Как результат:

Requirement already satisfied: pydotplus in /usr/local/lib/python3.6/dist-packages (2.0.2)
Requirement already satisfied: pyparsing>=2.0.1 in /usr/local/lib/python3.6/dist-packages (from pydotplus) (2.2.2)
Requirement already satisfied: pydot in /usr/local/lib/python3.6/dist-packages (1.2.4)
Requirement already satisfied: pyparsing>=2.1.4 in /usr/local/lib/python3.6/dist-packages (from pydot) (2.2.2)
Requirement already satisfied: pydot-ng in /usr/local/lib/python3.6/dist-packages (1.0.0)
Requirement already satisfied: pyparsing>=2.0.1 in /usr/local/lib/python3.6/dist-packages (from pydot-ng) (2.2.2)
Requirement already satisfied: graphviz in /usr/local/lib/python3.6/dist-packages (0.9)
Reading package lists... Done
Building dependency tree       
Reading state information... Done
graphviz is already the newest version (2.40.1-2).
python-pydot is already the newest version (1.2.3-1).
python-pydot-ng is already the newest version (1.0.0-3).
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.

Но когда я пытаюсь построить скомпилированную модель:

from keras.utils import plot_model
plot_model(model)

Я получил:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-47-4cf84b52a91d> in <module>()
      9 
     10 from keras.utils import plot_model
---> 11 plot_model(model)

/usr/local/lib/python3.6/dist-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:

/usr/local/lib/python3.6/dist-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)

/usr/local/lib/python3.6/dist-packages/keras/utils/vis_utils.py in _check_pydot()
     18     if pydot is None:
     19         raise ImportError(
---> 20             'Failed to import `pydot`. '
     21             'Please install `pydot`. '
     22             'For example with `pip install pydot`.')

ImportError: Failed to import `pydot`. Please install `pydot`. For example with `pip install pydot`.

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

Не уверен, чего не хватает.


person 0x90    schedule 11.10.2018    source источник
comment
Вы перезапустили виртуальную машину после установки pydot, т.е. Runtime --> Restart Runtime?   -  person today    schedule 11.10.2018