caffe——經常使用layer參數

caffe的model是須要用prototxt來定義的,若是要訓練本身的model咱們就須要本身來寫prototxt文件,這篇博文主要寫caffe的layer是如何來定義的。html

參考:http://caffe.berkeleyvision.org/tutorial/layers.htmlapp

layer的源代碼在$caffe-master/src/caffe/layerside

卷積層

  • layer類型:Convolution
  • 參數:(ConvolutionParameter convolution_param)
    • 必選
      •   num_output (c_o):filter的的數目
      •       kernel_size (or kernel_h and kernel_w):filter的尺寸,即長、寬
    •  推薦
      •   weight_filler:對權值的初始化設置,默認是{type:"constant" value:0},即初始化爲常數0。type也能夠選擇高斯分佈,這須要給定標準差和均值
    • 可選
      •      bias_term [default true]:是否對filter設定偏置項,默認爲true
      •      pad (or pad_h and pad_w) [default 0]:對輸入的每一個邊進行填充像素的個數,默認爲0
      •    stride (or stride_h and stride_w) [default 1]:filter在輸入圖像上的滑動步長
      •    group (g) [default 1]:當g>1時,將輸入和輸出的channels分爲g個組,第i個輸入group channels只與第i個輸出group channels相對應。
  • 輸入

    n * c_i * h_i * w_i學習

  • 輸出

     n * c_o * h_o * w_o,其中h_o = (h_i + 2 * pad_h - kernel_h) / stride_h + 1,w_o也相似spa

 

 layer {
      name: "conv1"  //層的名字
      type: "Convolution" //層的類型
      bottom: "data" //底層的blob
      top: "conv1" //上層的blob
      //filters的學習率和衰減參數
      param { lr_mult: 1 decay_mult: 1 }
      // biases的學習率和衰減參數
      param { lr_mult: 2 decay_mult: 0 }
      convolution_param {
        num_output: 96     # learn 96 filters
        kernel_size: 11    # each filter is 11x11
        stride: 4          # step 4 pixels between each filter application
        weight_filler {
          type: "gaussian" // 用Gaussian分佈初始化
          std: 0.01        // 標準差爲0.01,均值默認爲0
        }
        bias_filler {
          type: "constant" //初始化爲常數
          value: 0
        }
      }
    }

 

 池化層

  • layer類型:Pooling
  • 參數PoolingParameter pooling_param
    • 必選
      •   kernel_size:filter的尺寸
    • 可選  
      •   pool [default MAX]:pool的類型,MAX、AVE或者 STOCHASTIC
      •        pad (or pad_h and pad_w) [default 0]對輸入的每一個邊進行填充像素的個數,默認爲0
      •       stride (or stride_h and stride_w) [default 1]filter在輸入圖像上的滑動步長
  • 輸入

    n * c_i * h_i * w_icode

  • 輸出

      n * c_o * h_o * w_o,其中h_o = (h_i + 2 * pad_h - kernel_h) / stride_h + 1,w_o也相似htm

 

layer {
  name: "pool1"
  type: "Pooling"
  bottom: "conv1"
  top: "pool1"
  pooling_param {
    pool: MAX
    kernel_size: 3 # pool over a 3x3 region
    stride: 2      # step two pixels (in the bottom blob) between pooling regions
  }
}

 

 ReLU層

layer {
  name: "relu1"
  type: "ReLU"
  bottom: "conv1"
  top: "conv1"
}

 Dropout層

 

layer {
  name: "drop7"
  type: "Dropout"
  bottom: "fc7"
  top: "fc7"
  dropout_param {
    dropout_ratio: 0.5 //dropout率
  }
}

 

全鏈接層

  • layer類型:Pooling
  • 參數:InnerProductParameter inner_product_param
    • 必選
      •   kernel_size:filter的尺寸
    •  推薦
      •   weight_filler:對權值的初始化設置,默認是{type:"constant" value:0},即初始化爲常數0。type也能夠選擇高斯分佈,這須要給定標準差和均值
    • 可選
      •   bias_term [default true]:是否對filter設定偏置項,默認爲true
      •        bias_filler [default type: 'constant' value: 0]
  • 輸入

      n * c_i * h_i * w_iblog

  • 輸出

      n * c_o * h_o * w_o,其中h_o = (h_i + 2 * pad_h - kernel_h) / stride_h + 1,w_o也相似get

 

layer {
  name: "fc8"
  type: "InnerProduct"
  param { lr_mult: 1 decay_mult: 1 }
  param { lr_mult: 2 decay_mult: 0 }
  inner_product_param {
    num_output: 1000
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
  bottom: "fc7"
  top: "fc8"
}

 

 SoftMax層

layer {
  name: "loss"
  type: "SoftmaxWithLoss"
  bottom: "fc8"
  bottom: "label"
  top: "loss"
}

 Accuracy層

 

layer {
  name: "accuracy"
  type: "Accuracy"
  bottom: "fc8"
  bottom: "label"
  top: "accuracy"
  include {
    phase: TEST
  }
}
相關文章
相關標籤/搜索