CNN (Convolutional Neural Network)
Basic Operations in CNN
Fully-Connected (FC) Layer
- Flatten :
32x32x3
image -> stretch to 3072x1
32x32x3
image
- preserve spatial structure
Convolutional Layer
์ญํ : Rawdata๋ฅผ ์์ถ์์ผ์ ๋ง์ ์ ๋ณด๋ฅผ ๋ด๊ฒ ํ๊ธฐ ์ํ ๋ชฉ์
Padding & Stride
- Padding
- input ์ด๋ฏธ์ง์ ๋ฐ๊นฅ์ ์ฌ๋ฐฑ์ ๋๋ ๊ฒ.
- ๋ง์ฝ
5x5
์ input ์ด๋ฏธ์ง์ padding์ 2๋ก ํ๋ค๋ฉด, ์ค์ง์ ์ธ ์ด๋ฏธ์ง์ ํฌ๊ธฐ๋ (5+2)x(5+2) = 7x7
๊ฐ ๋๋ค.
- Stride :
- Convolution ์ฐ์ฐ์ ๋ช ์นธ ๋จ์๋ก ์ํํ ์ง ์ ํ๋ ๊ฐ๊ฒฉ.
Output Size of Convolutional Layer
Output Size of Zero Padding
Examples (1)
- Input volume :
32x32x3
- Ten(10) 5x5 filters with stride 1, pad 2
- Output volume size?
Result :
Examples (2)
- Input volume :
32x32x3
- Ten(10) 5x5 filters with stride 1, pad 2
- Number of parameters in this layer?
Result :
1x1 Convolution์ ์ฌ์ฉํ๋ ์ด์
- ๊ฐ์ฅ ๊ทผ๋ณธ์ ์ธ ์ด์ ๋ ์ฑ๋ ์๋ฅผ ์กฐ์ ํ๊ธฐ ์ํจ์ด๋ค.
- output ํฌ๊ธฐ์๋ ๋ณํ๊ฐ ์๊ณ ์ฑ๋์ ์๋ฅผ ์กฐ์ ํ ์ ์๋ ์ญํ ์ ํ๊ฒ ๋๋ค.
- 1x1 Conv๋ฅผ ์ฌ์ฉํจ์ผ๋ก์จ, ์ฐจ์์ ํ๋ํ๊ฑฐ๋ ์ถ์ํ ์ ์๋ค.
Pooling Layer
- down-sampling๊ณผ ๊ฐ์ ์ญํ
- Parameter๋ฅผ ๊ฐ์ง์ง ์์
Max Pooling
overlapping ๋์ง ์๊ธฐ ์ํด, ๋ณดํต filter ํฌ๊ธฐ์ stride๋ฅผ ๊ฐ๋๋ก ํด์ค๋ค.
Global Average Pooling (GAP)
- GAP์ ๋ชฉ์ ์ feature๋ฅผ 1์ฐจ์ ๋ฒกํฐ๋ก ๋ง๋ค๊ธฐ ์ํจ์ด๋ค.
- ์ด๋ค ํฌ๊ธฐ์ feature vector(
HxWxC
)๋ 1x1xC
๋ก ๋ง๋ค์ด์ค๋ค.
- ๊ธฐ์กด ๋ฐฉ๋ฒ์ธ FC Layer๋ฅผ ์ฌ์ฉํ๋ฉด ๋ง์ ํ๋ผ๋ฏธํฐ ์๊ฐ ํ์ํ์ง๋ง, GAP๋ ํ๋ผ๋ฏธํฐ๋ฅผ ์ฐจ์งํ์ง ์์ ๊ณ์ฐ ์๋๊ฐ ๋น ๋ฅด๊ณ , ์ค๋ฒํผํ
์ ๋ฐฉ์งํ๋ ํจ๊ณผ๊ฐ ์๋ค.
- ๋ฐ๋ผ์ GAP ์ฐ์ฐ ๊ฒฐ๊ณผ 1์ฐจ์ ๋ฒกํฐ๊ฐ ๋๊ธฐ ๋๋ฌธ์ ์ต์ข
์ถ๋ ฅ์ FC Layer ๋์ ์ฌ์ฉํ ์ ์๋ค.
Small filters, Deeper networks & Fewer parameters
- ํน์ง
3x3
ํฌ๊ธฐ์ ์์ Conv ํํฐ ์ฌ์ฉ
- bottleneck ๊ตฌ์กฐ
- ๋ชจ๋ธ์ ๋ฉ๋ชจ๋ฆฌ ๋๋ถ๋ถ์ ์ด๋ฐ๋ถ Conv ํํฐ ์ชฝ์ ๋ชฐ๋ ค ์์
- ๋ชจ๋ธ์ ํ๋ผ๋ฏธํฐ ๋๋ถ๋ถ์ ํ๋ฐ๋ถ FC Layer ์ชฝ์ ๋ชฐ๋ ค ์์
What is the effective receptive field of three 3x3
conv (stride 1) layers?
3x3
conv๋ฅผ
- ํ ๋ฒ ์์ผ๋ฉด
3x3
์ receptive field๋ฅผ ๊ฐ์ง๋ค.
- ๋ ๋ฒ ์์ผ๋ฉด
5x5
์ receptive field๋ฅผ ๊ฐ์ง๋ค.
- ์ธ ๋ฒ ์์ผ๋ฉด
7x7
์ receptive field๋ฅผ ๊ฐ์ง๋ค.
- ์ฆ ๊น๊ฒ ์์ผ๋ฉด, receptive field๊ฐ ์ ์ง๋๋ค.
- Input Size๊ฐ
7x7
์ด๋ฉฐ, 3x3
์ Output Size๋ฅผ ๋์ถํด๋ด์ผ ํ๋ค๊ณ ๊ฐ์ ํ์. ์ด๋ Filter Size๊ฐ 3x3
์ด๋ผ๋ฉด ์ด ์ธ ์ฐจ๋ก์ Convolution์ ์งํํด์ผ ํ๋ค.
- ๋ฐ๋ฉด
5x5
์ Filter Size๋ก๋ ๋จ ํ ๋ฒ์ Convolution์ผ๋ก ๋์ผํ ์ฌ์ด์ฆ์ Feature Map์ ์ฐ์ถํ๋ค. 3x3
Filter๋ก ์ธ ์ฐจ๋ก Convolution ํ๋ ๊ฒ์ 7x7 Filter๋ก ํ ๋ฒ Convolution ํ๋ ๊ฒ๊ณผ ๋์๋๋ค.
- ์ฆ,
3x3
Filter 3๊ฐ๋ 7x7
Filter ํ๋์ ๋์ผํ Receptive Field (= Filter๊ฐ ํ ๋ฒ์ ๋ณผ ์ ์๋ ์
๋ ฅ ์ด๋ฏธ์ง์ Spatial Area) ๋ฅผ ๊ฐ์ง๋ฉด์๋ ๋ ๊น์ ๋ ์ด์ด๋ฅผ ์์ ์ ์๊ฒ ํ๋ ๊ฒ์ด๋ค.
- ์ด์ฒ๋ผ Layer ์๊ฐ ๋์ด๋๋ฉด ์ด๋ฏธ์ง ํน์ฑ์ ๋น์ ํ์ฑ์ ๋ ์ถ๊ฐํ ์ ์๊ธฐ ๋๋ฌธ์(Deeper, more non-linearities), Filter๋ฅผ ํตํด ์ถ์ถํ Feature๊ฐ ์ ์ ์ ์ฉํด์ง๋ ์ด์ ์ ์ป๊ฒ ๋๋ค.
VGGNet์ด 3x3
ํฌ๊ธฐ์ ์์ ํํฐ๋ฅผ ์ฌ์ฉํ๋ ์ด์ (Why use smaller filters?)
7x7
ํํฐ ํ๋๋ฅผ ์ฌ์ฉํ๋ ๊ฒ๋ณด๋ค 3x3
ํํฐ๋ฅผ ์ธ ๋ฒ ์ฌ์ฉํ๋ฉด activation function์ ์ฌ๋ฌ๋ฒ ๊ฑฐ์ณ์ง๋ฉด์ ๋ non-linear ํด์ง๋ค.
- ํ๋ผ๋ฏธํฐ ์๋ฅผ ์ค์ด๊ณ Layer๋ฅผ ๋ค์ธต ์์์ ๋ชจ๋ธ์ ์ ์ฒด Depth๋ฅผ ๊น๊ฒ ๋ง๋ค๊ธฐ ์ํด์์ด๋ค.
GoogLeNet (Inception module)
Deeper networks, with computational efficiency
- ํน์ง
- ํจ์จ์ ์ธ Inception module ์ฌ์ฉ
- AlexNet, VGG ๋ณด๋ค ํจ์ฌ ์ ์ ํ๋ผ๋ฏธํฐ ์
- No FC layers
- bottleneck ๊ตฌ์กฐ๋ก ์ฑ๋ ํฌ๊ธฐ๋ฅผ ์ค์ด๋ฉด์ ์ฐ์ฐ๋์ ์ค์ (ํํฐ๊ฐ ์์์ง)
- Global Average Pooling(GAP)๋ก reshapeํ๋ฉด์ feature size๋ฅผ
1x1xC
๋ก ํ ์ค์
- Auxiliary Classifier ์ฌ์ฉ
- ์ค๊ฐ๋ง๋ค ๋ถ๊ธฐ๋ฅผ ๋ง๋ค์ด์ classifyํ๊ณ , loss๋ฅผ ๊ณ์ฐํจ
Inception Module
- Key Idea
- ์๋ก ๋ค๋ฅธ receptive field๋ฅผ ๊ฐ์ง ์ฌ๋ฌ ์ฌ์ด์ฆ์ Convolutional filter๋ค๊ณผ Pooling layer๋ฅผ ๋ณ๋ ฌ์ ์ผ๋ก ๋์์ ์ ์ฉ์ํค๋ ๊ฒ
- Split & Merge
- ๋จ์
- ์ฑ๋์ ํฌ๊ธฐ๊ฐ ์ปค์ง์ ๋ฐ๋ผ, ํ๋ผ๋ฏธํฐ์ ์ฌ์ด์ฆ๊ฐ ์ปค์ ธ Computational Complexity๊ฐ ๋๋ค.
- Solution
- ์ฑ๋์ ํฌ๊ธฐ๋ฅผ ์ค์ด๊ธฐ ์ํด,
1x1
conv filter๋ฅผ โbottleneckโ layer๋ก์จ ์ฌ์ฉ
Very deep networks using residual connections
- ํน์ง
- H(x)๋ฅผ ๊ตฌํ๊ธฐ ์ํด Residual์ธ F(x) ๋ง์ ํ์ต์ํจ๋ค.
- VGG์ ์ฅ์ ์ธ
3x3
conv filter ํ์ฉ
- GoogLeNet์ ์ฅ์ ์ธ GAP ํ์ฉ
- ๋ง์ง๋ง FC Layer๋ฅผ ์ ์ธํ๊ณ , FC๊ฐ ์ฐ์ด์ง ์์
- bottleneck ๊ตฌ์กฐ๋ฅผ ์ฌ์ฉ
References
- ์ธ๊ณต์ง๋ฅ ์์ฉ (ICE4104), ์ธํ๋ํ๊ต ์ ๋ณดํต์ ๊ณตํ๊ณผ ํ์ฑ์ ๊ต์๋
-
[[DL] 1x1 convolution์ ๋ฌด์์ด๊ณ ์ ์ฌ์ฉํ ๊น? |
Sociological Imagination](https://euneestella.github.io/research/2021-10-14-why-we-use-1x1-convolution-at-deep-learning/) |
- ํฉ์ฑ๊ณฑ ์ ๊ฒฝ๋ง ๊ธฐ์ด 5(VGGNet, Very Deep Convolutional Network)
- Global Average Pooling ์ด๋ - gaussian37
- GAP (Global Average Pooling) : ์ ์ญ ํ๊ท ํ๋ง
- [๋ฅ๋ฌ๋] GAP(Global Average Pooling)