我在用keras可视化模型时,遇见了上述错误,错误信息为:

 

Traceback (most recent call last):
File "HARRISON_feature_model.py", line 55, in <module>
plot_model(model, to_file='vgg_feature_model.png', show_shapes=True, show_layer_names=False)
File "/home/idc/anaconda3/envs/hashtag/lib/python2.7/site-packages/keras/utils/vis_utils.py", line 131, in plot_model
dot = model_to_dot(model, show_shapes, show_layer_names, rankdir)
File "/home/idc/anaconda3/envs/hashtag/lib/python2.7/site-packages/keras/utils/vis_utils.py", line 52, in model_to_dot
_check_pydot()
File "/home/idc/anaconda3/envs/hashtag/lib/python2.7/site-packages/keras/utils/vis_utils.py", line 27, 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.

解决办法为:

 

 

pip install pydot-ng
pip install graphviz

# 或者
sudo apt install python-pydot python-pydot-ng graphviz

然后就解决了,我的系统为ubuntu 16.04

 

或者:

 

sudo pip3 install pydot
sudo pip3 install graphviz
sudo apt-get install graphviz

下面解决方案也是ubuntu 16.04,不过用的是python3

 

参考文献

[1].Keras实现LeNet-5网络,并可视化网络结构图.

[2].keras模型可视化及解决'Failed to import pydot'问题.http://www.zhimengzhe.com/linux/353667.html

[3].ImportError: Failed to import pydot. You must install pydot and graphviz for `pydotprint` to work.​