caffe drawnet.py 用Python画网络框架

时间:2023-03-09 22:25:09
caffe drawnet.py 用Python画网络框架

在caffe中可以使用draw_net.py轻松地绘制卷积神经网络(CNN,Convolutional Neural Networks)的架构图。这个工具对于我们理解、学习甚至查错都有很大的帮助。

1、draw_net.py的使用方法如下:

usage: draw_net.py [-h] [--rankdir RANKDIR]
input_net_proto_file output_image_file Draw a graph of the net architecture. positional arguments:
input_net_proto_file Input network prototxt file
output_image_file Output image file optional arguments:
-h, --help show this help message and exit
--rankdir RANKDIR One of TB (top-bottom, i.e., vertical), RL (right-
left, i.e., horizontal), or another valid dot option;
see
http://www.graphviz.org/doc/info/attrs.html#k:rankdir
(default: LR)

其中,–rankdir选项确定了输出图片的摆放位置,如TB (Top-Bottom) 就是网络从上到下访问,同理RL (Right-Left)就是从右向左,LR (Left-Right) 就是从左向右摆放。默认使用的是LR方式。

下面的代码输出了卷积神经网络经典的LeNet的网络结构

/home/cheche/caffe-master/python# python draw_net.py --rankdir TB ../examples/mnist/lenet.prototxt ../examples/mnist/lenet_structure.jpg

caffe drawnet.py 用Python画网络框架

2、出错解决方案

(1)、提示“ImportError: no  module named pydot”

解决方案:返回系统根目录,用命令“pip install pydot”安装“pydot”

(2)、安装完pydot后,再次进入"../caffe-master/python#"目录,运行1中的命令进行绘图,出现新问题““AttributeError: ‘google.protobuf.pyext._message.RepeatedScalarConta’ object has no attribute ‘_values””

实际上是由于protobuf(例如centos7(protobuf=3.2)) 版本过高导致。 
解决办法:

返回系统根目录,运行以下代码重新安装protobuf

pip uninstall protobuf

pip install protobuf==2.6.0

(3)、如果上述步骤不能解决问题,可以使用在线绘图

地址为:http://ethereon.github.io/netscope/#/editor

感谢以下作者:

http://blog.csdn.net/dcxhun3/article/details/52237480

http://blog.csdn.net/xiaoyezi_1834/article/details/50725632

http://blog.csdn.net/yiranyhy/article/details/55509304

http://blog.csdn.net/dongfang1984/article/details/72868732