区分caffe中train.prototxt,solver.prototxt,deploy.prototxt等文件(1)

lenet_solver.prototxt

solver.prototxt的主要作用就是交替调用前向算法和后向算法来更新参数,从而最小化loss,实际上就是一种迭代的优化算法。

# The train/test net protocol buffer definition
net: "/home/yan/caffe-master/models/mnist/lenet_train_test.prototxt"
# test_iter specifies how many forward passes the test should carry out.
# In the case of MNIST, we have test batch size 100 and 100 test iterations,
# covering the full 10,000 testing images.
test_iter: 100            #预测阶段迭代100次可以覆盖全部10000个测试集
# Carry out testing every 500 training iterations.
test_interval: 500        #训练每迭代500次,进行一次预测
# The base learning rate, momentum and the weight decay of the network.
base_lr: 0.01             #基础学习率
momentum: 0.9             #动量
weight_decay: 0.0005      #权重衰减
# The learning rate policy
lr_policy: "inv"          #采用衰减学习策略
gamma: 0.0001
power: 0.75
# Display every 100 iterations
display: 100              #每经过100次迭代,在屏幕上打印一次log
# The maximum number of iterations
max_iter: 10000           #最大迭代次数
# snapshot intermediate results
snapshot: 5000            #每5000次迭代打印一次快照
#设置保存路径
snapshot_prefix: "/home/yan/caffe-master/models/mnist/lenet" 
# solver mode: CPU or GPU
solver_mode: GPU          #caffe求解模式为gpu

lenet_train_test.prototxt

name: "LeNet"
layer {
  name: "mnist"       #输入层的名称mnist
  type: "Data"        #输入层的类型data层
  top: "data"         #层的输出blob有两个:data和label
  top: "label"
  include {
    phase: TRAIN      #训练阶段,该层参数只在训练阶段有效
  }
  transform_param {
    scale: 0.00390625 #输入像素归一化到【0,1】 1/256=0.00390625
  }
  data_param {
    source: "examples/mnist/mnist_train_lmdb"  #LMDB的路径
    batch_size: 64                             #一次读取64张图
    backend: LMDB                              #数据格式为LMDB
  }
}
layer { #一个新数据层,名字也叫作mnist,输出blob也是data和label,但是这里定义的参数只在分类阶段有效
  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                 #batchsize大小,乘以test_iter = 测试集大小
    backend: LMDB
  }
}
layer {
  name: "conv1"
  type: "Convolution"
  bottom: "data"     #本层使用上一层的data,生成下一层conv1的blob
  top: "conv1"
  param {
    lr_mult: 1       #权重参数w的学习率倍数,1表示保持与全局参数一致
  }
  param {
    lr_mult: 2       #偏置参数b的学习率倍数,是全局参数的2倍
  }
  convolution_param {
    num_output: 20      #输出单元数20
    kernel_size: 5      #卷积核大小为5*5
    stride: 1           #步长为1
    weight_filler {     #权值使用xavier填充器
      type: "xavier"    
    }
    bias_filler {       #bias使用常数填充器,默认为0
      type: "constant"  
    }
  }
}
layer {
  name: "pool1"
  type: "Pooling"
  bottom: "conv1"      #本层的上一层是conv1,生成下一层Pool1的blob
  top: "pool1"
  pooling_param {     #下采样参数
    pool: MAX         #使用最大值下采样方法
    kernel_size: 2    #pooling核是2*2
    stride: 2        #pooling步长是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 {                    #新的全连接层,输入blob为pool2,输出blob为ip1
  name: "ip1"
  type: "InnerProduct"
  bottom: "pool2"
  top: "ip1"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  inner_product_param {    #全连接层的参数
    num_output: 5      #输出500个节点
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}
layer {                   #新的非线性层,用RELU方法
  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      #输出10个单元
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}
layer {    #分类准确率层(计算网络输出相对目标值的准确率),只在testing阶段有效,输入blob为iP2和label,输出blob为accuracy
  name: "accuracy"     #该层用于计算分类准确率
  type: "Accuracy"
  bottom: "ip2"
  bottom: "label"
  top: "accuracy"
  include {
    phase: TEST
  }
}
layer {   #损失层,损失函数采用softmaxloss,输入blob为iP2和label,输出blob为loss
  name: "loss"
  type: "SoftmaxWithLoss"
  bottom: "ip2"
  bottom: "label"
  top: "loss"
}

deploy.prototxt

name: "LeNet"
layer {
  name: "data"
  type: "Input"
  top: "data"
  input_param {shape:{dim:1 dim:1 dim:28  dim:28}}
  # dim:1 batchsize  dim:1 number of colour channels - rgb
  # dim:28 width dim:28 height 
}
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
  }
}
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
  }
}
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
  }
}
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
  }
}
layer {
  name: "prob"
  type: "Softmax"
  bottom: "ip2"
  top: "prob"
}
deploy.prototxt是测试时用的文件。可以看出,lenet_train_test.prototxt删除再改变一些东西就变成了deploy.prototxt文件,最大的区别就是deploy.prototxt文件删除了lenet_train_test.prototxt文件开始的输入数据test部分;删除了分类准确率层accuracy;把trian部分的输入数据部分修改,告诉我们输入维度;将损失层loss改成了prob。



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值