Windows下利用Python3绘制Caffe中的网络结构
来源:互联网 发布:李玖哲 解脱 知乎 编辑:程序博客网 时间:2024/06/05 22:48
在Windows10+Anaconda3环境下利用Caffe中的draw_net.py文件绘制Caffe中的网络结构图
1.必要安装
第一步:安装pydotplus。在cmd命令窗口输入:pip install pydotplus
。
第二步:安装Graphviz-2.38。在http://www.graphviz.org/Download_windows.php
页面中下载Graphviz安装包,并完成安装(例如安装目录:C:/Program Files (x86)/Graphviz2.38/bin/);右击“此电脑”打开“属性”,进入系统变量,添加C:/Program Files (x86)/Graphviz2.38/bin/到path中。
2.修改draw_net.py和draw.py文件
(1)打开caffe的根目录下python/caffe/draw.py文件,修改get_layer_label函数中的elif layer.type == 'Pooling':
以下的内容,修改如下:
def get_layer_label(layer, rankdir): """Define node label based on layer type. Parameters ---------- layer : ? rankdir : {'LR', 'RL', 'TB', 'BT'} Direction of graph layout. Returns ------- string : A label for the current layer """ if rankdir in ('TB', 'BT'): # If graph orientation is vertical, horizontal space is free and # vertical space is not; separate words with spaces separator = ' ' else: # If graph orientation is horizontal, vertical space is free and # horizontal space is not; separate words with newlines separator = '\\n' if layer.type == 'Convolution' or layer.type == 'Deconvolution': # Outer double quotes needed or else colon characters don't parse # properly node_label = '"%s%s(%s)%skernel size: %d%sstride: %d%spad: %d"' %\ (layer.name, separator, layer.type, separator, layer.convolution_param.kernel_size[0] if len(layer.convolution_param.kernel_size._values) else 1, separator, layer.convolution_param.stride[0] if len(layer.convolution_param.stride._values) else 1, separator, layer.convolution_param.pad[0] if len(layer.convolution_param.pad._values) else 0) elif layer.type == 'Pooling': pooling_types_dict = get_pooling_types_dict() node_label = '"%s%s(%s %s)%skernel size: %d%sstride: %d%spad: %d"' %\ (layer.name, separator, pooling_types_dict[layer.pooling_param.pool], layer.type, separator, layer.pooling_param.kernel_size, separator, layer.pooling_param.stride, separator, layer.pooling_param.pad) else: node_label = '"%s%s(%s)"' % (layer.name, separator, layer.type) return node_label
(2)若在pycharm下不使用命令窗口方式,则编辑caffe的根目录下python/draw_net.py文件,修改main函数如下:
def main(): """ input_net_proto_file: input network prototxt file. output_image_file: output image file phase: Which network phase to draw: can be TRAIN, TEST, or ALL. Default=ALL. If ALL, then all layers are drawn regardless of phase. rankdir: One of TB (top-bottom, i.e., vertical)、BT(bottom-top, i.e., vertical), LR (left-right, i.e., horizontal), RL (right-left, i.e., horizontal); """ # the file of the net prototxt input_net_proto_path = '../examples/mnist/' input_net_proto_name = 'lenet_train_test.prototxt' input_net_proto_file = input_net_proto_path + input_net_proto_name net = caffe_pb2.NetParameter() text_format.Merge(open(input_net_proto_file).read(), net) rankdir = 'LR' # draw the TRAIN or TEST phase network phase = "ALL" if phase == "TRAIN": phase = caffe.TRAIN elif phase == "TEST": phase = caffe.TEST elif phase == "ALL": phase = None # the path to a file where the networks visualization will be stored output_net_proto_path = '../examples/mnist/' output_net_proto_file = output_net_proto_path + 'Lenet_' + str(phase) + '.jpg' draw.draw_net_to_file(net, output_net_proto_file, rankdir, phase)
**input_net_proto_file
:指prototxt文件 output_image_file
:指保存后的图片名称和格式**
若在pycharm下使用命令窗口方式,则在下面界面中
输入命令:python ./python/draw_net.py ./examples/mnist/lenet_train_test.prototxt lenet.jpg
也可以指定图片的保存位置:python ./python/draw_net.py ./examples/mnist/lenet_train_test.prototxt ./examples/mnist/lenet.jpg
,图片保存在examples/mnist/目录下。
在上述命令中–rankdir默认值为LR,–phase默认值为ALL。
- Windows下利用Python3绘制Caffe中的网络结构
- Windows+Python3下绘制Caffe训练日志中的Loss和Accuracy曲线图
- Windows下使用python绘制caffe中.prototxt网络结构数据可视化
- Caffe学习笔记(2)--spyder 下绘制网络结构
- Caffe在windows下用python绘制网络结构图
- caffe利用draw_net.py绘制net结构
- Caffe学习:使用pycaffe绘制网络结构
- caffe使用draw_net.py网络结构绘制
- Caffe: 用Python绘制网络结构
- 在线网页绘制可视化 Caffe 网络结构
- Caffe学习:使用pycaffe绘制网络结构
- 绘制caffe中的prototxt网络结构图
- window 环境下 Caffe 绘制网络结构图
- caffe-windows下使用pycaffe绘制网络图
- windows下运用matlab绘制caffe训练日志文件中的loss曲线
- caffe基础(8):draw_net.py绘制网络结构
- ubuntu14使用python绘制caffe的深度学习网络结构
- ubuntu上使用draw_net.py绘制caffe ssd网络结构
- Spring Data
- jQuery的子元素过滤选择器
- Vue2+VueRouter2+webpack+Axios 构建项目实战(七)重构API文件为使用axios
- web测试工具SoapUI NG Pro v2.0发布,来看看全新的仪表盘
- java如何解决高并发
- Windows下利用Python3绘制Caffe中的网络结构
- 浅谈https\ssl\数字证书
- Tomcat启动异常
- 网易云信云叮当红包接入流程分享
- Objective-C Runtime入院第一天
- Java抽象类和接口的区别
- fab修复
- 快速排序算法
- Java实现插入排序