利用 caffe 接口构建 CNN 网络
2016-08-29 14:53
429 查看
我的研究重点原本是在 Torch 上,我也很喜欢用 Torch 去实现网络。但最近不得不转到 caffe 上。
在实现上篇博文:论文阅读:Reading Text in the Wild with Convolutional Neural Networks 的代码时,在 Bounding Box Regression 部分,需要用 caffe 来实现这个网络。
而一开始我构建论文中提到的这个 CNN 网络时,并没有用 caffe 提供的接口,而是直接手写
我将这个网络用 caffe 中的
调用 caffe 的 python 接口,网络构建方式如下:
最后生成两个
下图是自动生成的
这样的方式更快速,还不容易出错~^_^
在实现上篇博文:论文阅读:Reading Text in the Wild with Convolutional Neural Networks 的代码时,在 Bounding Box Regression 部分,需要用 caffe 来实现这个网络。
而一开始我构建论文中提到的这个 CNN 网络时,并没有用 caffe 提供的接口,而是直接手写
train.prototxt、
test.prototxt文件。结果除了很多错,caffe 的 layers 名称也在变化,所以极其不推荐这种方式。我这个网络较浅时还好,一旦网络很深,写起来累死人。
我将这个网络用 caffe 中的
draw_net.py脚本生成图像,网络结构如下:
调用 caffe 的 python 接口,网络构建方式如下:
import os, sys, glob CAFFE_PATH = '/home/chenxp/caffe/python' sys.path.append(CAFFE_PATH) import caffe import caffe.io from caffe import layers as L from caffe import params as P import h5py def Bounding_Box_Reg(hdf5, batch_size): n = caffe.NetSpec() n.data, n.label = L.HDF5Data(batch_size=batch_size, source=hdf5, ntop=2) n.conv1 = L.Convolution(n.data, kernel_size=5, num_output=64, pad=2, weight_filler=dict(type='xavier')) n.relu1 = L.ReLU(n.conv1, in_place=True) n.pool1 = L.Pooling(n.conv1, kernel_size=2, stride=2, pool=P.Pooling.MAX) n.conv2 = L.Convolution(n.pool1, kernel_size=5, num_output=128, pad=2, weight_filler=dict(type='xavier')) n.relu2 = L.ReLU(n.conv2, in_place=True) n.pool2 = L.Pooling(n.conv2, kernel_size=2, stride=2, pool=P.Pooling.MAX) n.conv3 = L.Convolution(n.pool2, kernel_size=3, num_output=256, pad=1, weight_filler=dict(type='xavier')) n.relu3 = L.ReLU(n.conv3, in_place=True) n.pool3 = L.Pooling(n.conv3, kernel_size=2, stride=2, pool=P.Pooling.MAX) n.conv4 = L.Convolution(n.pool3, kernel_size=3, num_output=512, pad=1, weight_filler=dict(type='xavier')) n.relu4 = L.ReLU(n.conv4, in_place=True) n.pool4 = L.Pooling(n.conv4, kernel_size=2, stride=2, pool=P.Pooling.MAX) n.ip1 = L.InnerProduct(n.pool4, num_output=4000, weight_filler=dict(type='xavier')) n.dp1 = L.Dropout(n.ip1, dropout_ratio=0.5) n.ip2 = L.InnerProduct(n.ip1, num_output=4, weight_filler=dict(type='xavier')) n.loss = L.EuclideanLoss(n.ip2, n.label) return n.to_proto() with open('BBR_train.prototxt', 'w') as f: f.write(str(Bounding_Box_Reg('train.h5', 16))) with open('BBR_test.prototxt', 'w') as f: f.write(str(Bounding_Box_Reg('test.h5', 16)))
最后生成两个
prototxt文件,一个是
BBR_train.prototxt,另一个是
BBR_test.prototxt文件。
下图是自动生成的
BBR_train.prototxt文件:
这样的方式更快速,还不容易出错~^_^
相关文章推荐
- 利用 caffe 接口构建 CNN 网络
- 利用MINA构建JAVA网络应用框架
- 利用ISCSI存储技术构建IP存储网络(安全篇)
- 利用GPU和Caffe训练神经网络
- caffe实现Alexnet网络结构(利用自己的数据)
- 利用OpenVSwitch构建多主机Docker网络
- Caffe框架源码剖析(1)—构建网络
- iOS开发--利用NSProxy实现消息转发-模块化的网络接口层设计
- 利用OpenVSwitch构建多主机Docker网络
- Docker实现跨主机容器实例网络通信(2)——利用OpenVSwitch构建多主机Docker网络
- 在Android下利用Shell命令管理网络接口
- 利用网络短信验证码接口实现手机短信轰炸 (历史代码,贴出学习)
- 利用RouterOS构建三层网络详解
- 利用caffe训练网络的步骤
- 利用ISCSI存储技术构建IP存储网络(实战篇)
- Java EE 下利用Servlet filter接口 和 GZIPOutputStream 包装流 解决web应用中网络传输数据量大的问题
- 中国玩家利用虚拟币节点技术构建去中心化的P2P影子网络BitNet
- 利用caffe 用自己的数据集在imagenet网络中实践
- 利用caffe生成 lmdb 格式的文件,并对网络进行FineTuning
- 利用接口构建系统架构的一次实践和反思