keras 可以通过如下方式可视化当前模型:
from keras.utils import plot_model
plot_model(model, to_file='model_plot.png', show_shapes=True)
在一些环境上运行上述命令,可能会出现以下错误:
-
没有pydot 包等提示,使用
pip install pydot
命令安装pydot -
使用
pip install pydot
命令安装pydot后,使用继续运行上述命令,报错
pydot failed to call GraphViz.Please install GraphViz (https://www.graphviz.org/) and ensure that its executables are in the $PATH. -
使用
pip install graphviz
安装graphviz 后还是存在该错误,发现graphviz 是一个软件包,而不是一个库,所以使用Linux软件安装的方式进行安装graphviz后(安装方法如下),能够正常可视化当前模型。- Mac:
brew install graphviz
Redhat/Centos:yum install graphviz
Debian/Ubuntu:apt-get install graphviz
- Mac: