Caffe Tutorial : 5.Layer Catalogue (Kor) - ys7yoo/BrainCaffe GitHub Wiki
Layers)
๊ณ์ธต (Caffe ๋ชจ๋ธ์ ์์ฑํ๊ธฐ ์ํด, Protocol Buffer Definition file (prototxt)์์ ๋ชจ๋ธ์ ์ค๊ณ๋ฅผ ์ ์ํด์ผํ ํ์๊ฐ ์๋ค. Caffe ๊ณ์ธต๋ค๊ณผ ํ๋ผ๋ฏธํฐ๋ caffe.proto์ ํ๋ก์ ํธ์ ๋ํ์ฌ protocol buffer definitions(prototxt)์ ์ ์๋์ด ์๋ค.
1. ๋ฐ์ดํฐ ๊ณ์ธต (Data Layer)
๋ฐ์ดํฐ๋ ๋ฐ์ดํฐ ๊ณํ์ ํตํ์ฌ Caffe๋ก ๋ค์ด๊ฐ๋ค: ์ด๋ค์ ๋ง์ ์ตํ์์ ๋์ฌ์๋ค. ๋ฐ์ดํฐ๋ ํจ์จ์ ์ธ ๋ฐ์ดํฐ ๋ฒ ์ด์ค(LevelDB ํน์ LMDB)์์ ๋ถ๋ฌ์ค๋ฉฐ, ํน์ ํจ์จ์ฑ์ด ๋ณ๋ก ์ค๋ํ ์ฌํญ์ด ์๋๋ผ๋ฉด, HDF5๋ด์ ๋์คํฌ ์ ํ์ผ์ด๋ ์ผ๋ฐ ์ด๋ฏธ์ง ํํ๋ก ๋ฉ๋ชจ๋ฆฌ๋ก๋ถํฐ ๋ฐ๋ก ๋ถ๋ฌ์ ์ฌ์ฉํ๋ค.
์ผ๋ฐ ์ ๋ ฅ ์ฒ๋ฆฌ(ํ๊ท ์ฐ์ฐ, ์ค์ผ์ผ๋ง, ๋ฌด์์ ํฌ๋กญํ, ๋ฏธ๋ฌ๋ง)์ ๊ณ์ธต๋ค์ค ์ผ๋ถ๋ฅผ ์ฌ์ฉํด TransformationParameters๋ฅผ ๋ช ์ํด์ค์ผ๋ก์จ ์ฌ์ฉ์ด ๊ฐ๋ฅํ๋ค. ํธ์ค์น, ์ค์ผ์ผ, ๊ทธ๋ฆฌ๊ณ ํฌ๋กญ ๋ ์ด์ด๋ TransformationParameter๋ฅผ ์ฌ์ฉํ ์ ์๋ค๋ฉด ์ ๋ ฅ์ ๋ณํํ๋๋ฐ์์ด ๋์์ ์ค ๊ฒ์ด๋ค.
-
๊ณ์ธต:
-
์ด๋ฏธ์ง ๋ฐ์ดํฐ(Image Data) - ์ ์ ๋์ง ์์ ๋ ๊ฒ์ ๋ฐ์ดํฐ๋ฅผ ์ฝ๋๋ค.
-
๋ฐ์ดํฐ๋ฒ ์ด์ค(Database) - (LEVELDB ํน์ LMDB)์์ ๋ฐ์ดํฐ๋ฅผ ๋ฐ์ ์ฝ๋๋ค.
-
HDF5์ ๋ ฅ(HDF5 Input) - read HDF5๋ฐ์ดํฐ๋ฅผ ์ฝ๊ณ ์์ ์ฐจ์์ ๋ฐ์ดํฐ๋ฅผ ํ์ฉํ๋ค.
-
HDF5 ์ถ๋ ฅ(HDF5 Output) - HDF5ํํ๋ก ๋ฐ์ดํฐ๋ฅผ ๊ธฐ๋กํ๋ค.
-
์ ๋ ฅ(Input) - ํจ์จ์ ์ผ๋ก ์ฌ์ฉ๋์ด์ง ๋คํธ์๋ค์ ๋ํ์ฌ ์ ํ์ ์ผ๋ก ์ฌ์ฉ์ด ๋์ด์ง๋ค.
-
์๋์ฐ ๋ฐ์ดํฐ(Window Data) - ์๋์ฐ ๋ฐ์ดํฐ ํ์ผ์ ์ฝ์ด์จ๋ค.
-
๋ฉ๋ชจ๋ฆฌ ๋ฐ์ดํฐ(Memory Data) - ๋ฉ๋ชจ๋ฆฌ๋ก๋ถํฐ ๋ฐ๋ก ๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฌ์จ๋ค.
-
์ฐ๋๊ธฐ ๋ฐ์ดํฐ(Dummy Data) - ์ ์ ๋ฐ์ดํฐ๋ ๋๋ฒ๊น ์ ์ํ ๊ฒ.
ํ์ด์ฌ ๊ณ์ธต์ ์ฌ์ฉ์์ ์ ๋ฐ์ดํฐ ๊ณ์ธต์ ์์ฑํ๋๋ฐ ํจ๊ณผ์ ์ผ ์๋ ์๋ค.
#------------------------- W I P ------------------------ #------------------------- W I P ------------------------ #------------------------- W I P ------------------------ #------------------------- W I P ------------------------ #------------------------- W I P ------------------------
2. ์๊ฐ ๊ณ์ธต (Vision Layers)
- Header : ./include/caffe/vision_layers.hpp
์๊ฐ ๊ณ์ธต๋ค์ ๋ณดํต ์ ๋ ฅ์ผ๋ก ์ด๋ฏธ์ง๋ฅผ ๋ฐ์๋ค์ฌ์ ์ถ๋ ฅ์ผ๋ก ๋ค๋ฅธ ์ด๋ฏธ์ง๋ฅผ ์์ฐํ๋ค. ํ์ค์ธ๊ณ์์ ์ ํ์ ์ธ "์ด๋ฏธ์ง"๋ ์๋ง ํ๋ฐฑ ์ด๋ฏธ์ง๋ก์จ ๋จ์ผ ์ ์ฑ๋ (c=1) ์ด๋, RGB (red, green, blue) ์ด๋ฏธ์ง๋ก์จ ์ธ๊ฐ์ ์ ์ฑ๋ (c = 3)์ ๊ฐ์ง๋ค. ํ์ง๋ง ์ด ๊ธ ๋งฅ๋ฝ์์, ์ด๋ฏธ์ง์ ํน์ฑ์ ๊ตฌ๋ณํ๋ ๊ฒ์ ์ด๋ฏธ์ง์ ๊ณต๊ฐ์ ๊ตฌ์กฐ์ด๋ค. : ๋ณดํต ์ด๋ฏธ์ง๋ ์ฝ๊ฐ์ ์ฌ์ํ์ง ์์ ๋์ด h>1 ๊ทธ๋ฆฌ๊ณ ๋๋น w>1๋ฅผ ๊ฐ์ง๋ค. ์ด๋ฌํ 2D ๊ธฐํํ ๊ตฌ์กฐ๋ ์์ฐ์ค๋ฝ๊ฒ ๊ทธ์์ฒด๋ฅผ ์ ๋ ฅ์ ์ด๋ป๊ฒ ์ฒ๋ฆฌํ ์ง์ ๋ํ ํ์คํ ๊ฒฐ์ ์ ๋ด๋ฆฐ๋ค. ์ค์ ๋ก ๋๋ถ๋ถ์ ์๊ฐ ๊ณ์ธต๋ค์ ์ถ๋ ฅ์ ์ง์ญ๊ณผ ์ผ์นํ๋ ๊ฒ์ ์์ฐํ๊ธฐ ์ํด ์ ๋ ฅ์ ๋ช๋ช ์ง์ญ์ ํน์ ํ ์์ฉ์ ์ ์ฉ์ํด์ ์ํด ํ๋ํ๋ค. ๋ฐ๋๋ก, ๋ค๋ฅธ ๊ณ์ธต๋ค์ (๋ช๋ช์ ์์ธ๋ฅผ ํฌํจํด) ์ ๋ ฅ์ ๊ณต๊ฐ์ ๊ตฌ์กฐ๋ฅผ ๋ฌด์ํ๋ค. ์ด๋ ํจ์จ์ ์ผ๋ก chw ์ฐจ์์ "ํ๋์ ํฐ ๋ฒกํฐ" ๋ก์จ ๊ทธ๊ฒ์ ๋ค๋ฃจ๊ธฐ ๋๋ฌธ์ด๋ค.
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)
- ์๊ตฌ์ฌํญ.
- num_output (c_o): the number of filters
- kernel_size (or kernel_h and kernel_w): ๊ฐ ํํฐ์ ๋๋น์ ๋์ด๋ฅผ ๋ช ์ํ๋ค.
- ๊ฐ๋ ฅํ ๊ถ๊ณ ์ฌํญ.
- weight_filler [default type: 'constant' value: 0]
- ์ถ๊ฐ ์ต์ .
- bias_term [default true]: ํํฐ ์ถ๋ ฅ์ ์ถ๊ฐ์ ์ธ ํธํฅ์ ์ง๋จ์ ์ ์ฉํ ๊ฒ์ธ์ง ํ์ต์ํฌ ๊ฒ์ธ์ง ๋ช ์ํ๋ค.
- pad (or pad_h and pad_w) [default 0]: (์๋ฌต์ ์ผ๋ก) ์ ๋ ฅ์ ๊ฐ๊ฐ ์ฌ์ด๋์ ์ถ๊ฐํ ํฝ์ ์ ์๋ฅผ ๋ช ์ํ๋ค.
- stride (or stride_h and stride_w) [default 1]: ์ถ๋ ฅ์ ํํฐ๋ฅผ ์ ์ฉํ ๊ฐ๊ฒฉ๋ค ์์น์ ๋ช ์ํ๋ค
- group (g) [default 1]: ๋ง์ฝ g>1 ๋ฉด, ์ ๋ ฅ์ ๋ถ๋ถ ์งํฉ์ ๊ฐ๊ฐ ํํฐ์ ์ฐ๊ฒฐ์ ์ ํํ๋ค. ํนํ ์ ๋ ฅ๊ณผ ์ถ๋ ฅ ์ฑ๋์ด g ๊ทธ๋ฃน๋ค๋ก ๋๋์ด์ง๊ณ , i๋ฒ์งธ ์ถ๋ ฅ ๊ทธ๋ฃน ์ฑ๋์ ์ค์ง i๋ฒ์งธ ์ ๋ ฅ ๊ทธ๋ฃน ์ฑ๋๊ณผ ์ฐ๊ฒฐ๋ ๊ฒ์ด๋ค.
- Input
- n * c_i * h_i * w_i
- Output
- n * c_o * h_o * w_o, where h_o = (h_i + 2 * pad_h - kernel_h) / stride_h + 1 and w_o likewise.
- Sample (as seen in ./models/bvlc_reference_caffenet/train_val.prototxt)
layer {
name: "conv1"
type: "Convolution"
bottom: "data"
top: "conv1"
# learning rate and decay multipliers for the filters
param { lr_mult: 1 decay_mult: 1 }
# learning rate and decay multipliers for the 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" # 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
}
}
}
์ปจ๋ณผ๋ฃจ์ ๊ณ์ธต์ ์ถ๋ ฅ์ด๋ฏธ์ง์์ ๊ฐ๊ฐ ํ๋์ ํน์ง ๋งต์ ์์ฐํ๋ฉด์ ๋ฐฐ์ธ์ ์๋ ํํฐ๋ค์ ์ง๋จ์ผ๋ก ์ ๋ ฅ ์ด๋ฏธ์ง๋ฅผ ๊ฐ์๋๋๋ค.
Pooling
- Layer type: Pooling
- CPU implementation: ./src/caffe/layers/pooling_layer.cpp
- CUDA GPU implementation: ./src/caffe/layers/pooling_layer.cu
- Parameters (PoolingParameter pooling_param)
- ์๊ตฌ ์ฌํญ
- kernel_size (or kernel_h and kernel_w): ๊ฐ๊ฐ์ ํํฐ์ ๋์ด์ ๋๋น๋ฅผ ๋ช ์ํ๋ค.
- ์ถ๊ฐ ์ฌํญ
- pool [default MAX]: pooling ๋ฉ์๋. ํ์ฌ์ MAX, AVE๋ STOHASTIC ๋ช ์
- pad (or pad_h and pad_w) [default 0]: (์๋ฌต์ ์ผ๋ก) ์ ๋ ฅ์ ๊ฐ ์ฌ์ด๋์ ์ถ๊ฐํ ํฝ์ ์๋ฅผ ๋ช ์ํ๋ค.
- stride (or stride_h and stride_w) [default 1]: ์ ๋ ฅ์ ํํฐ๋ฅผ ์ ์ฉํ ๊ฐ๊ฒฉ์ ๋ช ์ํ๋ค.
- Input
- n * c * h_i * w_i
- Output
- n * c * h_o * w_o, where h_o and w_o are computed in the same way as convolution.
- Sample (as seen in ./models/bvlc_reference_caffenet/train_val.prototxt)
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
}
}
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)
- ์ถ๊ฐ ์ฌํญ
- local_size [default 5]: (LRN ์ฑ๋์์ ๋ํ์ฌ) ๋ชจ๋ ๋ํ ์ฌ๊ฐํ ์ง์ญ์ ์ฌ์ด๋ ๊ธธ์ด๋ (cross channel LRN์ ๋ํ์ฌ) ๋ชจ๋ ๋ํ ์ฑ๋์ ์
- alpha [default 1]: ํ๋ผ๋ฏธํฐ ํฌ๊ธฐ ์ค์ (์๋ ์ฐธ๊ณ )
- beta [default 5]: ์ง์ (์๋ ์ฐธ๊ณ )
- norm_region [default ACROSS_CHANNELS]: (WITHIN_CHANNEL) ๊ณต๊ฐ์ ์์น ๊ทผ์ฒ์ (ACROSS_CHANNELS) ์ธ์ ํ ์ฑ๋์ค ์ด๋ค ๊ฒ์ ๋ชจ๋ ๋ํ ์ง
๊ณต๊ฐ ๋ฐ์ ํ์คํ ๊ณ์ธต์ ๋ก์ปฌ ์ ๋ ฅ ์ง์ญ ์ ์ฒด๋ฅผ ํ์คํ ํจ์ ์ํด "์ธก๋ฉด ์ต์ "์ ํ ์ข ๋ฅ๋ฅผ ์ํํ๋ค. ACROSS_CHANNELS ๋ชจ๋์์, ๋ก์ปฌ ์ง์ญ์ ๊ทผ์ฒ ์ฑ๋๋ค์ ๋์ด ํ์ฅ๋์ง๋ง, ๊ณต๊ฐ์ ํ์ฅ์ ์๋ค. (์๋ฅผ๋ค๋ฉด local_size x 1 x 1 ๊ฐ์ด ๋ชจ์์ ๊ฐ์ง๋ฟ์ด๋ค.) WITHIN_CHANNEL์์๋, ๋ก์ปฌ ์ง์ญ์ด ๊ณต๊ฐ์ ์ผ๋ก ํ์ฅ๋์ง๋ง, ๋ถ๋ฆฌ๋ ์ฑ๋๋ค์์๋ ๊ทธ๋ ์ง ๋ชปํ๋ค. (์๋ฅผ๋ค์ด ๊ทธ๋ค์ 1 x local_size x local_size์ ๊ฐ์ ๋ชจ์์ ๊ฐ์ง ๋ฟ์ด๋ค.) ๊ฐ๊ฐ์ ์ ๋ ฅ๊ฐ์ (1+(ฮฑ/n)โix2i)ฮฒ์ ์ํด ๋๋์ด ์ง๋ฉฐ, ์ฌ๊ธฐ์ n์ ๊ฐ๊ฐ ๋ก์ปฌ ์ง์ญ์ ํฌ๊ธฐ์ด๋ฉฐ, ํฉ์ ๊ทธ ๊ฐ์ผ๋ก ์ค์ฌ์ด ๋ ์ง์ญ์ ์ํด ์ ์ ๋๋ค. (zero padding์ด ํ์ํ ๊ณณ์ ์ถ๊ฐ๋๋ค.)
im2col
Im2col์ด๋ ์๋ง ์์ธํ ์์์ผ ํ ํ์๊ฐ ํ์๊ฐ ์๋ ์ด๋ฏธ์ง์์ ์ด๋ก (image to column) ์ ํ์ ์กฐ๋ ฅ์์ด๋ค. ํ๋ ฌ ์์ ๋ชจ๋ ํจ์น๋ฅผ ํผ์นจ์ผ๋ก์จ ํ๋ ฌ ๊ณฑ์ ์ ํ๋ Caffe์ ์์กฐ ์ปจ๋ณผ๋ฃจ์ ์์ ์ฌ์ฉํ๋ค.
3. ์์ค ๊ณ์ธต (Loss Layers)
์์ค์ ์ต์ํํด์ผํ๋ ๋น์ฉ์ ๋ฑ๋กํจ๊ณผ ๋ชฉ๋ฃ๋ก ์ผ์์ผํ๋ ์ถ๋ ฅ์ ๋น๊ตํจ์์ํด ์์ค์ ํ์ต์ผ๋ก ๋๋ ค๊ฐ๋ค. ์์ค ๊ทธ์์ฒด๋ ์ ๋ฐฉํฅ๊ณผ์ ์ ์ํด ๊ณ์ฐ๋์ด ์ง๊ณ ์์ค์์์ ๊ทธ๋๋์ธํธ w.r.t.๋ ์ญ๋ฐฉํฅ๊ณผ์ ์ ์ํด ๊ณ์ฐ๋์ด์ง๋ค.
์ํํธ๋งฅ์ค (Softmax)
- Layer type: SoftmaxWithLoss
์ํํธ๋งฅ์ค ์์ค ๊ณ์ธต์ ๊ณ์ธต์ ์ ๋ ฅ์ ์ํํธ๋งฅ์ค์ ๋คํญ์์ ๋ก์ง์คํฑ ์์ค(multinomial logistic loss)์ ์ฐ์ฐํ๋ค. ๋คํญ์ ๋ก์ง์คํฑ ์์ค ๊ณ์ธต์ ์ํด ๋ํ๋๋ ์ํํธ๋งฅ์ค ๊ณ์ธต์ ๊ฐ๋ ์ ์ผ๋ก๋ ๋์ผํ๋, ๋ ๊ณ์์ ์ด๋ก ์์ ๋ ๊ทธ๋๋์ธํธ๋ฅผ ์ ๊ณตํ๋ค.
์ ๊ณฑํฉ / ์ ํด๋ฆฌ๋์ธ (Sum-of-Squares / Euclidean)
- Layer type: EuclideanLoss
์ ํด๋ฆฌ๋์ ์์ค ๊ณ์ธต์ ๋ ๊ฐ์ ์๋ก๋ค๋ฅธ ์ ๋ ฅ์ ์ ๊ณฑ ํฉ์ ์ฐ์ฐํ๋ค.
\frac 1 {2N} \sum_{i=1}^N \| x^1_i - x^2_i \|_2^2
ํ์ง์ ๋ง์ง (Hinge / Margin)
- Layer type: HingeLoss
- CPU implementation: ./src/caffe/layers/hinge_loss_layer.cpp
- CUDA GPU implementation: none yet
- Parameters (HingeLossParameter hinge_loss_param)
- Optional
- norm [default L1]: the norm used. Currently L1, L2
- Inputs
- n * c * h * w Predictions
- n * 1 * 1 * 1 Labels
- Output
- 1 * 1 * 1 * 1 Computed Loss
- Samples
# L1 Norm
layer {
name: "loss"
type: "HingeLoss"
bottom: "pred"
bottom: "label"
}
# L2 Norm
layer {
name: "loss"
type: "HingeLoss"
bottom: "pred"
bottom: "label"
top: "loss"
hinge_loss_param {
norm: L2
}
}
ํ์ง ์์ค ๊ณ์ธต์ ์ ๊ณฑ๋ ํ์ง ์์ค์ด๋ ๋ชจ๋ ํ์ง์ ๋ํญํ๋ ํ๋๋ฅผ ๊ณ์ฐํ๋ค.
์๊ทธ๋ชจ์ด๋ ํฌ๋ก์ค-์ํธ๋กํผ (Sigmoid Cross-Entropy)
- SigmoidCrossEntropyLoss
์ ๋ณด์ต๋ (Infogain)
- InfogainLoss
์ ํ๋์ K ์ต์์(Accuracy and Top-k)
์ ํ๋๋ ๋ชฉํ์ ๋ํ์ฌ ์ถ๋ ฅ์ ์ ํ๋๋ก์จ ์ ์๋ฅผ ๋ธ๋ค. - ์ด๊ฒ์ ์ค์ ๋ก ์์ค์ด ์๋๋ผ ์ญ๋ฐฉํฅ๊ณผ์ ์ด ์๋ ๊ฒ์ด๋ค.
4. ํ์ฑํ / ๋ด๋ฐ ๊ณ์ธต (Activation / Neuron Layers)
์ผ๋ฐ์ ์ผ๋ก ํ์ฑํ / ๋ด๋ฐ ๊ณ์ธต์ ํ๋์ bottom blob๋ฅผ ์ทจํด์ ๊ฐ์ ์ฌ์ด์ฆ์ ํ๋์ top blob๋ฅผ ์์ฑํ๋ ์์์ ๊ดํ ์๋๊ธฐ์ด๋ค. ์๋์ ๊ณ์ธต๋ค์์, ์ฐ๋ฆฌ๋ ์ ๋ ฅ๊ณผ ์ถ๋ ฅ์ ์ฌ์ด์ฆ๊ฐ ๋์ผํ๊ธฐ ๋๋ฌธ์ ๋ฌด์ํ ๊ฒ์ด๋ค.
- Input
- n * c * h * w
- Output
- n * c * h * w
ReLU / ์ ๋ฅ๋-์ ํ ๊ทธ๋ฆฌ๊ณ ์๋-ReLU (ReLU / Rectified-Linear and Leaky-ReLU)
- Layer type: ReLU
- CPU implementation: ./src/caffe/layers/relu_layer.cpp
- CUDA GPU implementation: ./src/caffe/layers/relu_layer.cu
- Parameters (ReLUParameter relu_param)
- ์ถ๊ฐ ์ต์
- negative_slope [default 0]: ๋ค๊ฑฐํฐ๋ธ ๋ถ๋ถ์ 0์ผ๋ก ์ค์ ํ๊ธฐ๋ณด๋ค๋ ๊ธฐ์ธ๊ธฐ ๊ฐ์ผ๋ก ๊ณฑ์ ํ๋ ๊ฒ์ผ๋ก ๋์ถ ์ํฌ์ง ์๋์ง๋ฅผ ๋ช ์ํ๋ค.
- Sample (as seen in ./models/bvlc_reference_caffenet/train_val.prototxt)
layer {
name: "relu1"
type: "ReLU"
bottom: "conv1"
top: "conv1"
}
์ ๋ ฅ๊ฐ x๋ฅผ ๊ณ ๋ คํ์ฌ, ReLU ๊ณ์ธต์ ๋ง์ฝ x > 0์ด๋ฉด ์ถ๋ ฅ์ผ๋ก x๋ฅผ ๊ทธ๋ฆฌ๊ณ x <= 0 ์ด๋ฉด negative_slope * x๋ฅผ ์ถ๋ ฅ์ผ๋ก ๊ณ์ฐํ๋ค. ๋ค๊ฑฐํฐ๋ธ ๊ธฐ์ธ๊ธฐ ํ๋ผ๋ฏธํฐ๊ฐ ์ค์ ๋์ด์์ง ์์ ๋, max(x, 0)์ ์ทจํ๋ ๊ฒ์ ํ์ค ReLU ํจ์์ ๋๋ฑํ๋ค. ๋ํ bottom ๊ณผ top blob๊ฐ ๋ณด์กด ๋งค๋ชจ๋ฆฌ ์ฅ์น ์๋น์ ๊ฐ๊ฒ ๋ ์ ์๋ค๋ ๊ฒ์ ์๋ฏธํ๋ฉฐ ์ ์๋ฆฌ ์ฐ์ฐ (In-place Computation)์ ์ง์ํ๋ค.
์๊ทธ๋ชจ์ด๋ (Sigmoid)
- Layer type: Sigmoid
- CPU implementation: ./src/caffe/layers/sigmoid_layer.cpp
- CUDA GPU implementation: ./src/caffe/layers/sigmoid_layer.cu
- Sample (as seen in ./examples/mnist/mnist_autoencoder.prototxt)
layer {
name: "encode1neuron"
bottom: "encode1"
top: "encode1neuron"
type: "Sigmoid"
}
์๊ทธ๋ชจ์ด๋ ๊ณ์ธต์ ๊ฐ ์ ๋ ฅ ์์ x์ ๋ํ์ฌ sigmoid(x)๋ก ์ถ๋ ฅ์ ๊ณ์ฐํ๋ค.
ํ์ดํผ๋ธ๋ฆญ ํ์ ํธ (TanH / Hyperbolic Tangent)
- Layer type: TanH
- CPU implementation: ./src/caffe/layers/tanh_layer.cpp
- CUDA GPU implementation: ./src/caffe/layers/tanh_layer.cu
- Sample
layer {
name: "layer"
bottom: "in"
top: "out"
type: "TanH"
}
ํ์ดํผ๋ธ๋ฆญ ํ์ ํธ (TanH) ๊ณ์ธต์ ๊ฐ ์ ๋ ฅ ์์ x์ ๋ํ์ฌ tanh(x)๋ก์ ์ถ๋ ฅ์ ์ฐ์ฐํ๋ค.
์ ๋๊ฐ (Absolute Value)
- Layer type: AbsVal
- CPU implementation: ./src/caffe/layers/absval_layer.cpp
- CUDA GPU implementation: ./src/caffe/layers/absval_layer.cu
- Sample
layer {
name: "layer"
bottom: "in"
top: "out"
type: "AbsVal"
}
AbsVal ๊ณ์ธต์ ๊ฐ ์ ๋ ฅ ์์ x์ ๋ํ์ฌ abs(x)๋ก์ ์ถ๋ ฅ์ ์ฐ์ฐํ๋ค.
ํ์ (Power)
- Layer type: Power
- CPU implementation: ./src/caffe/layers/power_layer.cpp
- CUDA GPU implementation: ./src/caffe/layers/power_layer.cu
- Parameters (PowerParameter power_param)
- ์ถ๊ฐ ์ต์
- power [default 1]
- scale [default 1]
- shift [default 0]
- Sample
layer {
name: "layer"
bottom: "in"
top: "out"
type: "Power"
power_param {
power: 1
scale: 1
shift: 0
}
}
ํ์ ๊ณ์ธต์ ๊ฐ ์ ๋ ฅ ์์ x์ ๋ํ์ฌ (shift + scale * x) ^ power ๋ก์ ์ถ๋ ฅ์ ์ฐ์ฐํ๋ค.
์ด์ง ์ผ๋ฐ ๋ก๊ทธ ์ ์ฌ์ฑ (BNLL)
- Layer type: BNLL
- CPU implementation: ./src/caffe/layers/bnll_layer.cpp
- CUDA GPU implementation: ./src/caffe/layers/bnll_layer.cu
- Sample
layer {
name: "layer"
bottom: "in"
top: "out"
type: BNLL
}
BNLL (binomial normal log likelihood) ๊ณ์ธต์ ๊ฐ ์ ๋ ฅ ์์ x์ ๋ํ์ฌ log(1 + exp(x))๋ก์ ์ถ๋ ฅ์ ์ฐ์ฐํ๋ค.
In-Memory
- Layer type: MemoryData
- Parameters
- ์๊ตฌ ์ฌํญ
- batch_size, channels, height, width: ๋ฉ๋ชจ๋ฆฌ๋ก ๋ถํฐ ์ฝ์ด์ค๋ ์ ๋ ฅ ๋์ ์ฌ์ด์ฆ๋ฅผ ๋ช ์ํ๋ค.
๋ฉ๋ชจ๋ฆฌ ๋ฐ์ดํฐ ๊ณ์ธต์ ๋ณต์ฌ ์์ด ๋ฉ๋ชจ๋ฆฌ๋ก๋ถํฐ ์ง์ ๋ฐ์ดํฐ๋ฅผ ์ฝ์ด์จ๋ค. ์ด๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด (C++ ๊ธฐ๋ฐ) "MemoryDataLayer::Reset"์ด๋ (Python ๊ธฐ๋ฐ)"Net.set_input_arrays"๋ฅผ ๋ถ๋ฌ์์ผ๋ง ํ๋ค. (4D ํ ์ฐ์ ๋ฐฐ์ด๋ก์จ) ์ฐ์์ ๋ฐ์ดํฐ์ ์์ค๋ฅผ ๋ช ์ํ๊ธฐ์ํจ์ด๋ฉฐ ์ด๋ ํ๋ฒ์ ์ผํ ์ฒ๋ฆฌ๋ ํฌ๊ธฐ์ ๋ฉ์ด๋ฆฌ๋ฅผ ์ฝ๋๋ค.
5. ์ผ๋ฐ ๊ณ์ธต (Common Layers)
๋ด๋ถ ์์ฐ (Inner Product)
- ayer type: InnerProduct
- CPU implementation: ./src/caffe/layers/inner_product_layer.cpp
- CUDA GPU implementation: ./src/caffe/layers/inner_product_layer.cu
- Parameters (InnerProductParameter inner_product_param)
- ์๊ตฌ ์ฌํญ
- num_output (c_o): ํํฐ์ ์
- ๊ฐ๋ ฅํ ๊ถ๊ณ ์ฌํญ
- weight_filler [default type: 'constant' value: 0]
- ์ถ๊ฐ ์ต์
- bias_filler [default type: 'constant' value: 0]
- bias_term [default true]: ํํฐ ์ถ๋ ฅ์ ์ถ๊ฐ์ ํธํฅ์ ์ธํธ๋ฅผ ์ ์ฉํ๊ณ ํ์ตํ ์ง ๋ช ์ํ๋ค.
- Input
- n * c_i * h_i * w_i
- Output
- n * c_o * 1 * 1
- Sample
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"
}
"InnerProduct" ๊ณ์ธต์ (์์ ์ฐ๊ฒฐ ๊ณ์ธต์ผ๋ก์จ ๋ณดํต ์ธ๊ธ๋จ) ์ํ ๋ฒกํฐ๋ก์จ ์ ๋ ฅ์ ๋ค๋ฃจ๊ณ (1๋ก blob์ ๋์ด์ ๋๋น๋ฅผ ์ค์ ํ๋ฉด์)๋จ์ผ ๋ฒกํฐ์ ํํ์์ ์ถ๋ ฅ์ ์์ฐํ๋ค.
๋ถ์ด (Splitting)
"Split" ๊ณ์ธต์ ๋ค์ค ์ถ๋ ฅ blob์ ์ ๋ ฅ blob์ ๋๋๋ ๋๊ตฌ ๊ณ์ธต์ด๋ค. ์ด๋ blob๊ฐ ๋ค์ค ์ถ๋ ฅ ๊ณ์ธต์ผ๋ก ์ ์ฉ๋ฌ์ ๋ ์ฌ์ฉ๋๋ค.
ํธ์จ, ํ์์จ (Flattening)
"Flatten" ๊ณ์ธต์ n * (chw)๋ชจ์์ ๊ฐ๋จํ ๋ฐฑํฐ ์ถ๋ ฅ์ n * c * h * w ๋ชจ์์ ์ ๋ ฅ์ ๋ฉ์ํ๊ฒ ๋ง๋๋ ๋๊ตฌ ๊ณ์ธต์ด๋ค.
์ฌ๊ตฌ์ฑ (Reshape)
- Layer type: Reshape
- Implementation: ./src/caffe/layers/reshape_layer.cpp
- Parameters (ReshapeParameter reshape_param)
- ์ถ๊ฐ ์ต์ : (์๋ ์์ธํ ์ค๋ช ์ ์ฐธ๊ณ )
- shape
- ์ ๋ ฅ
- ์์์ ์ธ ์ฐจ์๋ค๋ก ์ด๋ฃจ์ด์ง ๋จ์ผ blob
- ์ถ๋ ฅ
- "reshape_param"๋ก์จ ๋ช ์๋, ์์ ๋ ์ฐจ์๋ค๋ก ์ด๋ฃจ์ด์ง ๊ฐ์ blob reshape_param
- Sample
layer {
name: "reshape"
type: "Reshape"
bottom: "input"
top: "output"
reshape_param {
shape {
dim: 0 # bottom ๊ณ์ธต์ ๊ฐ๊ฐ ์ฐจ์์ ๋ณต์ฌํ๋ค.
dim: 2
dim: 3
dim: -1 # ๋ค๋ฅธ ์ฐจ์์ผ๋ก ๋ถํฐ ์ถ๋ก ํ๋ค.
}
}
}
"Reshape" ๊ณ์ธต์ ๋ฐ์ดํฐ์ ๋ณํ ์์ด ์ ์ญ์ ์ฐจ์์ ๋ณํ์ํค๋๋ฐ ์ฌ์ฉ๋๋ค. ํ์์จ ๊ณ์ธต (Flatten layer)์ฒ๋ผ, ์ฐจ์๋ง ๋ฐ๋๋ค. ๊ณผ์ ์ค์ ์ด๋ค ๋ฐ์ดํฐ๋ ๋ณต์ฌ๋์ง ์๋๋ค. ์ถ๋ ฅ ์ฐจ์์ "ReshapeParam"proto์ ์ํด ๋ช ์๋๋ค. ์ถ๋ ฅ blob ์ฐจ์์ ํด๋นํ๊ฒ ์ค์ ํ๋ฉด์ ์์๋ ๋ฐ๋ก ์ฌ์ฉ๋๋ค. ์ถ๊ฐ๋ก, ๋ ๊ฐ์ ํน๋ณํ ๊ฐ์ ์ด๋ค ๋ชฉํ ์ฐจ์ ๊ฐ์ ๋ํ์ฌ ๋ฐ์๋ค์ธ๋ค :
- 0 ์ "bottom ๊ณ์ธต์ ๊ฐ๊ฐ ์ฐจ์์ ๋ณต์ฌํ๋ค."๋ฅผ ์๋ฏธํ๋ค. ์ฆ, ์ฒซ ์ฐจ์์์ bottom์ด 2๋ฅผ ๊ฐ์ง๊ณ ์์ผ๋ฉด, ์ฒซ๋ฒ์งธ ๋ชฉํ ์ฐจ์์ผ๋ก์จ "dim:0"์ ์ฃผ๋ฉด์, top ๋ํ ์ด์ ์ฒซ๋ฒ์งธ ๊ณ์ธต์ผ๋ก์จ 2๋ฅผ ๊ฐ์ง๋ค.
- -1 โ๋ค๋ฅธ ์ฐจ์์ผ๋ก ๋ถํฐ ์ถ๋ก ํ๋ค.โ๋ฅผ ๋ปํ๋ค. ์ด ํ๋์ MATLAB์ ์ฌ๊ตฌ์ฑ์ ๋ํ์ฌ numpy's๋ []์์ -1์ ๋ํ ๊ฒ๊ณผ ๋น์ทํ๋ค. : ์ด ์ฐจ์์ bottom ๊ณ์ธต์์์ ๊ฐ์ด ์ ์ฒด ์์ ์นด์ดํธ๋ฅผ ๊ณ์ฐํ๋ค. ๋๋ถ๋ถ์ ๊ฒ์์ -1์ ์ฌ๊ตฌ์ฑ ์๋์ผ๋ก ์ฌ์ฉ๋ ์ ์๋ค.
๋ค๋ฅธ ์๋ก์จ "reshape_param { shape { dim: 0 dim: -1 } }"๋ฅผ ๋ช ์ํ๋ ๊ฒ์ ํ์์จ ๊ณ์ธต์์ ์ฒ๋ผ ์ ํํ ๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก ํ๋ํ๋ ๊ณ์ธต์ ์์ฑํ๋ค.
์ฐ์ (Concatenation)
- Layer type: Concat
- CPU implementation: ./src/caffe/layers/concat_layer.cpp
- CUDA GPU implementation: ./src/caffe/layers/concat_layer.cu
- Parameters (ConcatParameter concat_param)
- ์ถ๊ฐ์ฌํญ
- axis [default 1]: 0์ num์ ๋ฐ๋ฅธ ์ฐ์, 1์ channel์ ๋ฐ๋ฅธ ์ฐ์.
- Input
- n_i * c_i * h * w for each input blob i from 1 to K.
- Output
- if axis = 0: (n_1 + n_2 + ... + n_K) * c_1 * h * w, and all input c_i should be the same.
- if axis = 1: n_1 * (c_1 + c_2 + ... + c_K) * h * w, and all input n_i should be the same.
- Sample
layer {
name: "concat"
bottom: "in1"
bottom: "in2"
top: "out"
type: "Concat"
concat_param {
axis: 1
}
}
"Concat" ๊ณ์ธต์ ๋จ์ผ ์ถ๋ ฅ blob์ ๋ค์ค ์ ๋ ฅ blob๋ฅผ ์ฐ์์ํค๋ ๋๊ตฌ ๊ณ์ธต์ด๋ค.
์ฌ๋ผ์ด์ฑ (Slicing)
"Slice"๊ณ์ธต์ ์ฃผ์ด์ง ์ฌ๋ผ์ด์ค ์งํ์ ๋ฐ๋ผ์ (ํ์ฌ num ์ด๋ channel ๋ง) ์ฃผ์ด์ง ์ฐจ์์ ๋ฐ๋ผ ๋ค์ค ์ถ๋ ฅ ๊ณ์ธต์ ์ ๋ ฅ ๊ณ์ธต์ ์ฐ์ด์ฃผ๋ ๋๊ตฌ ๊ณ์ธต์ด๋ค.
- Sample
layer {
name: "slicer_label"
type: "Slice"
bottom: "label"
## Example of label with a shape N x 3 x 1 x 1
top: "label1"
top: "label2"
top: "label3"
slice_param {
axis: 1
slice_point: 1
slice_point: 2
}
}
"axis"๋ ๋ชฉํ์ถ์ ๋ํ๋ธ๋ค. ; "slice_point"๋ ์ ํ๋ ์ฐจ์์์ ์งํ๋ฅผ ๋ํ๋ธ๋ค. (์งํ๋ค์ ์๋ top blob์ ๋ง์ด๋์ค 1์ ์์ ๋๋ฑํด์ผ๋งํ๋ค.)
Elementwise Operations
Eltwise
Argmax
ArgMax
Softmax
Softmax
Mean-Variance Normalization
MVN