zoukankan      html  css  js  c++  java
  • Caffe常用层参数介绍

     

    版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/Cheese_pop/article/details/52024980

    DATA

    crop:截取原图像中一个固定patch

    layers {
      name: "data"
      type: DATA
      top: "data"
      top: "label"
      data_param {
        source: "../data/ImageNet/imagenet-train" #数据存放位置
        batch_size: 128 #一次批处理的大小,视内存大小而定。四维数组N*C*H*W中的N
        backend: LMDB #数据库类型,默认为leveldb
      }
      include: { phase: TRAIN } #如果加了这一行的话表示是在训练过程中使用该层,可将TRAIN替换为TEST
    }

    CONVOLUTION

    layer {
      name: "conv"
      type: "Convolution"
      bottom: "data"
      top: "conv"
      param {  
        lr_mult: 1 #权重的学习率 该层lr=lr_mult*base_lr
        decay_mult: 1 #权重的衰减值
      }
      param {  
        lr_mult: 2 #偏置项的学习率
        decay_mult: 0 #偏置项的衰减值
      }
      convolution_param {
        num_output: 96 #该层输出的filter的个数。四维数组N*C*H*W中的W
        kernel_size: 11 #卷积核大小11*11。可设定长kernel_h与宽kernel_w
        stride: 4 #步长,也就是卷积核滑动的距离
        weight_filler { #卷积核初始化方式
          type: "gaussian" #高斯分布
          std: 0.01 #标准差为0.01
        }
        bias_filler { #偏置项初始化方式
          type: "constant" #连续分布
          value: 0
        }
      }
    }

    这里说一下关于weight_filler和bias_filler的几种设定方式:

    TYPEPARAMEXPLAIN
    Constant Value 以常量初始化,初始化值为[Value]
    Gaussian std,mean 以高斯分布方式初始化,均值为[mean],标准差为[std]
    uniform min,max 均匀分布,[min,max]
    xavier scale 均匀分布,[-scale,scale],scale=sqrt(3/K*H*W)

    RELU

    layer {
      name: "relu"
      type: "ReLU"
      bottom: "conv"
      top: "conv"
    }

    Relu标准函数:f(x)=max(0,x)f(x)=max(0,x)。 
    当未指定negative_slope值时,为标准Relu层;指定negative_slope值时,f(x)={x,negative_slope×x,x>0x0f(x)={x,x>0negative_slope×x,x≤0

    LRN

    layer {
      name: "norm"
      type: "LRN"
      bottom: "conv"
      top: "norm"
      lrn_param {
        local_size: 5#对于cross channel LRN,表示需要求和的channel的数量;对于within channel LRN,表示需要求和的空间区域的边长。默认为5
        alpha: 0.0001 #LRN公式中的参数alpha
        beta: 0.75 #LRN公式中的参数beta
      }
    }

    POOLING

    layer {
      name: "pool"
      type: "Pooling"
      bottom: "norm1"
      top: "pool1"
      pooling_param {
        pool: MAX #有三种池化方式:MAX,AVG,STOCHASTIC
        kernel_size: 3 #卷积核大小;可设定长kernel_h与宽kernel_w
        stride: 2 #步长
      }
    }

    INNERPRODUCT

    参数和卷积层几乎一样,仅贴出代码,不做过多解释

    layer {
      name: "fc7"
      type: "InnerProduct"
      bottom: "fc6"
      top: "fc7"
      param { 
        lr_mult: 1
        decay_mult: 1
      }
      param { 
        lr_mult: 2
        decay_mult: 0
      }
      inner_product_param {
        num_output: 4096
        weight_filler {
          type: "gaussian"
          std: 0.005
        }
        bias_filler {
          type: "constant"
          value: 0.1
        }
      }
    }

    ACCURACY

    layer {
      name: "accuracy"
      type: "Accuracy"
      bottom: "fc8"
      bottom: "label"
      top: "accuracy"
      include {phase: TEST}
    }

    可添加

    accuracy_param {
        top_k: 5
      }

    默认为top_1,添加该项后,选择测试top_k准确率。

    SOFTMAX_LOSS

    layers {
      name: "loss"
      type: SOFTMAX_LOSS
      bottom: "pool3"
      bottom: "label"
      top: "loss"
     include: { phase: TRAIN }
    }

    注意,在计算softmax_loss前,将pool3层默认经过了一次softmax计算。 
    另外,以上所有层的name项都是自己随意定的,只要好辨认,不重复就可以。

  • 相关阅读:
    NYOJ The Triangle
    max()和数组里面的max
    sizeof和strlen的区别和联系总结
    继BAT之后 第四大巨头是谁
    专注做好一件事
    编程技术面试的五大要点
    IBM面试记
    创业者,你为什么这么着急?
    硅谷创业教父Paul Graham:如何获得创业idea
    17家中国初创公司的失败史
  • 原文地址:https://www.cnblogs.com/sddai/p/10200419.html
Copyright © 2011-2022 走看看