- Vision Layers
1.1 卷積層(Convolution)
類型:CONVOLUTION
例子
layers {
name: "conv1"
type: CONVOLUTION
bottom: "data"
top: "conv1"
blobs_lr: 1 # learning rate multiplier for the filters
blobs_lr: 2 # learning rate multiplier for the biases
weight_decay: 1 # weight decay multiplier for the filters
weight_decay: 0 # weight decay multiplier for the biases
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" # initialize the filters from a Gaussian
std: 0.01 # distribution with stdev 0.01 (default mean: 0) }
bias_filler {
type: "constant" # initialize the biases to zero (0) value: 0 }
}
}
**blobs_lr: **學(xué)習(xí)率調(diào)整的參數(shù),在上面的例子中設(shè)置權(quán)重學(xué)習(xí)率和運(yùn)行中求解器給出的學(xué)習(xí)率一樣,同時(shí)是偏置學(xué)習(xí)率為權(quán)重的兩倍。 (設(shè)為0時(shí)稱為freeze參數(shù))
weight_decay:
卷積層的重要參數(shù)
必須參數(shù):
num_output (c_o):過濾器的個(gè)數(shù)
kernel_size (or kernel_h and kernel_w):過濾器的大小
可選參數(shù):
weight_filler [default type: 'constant' value: 0]:參數(shù)的初始化方法
bias_filler:偏置的初始化方法
bias_term [default true]:指定是否是否開啟偏置項(xiàng)
pad (or pad_h and pad_w) [default 0]:指定在輸入的每一邊加上多少個(gè)像素
stride (or stride_h and stride_w) [default 1]:指定過濾器的步長
**group (g) [default 1]: **If g > 1, we restrict the connectivityof each filter to a subset of the input. Specifically, the input and outputchannels are separated into g groups, and the ith output group channels will beonly connected to the ith input 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通過同樣的方法計(jì)算。
1.2 池化層(Pooling)
類型:POOLING
例子
layers {
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
}}
卷積層的重要參數(shù)
必需參數(shù):
kernel_size (or kernel_h and kernel_w):過濾器的大小
可選參數(shù):
pool [default MAX]:pooling的方法,目前有MAX, AVE, 和STOCHASTIC三種方法
pad (or pad_h and pad_w) [default 0]:指定在輸入的每一遍加上多少個(gè)像素
stride (or stride_h and stride_w) [default1]:指定過濾器的步長
通過池化后的大小變化:
輸入: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通過同樣的方法計(jì)算。
1.3 Local Response Normalization (LRN)
類型:LRN
Local ResponseNormalization是對一個(gè)局部的輸入?yún)^(qū)域進(jìn)行的歸一化(激活a被加一個(gè)歸一化權(quán)重(分母部分)生成了新的激活b),有兩種不同的形式,一種的輸入?yún)^(qū)域?yàn)橄噜彽腸hannels(cross channel LRN),另一種是為同一個(gè)channel內(nèi)的空間區(qū)域(within channel LRN)

可選參數(shù):
local_size [default 5]:對于cross channel LRN為需要求和的鄰近c(diǎn)hannel的數(shù)量;對于within channel LRN為需要求和的空間區(qū)域的邊長
alpha [default 1]:scaling參數(shù)
beta [default 5]:指數(shù)
**norm_region [default ACROSS_CHANNELS]: **選擇哪種LRN的方法ACROSS_CHANNELS 或者WITHIN_CHANNEL
- Loss Layers
深度學(xué)習(xí)是通過最小化輸出和目標(biāo)的Loss來驅(qū)動(dòng)學(xué)習(xí)。
2.1 Softmax
類型: SOFTMAX_LOSS2.2 Sum-of-Squares / Euclidean
類型: EUCLIDEAN_LOSS
2.3 Hinge / Margin
類型: HINGE_LOSS例子:
L1 Normlayers
{ name: "loss"
type: HINGE_LOSS
bottom: "pred"
bottom: "label"}
L2 Normlayers {
name: "loss"
type: HINGE_LOSS
bottom: "pred"
bottom: "label"
top: "loss"
hinge_loss_param
{ norm: L2 }}
可選參數(shù):
**norm [default L1]: **選擇L1或者 L2范數(shù)
輸入:
n * c * h * wPredictions
n * 1 * 1 * 1Labels
輸出
1 * 1 * 1 * 1Computed Loss
2.4 Sigmoid Cross-Entropy
類型:SIGMOID_CROSS_ENTROPY_LOSS2.5 Infogain
類型:INFOGAIN_LOSS2.6 Accuracy and Top-k
類型:ACCURACY 用來計(jì)算輸出和目標(biāo)的正確率,事實(shí)上這不是一個(gè)loss,而且沒有backward這一步。
- 激勵(lì)層(Activation / Neuron Layers)
一般來說,激勵(lì)層是element-wise的操作,輸入和輸出的大小相同,一般情況下就是一個(gè)非線性函數(shù)。
3.1 ReLU / Rectified-Linear and Leaky-ReLU
類型: RELU例子:
layers { name: "relu1" type: RELU bottom: "conv1" top: "conv1"}
可選參數(shù):
negative_slope [default 0]:指定輸入值小于零時(shí)的輸出。
ReLU是目前使用做多的激勵(lì)函數(shù),主要因?yàn)槠涫諗扛欤⑶夷鼙3滞瑯有Ч?/strong>
標(biāo)準(zhǔn)的ReLU函數(shù)為max(x, 0),而一般為當(dāng)x > 0時(shí)輸出x,但x <= 0時(shí)輸出negative_slope。RELU層支持in-place計(jì)算,這意味著bottom的輸出和輸入相同以避免內(nèi)存的消耗。
3.2 Sigmoid
類型: SIGMOID例子:
layers { name: "encode1neuron" bottom: "encode1" top: "encode1neuron" type: SIGMOID}

3.3 TanH / Hyperbolic Tangent
類型: TANH例子:
layers { name: "encode1neuron" bottom: "encode1" top: "encode1neuron" type: SIGMOID}
TANH層通過 tanh(x) 計(jì)算每一個(gè)輸入x的輸出,函數(shù)如下圖。

3.3 Absolute Value
類型: ABSVAL例子:
layers { name: "layer" bottom: "in" top: "out" type: ABSVAL}
ABSVAL層通過 abs(x) 計(jì)算每一個(gè)輸入x的輸出。
3.4 Power
類型: POWER例子:
layers { name: "layer" bottom: "in" top: "out" type: POWER power_param { power: 1 scale: 1 shift: 0 }}
可選參數(shù):power [default 1]scale [default 1]shift [default 0]POWER層通過 (shift + scale * x) ^ power計(jì)算每一個(gè)輸入x的輸出。
3.5 BNLL
類型: BNLL例子:
layers { name: "layer" bottom: "in" top: "out" type: BNLL}
BNLL (binomial normal log likelihood) 層通過 log(1 + exp(x)) 計(jì)算每一個(gè)輸入x的輸出。
- 數(shù)據(jù)層(Data Layers)
數(shù)據(jù)通過數(shù)據(jù)層進(jìn)入Caffe,數(shù)據(jù)層在整個(gè)網(wǎng)絡(luò)的底部。數(shù)據(jù)可以來自高效的數(shù)據(jù)庫(LevelDB 或者 LMDB),直接來自內(nèi)存。如果不追求高效性,可以以HDF5或者一般圖像的格式從硬盤讀取數(shù)據(jù)。
4.1 Database
類型:DATA
必須參數(shù):
source:包含數(shù)據(jù)的目錄名稱
batch_size:一次處理的輸入的數(shù)量
可選參數(shù):
rand_skip:在開始的時(shí)候從輸入中跳過這個(gè)數(shù)值,這在異步隨機(jī)梯度下降(SGD)的時(shí)候非常有用
backend [default LEVELDB]: 選擇使用 LEVELDB 或者 LMDB
4.2 In-Memory
類型: MEMORY_DATA必需參數(shù):batch_size, channels, height, width: 指定從內(nèi)存讀取數(shù)據(jù)的大小The memory data layer reads data directly from memory, without copying it. In order to use it, one must call MemoryDataLayer::Reset (from C++) or Net.set_input_arrays (from Python) in order to specify a source of contiguous data (as 4D row major array), which is read one batch-sized chunk at a time.
4.3 HDF5 Input
類型: HDF5_DATA必要參數(shù):source:需要讀取的文件名batch_size:一次處理的輸入的數(shù)量
4.4 HDF5 Output
類型: HDF5_OUTPUT必要參數(shù):file_name: 輸出的文件名HDF5的作用和這節(jié)中的其他的層不一樣,它是把輸入的blobs寫到硬盤
4.5 Images
類型: IMAGE_DATA必要參數(shù):source: text文件的名字,每一行給出一張圖片的文件名和labelbatch_size: 一個(gè)batch中圖片的數(shù)量可選參數(shù):rand_skip:在開始的時(shí)候從輸入中跳過這個(gè)數(shù)值,這在異步隨機(jī)梯度下降(SGD)的時(shí)候非常有用shuffle [default false]****new_height, new_width: 把所有的圖像resize到這個(gè)大小
4.6 Windows
類型:WINDOW_DATA4.7 Dummy
類型:DUMMY_DATADummy 層用于development 和debugging。具體參數(shù)DummyDataParameter。
- 一般層(Common Layers)
5.1 全連接層Inner Product
類型:INNER_PRODUCT例子:layers { name: "fc8" type: INNER_PRODUCT blobs_lr: 1 # learning rate multiplier for the filters blobs_lr: 2 # learning rate multiplier for the biases weight_decay: 1 # weight decay multiplier for the filters weight_decay: 0 # weight decay multiplier for the biases inner_product_param { num_output: 1000 weight_filler { type: "gaussian" std: 0.01 } bias_filler { type: "constant" value: 0 } } bottom: "fc7" top: "fc8"}
必要參數(shù):
num_output (c_o):過濾器的個(gè)數(shù)
可選參數(shù):
weight_filler [default type: 'constant' value: 0]:參數(shù)的初始化方法
bias_filler:偏置的初始化方法
bias_term [default true]:指定是否是否開啟偏置項(xiàng)
通過全連接層后的大小變化:
輸入:n * c_i * h_i * w_i
輸出:n * c_o * 1 *1
5.2 Splitting
類型:SPLITSplitting層可以把一個(gè)輸入blob分離成多個(gè)輸出blobs。這個(gè)用在當(dāng)需要把一個(gè)blob輸入到多個(gè)輸出層的時(shí)候。5.3 Flattening
類型:FLATTENFlattening是把一個(gè)輸入的大小為n * c * h * w變成一個(gè)簡單的向量,其大小為 n * (chw) * 1 * 1。5.4 Concatenation
類型:CONCAT例子:layers { name: "concat" bottom: "in1" bottom: "in2" top: "out" type: CONCAT concat_param { concat_dim: 1 }}
可選參數(shù):
concat_dim [default 1]:0代表鏈接num,1代表鏈接channels
通過全連接層后的大小變化:
輸入:從1到K的每一個(gè)blob的大小n_i * c_i * h * w
輸出:
如果concat_dim = 0: (n_1 + n_2 + ... + n_K) *c_1 * h * w,需要保證所有輸入的c_i 相同。
如果concat_dim = 1: n_1 * (c_1 + c_2 + ... +c_K) * h * w,需要保證所有輸入的n_i 相同。
通過Concatenation層,可以把多個(gè)的blobs鏈接成一個(gè)blob。
5.5 Slicing
The SLICE layer is a utility layer that slices an input layer to multiple output layers along a given dimension (currently num or channel only) with given slice indices.5.6 Elementwise Operations
類型:ELTWISE5.7 Argmax
類型:ARGMAX5.8 Softmax
類型:SOFTMAX5.9 Mean-Variance Normalization
類型:MVN