【tensorflow2】plot_modelでエラーが出た時の対処法

スポンサーリンク
plot_modelでエラーが出た時の対処法AIを作ってみる
この記事を読んで分かること
  • plot_modelのエラーの対処方法
    (‘You must install pydot (`pip install pydot`) and install graphviz (see instructions at https://graphviz.gitlab.io/download/) ‘, ‘for plot_model/model_to_dot to work.’)

 

plot_modelのエラー

tensorflowでモデルを可視化するために、

tensorflow.keras.utils.plot_model(model, "model_with_shape_info.png", show_shapes=True)

を実行したら以下のようなエラーが出たため、対処法を紹介します。

ImportError: (‘You must install pydot (`pip install pydot`) and install graphviz (see instructions at https://graphviz.gitlab.io/download/) ‘, ‘for plot_model/model_to_dot to work.’)

 

普通にpipで必要なモジュールをインストールしてもうまくいかなかったので、情報共有します。

 

対処方法

必要なモジュールを再インストールしたら直りました。

アンインストール

一度必要なモジュールをすべてアンインストールします。

pip3 uninstall pydot
pip3 uninstall pydotplus
pip3 uninstall graphviz

 

再度、インストール

必要なモジュールをインストールし直します。

pip3 install pydot
pip3 install pydotplus
apt-get install graphviz

 

graphviz」はpipではなく、apt-getでインストールしてください。

以上で、動くようになると思います。

 

備考

pydotは現在開発が止まっており、python3.6では動かないそうです。

pydotplusまたはpydot-ngを代わりに使用することで対処できます。

今回はpydotplusをインストールする方法を紹介しました。

 

こんな感じで見やすくモデルを可視化できました。

pydot_例

 

参考

ImportError: Failed to import pydot. You must install pydot and graphviz for `pydotprint` to work
I have seen similar issue but it is not solved either, so I decided to ask. I am trying to visualize my model in keras using from keras.utils import plot_mode...

 

コメント

タイトルとURLをコピーしました