1、基本的layer定義,參數
1、基本的layer定義,參數
如何利用caffe定義一個網路,首先要瞭解caffe中的基本介面,下面分別對五類layer進行介紹
Vision Layers
可視化層來自於標頭檔 Header: ./include/caffe/vision_layers.hpp 一般輸入和輸出都是映像,這一層關注映像的2維的幾何結構,並根據此結構對輸入進行處理,特別是,大多數可視化層都通過對一些地區的操作,產生相關的地區進行輸出,相反的是其他層忽視結合結構,只是把輸入當作一個一維的大規模的向量進行處理。
Convolution:
Convolution
Layer type: Convolution
CPU implementation: ./src/caffe/layers/convolution_layer.cpp
CUDA GPU implementation: ./src/caffe/layers/convolution_layer.cu
Parameters (ConvolutionParameter convolution_param)
Required:
num_output (c_o): the number of filters//卷積的個數kernel_size (or kernel_h and kernel_w): specifies height and width of each filter//每個卷積的sizeStrongly Recommendedweight_filler [default type: 'constant' value: 0]Optionalbias_term [default true]: specifies whether to learn and apply a set of additive biases to the filter outputs//位移量pad (or pad_h and pad_w) [default 0]: specifies the number of pixels to (implicitly) add to each side of the input//pad是對輸入映像的擴充,邊緣增加的大小stride (or stride_h and stride_w) [default 1]: specifies the intervals at which to apply the filters to the input//定義引用卷積的區間group (g) [default 1]: If g > 1, we restrict the connectivity of each filter to a subset of the input. Specifically, the input and output channels are separated into g groups, and the ith output group channels will be only connected to the ith input group channels.//限定輸入的連通性,輸入通道被分成g組,輸出和輸入的聯通性是一致的,第i個輸出通道僅僅和第i個輸入通道聯通。
每個filter產生一個featuremap.
輸入的大小: n∗ci(channel)∗hi(height)∗wi(weight) n*c_i(channel)*h_i(height)*w_i(weight)
輸出的大小:
n∗co∗ho∗wo,whereho=(hi+2∗padh−kernelh)/strideh+1andwo likewise. n * c_o * h_o * w_o, where h_o = (h_i + 2 * pad_h - kernel_h) / stride_h + 1 and w_o\ likewise.
Pooling:
池化層的作用是壓縮特徵的維度,把相鄰的地區變成一個值。目前的類型包括:最大化,平均,隨機
參數有:
kernel_size,filter的大小
pool:類型
pad:每個輸入映像的增加的邊界的大小
stride:filter之間的大小
輸入大小:
n∗c∗hi∗wi n * c * h_i * w_i
輸出大小:
n∗c∗ho∗wo n * c * h_o * w_o, where h_o and w_o are computed in the same way as convolution.
Local Response Normalization (LRN):
Layer type: LRN
CPU Implementation: ./src/caffe/layers/lrn_layer.cpp
CUDA GPU Implementation: ./src/caffe/layers/lrn_layer.cu
Parameters (LRNParameter lrn_param)
Optional
local_size [default 5]: the number of channels to sum over (for cross channel LRN) or the side length of the square region to sum over (for within channel LRN)
alpha [default 1]: the scaling parameter (see below)
beta [default 5]: the exponent (see below)
norm_region [default ACROSS_CHANNELS]: whether to sum over adjacent channels (ACROSS_CHANNELS) or nearby spatial locaitons (WITHIN_CHANNEL)
The local response normalization layer performs a kind of “lateral inhibition” by normalizing over local input regions. In ACROSS_CHANNELS mode, the local regions extend across nearby channels, but have no spatial extent (i.e., they have shape local_size x 1 x 1). In WITHIN_CHANNEL mode, the local regions extend spatially, but are in separate channels (i.e., they have shape 1 x local_size x local_size). Each input value is divided by (1+(α/n)∑ix2i)β (1+(\alpha/n)\sum_ix_i^2)^{\beta}, where