Caffe绘制神经网络结构图

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. 介绍

Caffe中自带绘制神经网络结构图的工具,主要是在pycaffe中,因此首先要安装pycaffe,可参考我的另一篇文章,Caffe安装,除此之外还需要安装两个依赖:pydot和graphviz。

graphviz不能通过pip安装,否则仍然会报下面的错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
Drawing net to lenet.png
Traceback (most recent call last):
File "draw_net.py", line 58, in <module>
main()
File "draw_net.py", line 54, in main
phase)
File "/Users/ltc/Caffe/caffe-master/python/caffe/draw.py", line 244, in draw_net_to_file
fid.write(draw_net(caffe_net, rankdir, ext, phase))
File "/Users/ltc/Caffe/caffe-master/python/caffe/draw.py", line 223, in draw_net
return get_pydot_graph(caffe_net, rankdir, phase=phase).create(format=ext)
File "/Users/ltc/anaconda/lib/python2.7/site-packages/pydot.py", line 1883, in create
prog=prog))
Exception: "dot" not found in path.

2. graphviz安装

graphviz安装命令如下(Mac,Linux可用apt-get):

1
brew install graphviz

3. pydot安装

pydot的安装命令:

1
pip install pydot

4. 绘制结构图

绘制神经网络结构图:

1
2
3
4
5
# 进入Caffe python目录
$ cd /Users/ltc/Caffe/caffe-master/python

# 绘制结构图
$ python draw_net.py ../examples/mnist/lenet_train_test.prototxt lenet.png

5. 结果

结果如下:

LeNet网络结构图

如果有收获,可以请我喝杯咖啡!