from keras.utils import plot_model plot_model(model)
出现错误:
ImportError: Failed to importpydot
. Please installpydot
. For example withpip install pydot
.
Google了一下,解决问题:
首先第一反应conda install pydot。
这一步会顺便装了graphviz:
结果运行还是不行。
继续查阅:
安装顺序问题,有人提示,In addition to pydot and graphviz install pydotplus(需要再装一个pydotplus)
并且按照顺序:
Edit:Try uninstalling all pydot related modules and graphiviz, then reinstall in the following order:(如果很混乱,就全部重装,按照以下顺序再安装一遍)
- pydot
- pydotplus
- graphviz
我装了pydotplus还是不行,继续,尝试这种方法保存model也可以_只是保存的model流程图不够全面。
1 import keras 2 import pydot as pyd 3 from IPython.display import SVG 4 from keras.utils.vis_utils import model_to_dot 5 6 keras.utils.vis_utils.pydot = pyd 7 8 #Visualize Model 9 10 def visualize_model(model): 11 return SVG(model_to_dot(model).create(prog='dot', format='svg')) 12 #create your model 13 #then call the function on your model 14 visualize_model(model)
继续寻找,最后最重要的解决方案(好像因为这个包是为Linux系统设计的,所以在windows系统需要运行exe文件):
按照下面这个方案,先修改pydot.py文件,在class Dot(Graph)函数下把self.prog = 'dot' 改成 self.prog = 'dot.exe'
然后把dot.exe文件所在的graphviz文件夹的路径加入系统path
我的电脑上路径是C:UsersuserAnaconda3Libraryingraphviz
最后就解决了!~~~
Just in case someone using windows might need it, modify the pydot.py file. It should be in <python_install_path>LibSite-packagespydot.py. Besides pip install pydot and pip install graphviz, also install graphviz software. And add the software bin directory to the system's path. And in class Dot(Graph), change self.prog = 'dot' to self.prog = 'dot.exe'