caffe学习笔记
1. 生成caffe网络的配置文件,prototxt:
def create_net():
net = caffe.NetSpec()
# LeNet structure
# define data layer
net.data, net.label = caffe.layers.Data(source="data.lmdb",
backend=caffe.params.Data.LMDB,
batch_size=32,
ntop=2,
transform_param=dict(crop_size=40,mirror=True)
)
# define conv layer
net.conv1 = caffe.layers.Convolution(net.data,num_output=20,kernel_size=5,
weight_filler={"type":"xavier"},
bias_filler={"type":"xavier"})
# define activate layer
net.relu1 = caffe.layers.ReLU(net.conv1,in_place=True)
# define pooling layer
net.pool1 = caffe.layers.Pooling(net.relu1,pool=caffe.params.Pooling.MAX,
kernel_size=3,stride=2)
# define conv layer
net.conv2 = caffe.layers.Convolution(net.pool1, num_output=32, kernel_size=3,
pad=1,
weight_filler={"type": "xavier"},
bias_filler={"type": "xavier"})
# define activate layer
net.relu2 = caffe.layers.ReLU(net.conv2, in_place=True)
# define pooling layer
net.pool2 = caffe.layers.Pooling(net.relu2, pool=caffe.params.Pooling.MAX,
kernel_size=3, stride=2)
# define fc layer
net.fc3 = caffe.layers.InnerProduct(net.pool2,num_output=1024,
weight_filler=dict(type='xavier'))
# define activate layer
net.relu3 = caffe.layers.ReLU(net.fc3, in_place=True)
# define dropout layer
net.drop = caffe.layers.Dropout(net.relu3, dropout_param=dict(dropout_ratio=0.5))
# define output layer
net.fc4 = caffe.layers.InnerProduct(net.drop, num_output=10,
weight_filler=dict(type='xavier'))
# define loss
net.loss = caffe.layers.SoftmaxWithLoss(net.fc4, net.label)
with open("net/tt.prototxt",'w') as f:
f.write(str(net.to_proto()))
2. 利用可视化工具查看生成网络的结构:
打开: http://ethereon.github.io/netscope/quickstart.html
点击: Editor / Launch Editor , 进入页面后,将生成的 prototxt 文件复制到左侧, 按 shift+ enter , 即可查看网络结构。