如何在Google Colaboratory会话中运行Kera的plot_model?

时间:2018-10-11 09:13:08

标签: python python-3.x keras google-colaboratory pydot

以下设置命令似乎正在运行(笔记本配置为运行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.
---------------------------------------------------------------------------

不确定丢失了什么。

0 个答案:

没有答案