您的位置:首页 > 理论基础 > 计算机网络

深度学习_caffe (4) 基于mnist实例搭建新的神经网络&在caffe中添加层(续1)

2016-05-23 10:22 841 查看
如何在caffe中添加层:

http://blog.sciencenet.cn/home.php?mod=space&uid=1583812&do=blog&id=850247

/article/3710391.html

怎么在caffe中配置每一个层的结构:

http://www.myexception.cn/other/1828071.html

上一篇 看到了lenet_solver.prototxt

其中net: “examples/mnist/lenet_train_test.prototxt”指定了网络模型,打开lenet_train_test.prototxt看一下

name: "LeNet"
layer {
name: "mnist"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
scale: 0.00390625
}
data_param {
source: "examples/mnist/mnist_train_lmdb"
batch_size: 64
backend: LMDB
}
}
layer {
name: "mnist"
type: "Data"
top: "data"
top: "label"
include {
phase: TEST
}
transform_param {
scale: 0.00390625
}
data_param {
source: "examples/mnist/mnist_test_lmdb"
batch_size: 100
backend: LMDB
}
}
layer {
name: "conv1"
type: "Convolution"
bottom: "data"
top: "conv1"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
convolution_param {
num_output: 20
kernel_size: 5
stride: 1
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layer {
name: "pool1"
type: "Pooling"
bottom: "conv1"
top: "pool1"
pooling_param {
pool: MAX
kernel_size: 2
stride: 2
}
}
layer {
name: "conv2"
type: "Convolution"
bottom: "pool1"
top: "conv2"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
convolution_param {
num_output: 50
kernel_size: 5
stride: 1
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layer {
name: "pool2"
type: "Pooling"
bottom: "conv2"
top: "pool2"
pooling_param {
pool: MAX
kernel_size: 2
stride: 2
}
}
layer {
name: "ip1"
type: "InnerProduct"
bottom: "pool2"
top: "ip1"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 500
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layer {
name: "relu1"
type: "ReLU"
bottom: "ip1"
top: "ip1"
}
layer {
name: "ip2"
type: "InnerProduct"
bottom: "ip1"
top: "ip2"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 10
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layer {
name: "accuracy"
type: "Accuracy"
bottom: "ip2"
bottom: "label"
top: "accuracy"
include {
phase: TEST
}
}
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "ip2"
bottom: "label"
top: "loss"
}


全是一层一层的定义,也就是神经网络模型各个层的组合方式声明。

关于这些层结构的参数和详细解释 可以参考caffe官网给出的资料。/article/10561720.html

看到这里可以回顾一下

运行mnist

首先是运行一个.sh文件

time sh examples/mnist/train_lenet.sh

然后.sh文件里是 solver.prototxt文件

solver.prototxt 里面定义了 net 和一些迭代什么的 参数

net是由 另一个prototxt文件详细定义的。

所以到目前为止 如果要仿写模型的话 可以先写好这三个文件夹。搭好框架 然后再最后一个prototxt中 调用各个层 组合自己的模型就好了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: