美文网首页
LeNet5模型学习

LeNet5模型学习

作者: 黑恶歌王 | 来源:发表于2018-09-01 11:14 被阅读0次

    这里是caffe框架下一个经典的深度学习模型LeNet-5模型,它应用到了邮政编码中。(课本讲到)
    下面贴出代码并且又一些注释。

    name:"LeNet"    //名称叫做LeNet
    layer {                //定义一个层(例如池化,卷积这种)
      name:"mnist"    //层的名字为"mnist"
      type:"Data"        //层的类型微数据层
      top:"data"            //层的输出blob有两个data和label1  
      top:"label1"
      include {
          phase:TRAIN          //该层只在训练阶段有效
    }
      transform_param{  
          scale:0.00390625
    }
    data_param{              //数据层参数
        source:"examples/mnist/mnist_train_lmdb"      //这里是LMDB的路径,也就是说其实应该是生成好了二进制文件了。  
        batch_size:64          //批量数目,他的意思是一次读64张图。(这里大小可以自己自行设定,具体情况根据自己的显存gpu来定)
        backend:LMDB
     }
    }
    layer {                  //一个新的数据层,名字也叫mnist,输出blob也是data和label1,但是这里定义的参数只在分类阶段有效。
        name:"mnist"
        type:"Data"
        top:"data"
        top:"label1"
        include{
             phase:TEST         //但是这里应该出卖了他是测试阶段有效。
      }
    transform_param  {
       scale:0.00390625
    }
    data_param {
          source:"examples/mnist/mnist_test_lmdb"
          batch_size:100
          backend:LMDB`
      }
    }
    layer {   //定义一个新的卷积层conv1,输入为blob为data,输出blob为conv1
        name:"conv1"
        type:"Convolution"
        bottom:"data"           //我理解的既然top是所谓的输出,那么bottom就是输入咯?
        top:"conv1"
        param    {
                lr_mult:2
          }
       convolution_param   {          //卷积计算参数  
              num_output:20          //输出feature map数目为20
              kernel_size:5            //卷积核尺寸,5*5  
              stride:1                       //卷积输出跳跃间隔,1表示连续输出,无跳跃。
              weight_filler    {            //权值使用xavier填充器
                    type:"constant"
                }
              }
    }
    layer  {                            //定义新的下采样层pool1,输入blob为conv1,输出blob为pool1.
               name:"pool1"
                type:"Pooling"
                bottom:"conv1"
                top:"pool1"
                pooling_gram    {          //下采样参数
                        pooling:MAX          //使用最大值下采样方法
                        kernel_size:2        //下采样窗口尺寸2*2
                        stride:2            //下采样输出跳跃间隔2*2
                    }
    }
    layer   { //新的卷积层,和conv1类似
          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    {          //新的下采样层,和pooling1相似
          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:500            //该层输出元素是500个
                  weigh_filler    {
                        type:"xavier"
                  }
                  bias_filler    {
                        type: "constant"
                        }
          }
    }
    layer  { //新的全连接层,用relu的方法。
          name:"ip2"
          type:InnerProduct
          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  {
                      typr:"constant"
                }
          }
    }
    layer    {          //  分类准确层设定,只在测试阶段有效,输入blob为ip2和label1,输出blob为accuracy,该层用来计算分类准确度。
              name:"accuracy"
              type:"Accuracy"
              bottom:"ip2"
              bottom:"label1"
              top:"accuracy"
              include    {
                      phase:TEST
                }
        }
    layer    {          //损失层,损失函数用softmaxloss,输入blob为ip2和label1,输出blob为loss
                name:"loss"
                 type:"SoftmaxWithLoss"
                 bottom:"ip2"
                 bottom"label1"
                 top:"loss"
      }
    

    相关文章

      网友评论

          本文标题:LeNet5模型学习

          本文链接:https://www.haomeiwen.com/subject/aebywftx.html