1. Convolution
지금까지 본 신경망은 인접하는 계층의 모든 뉴런이 결합되어 있는 fully-connected 형태이며 완전히 연결된 계층을 Affine 계층이라는 이름으로 구현하였다.
위 그림과 같이 CNN에서는 새로운 ’합성곱 계층’과 ’풀링 계층’이 추가된다. 기존 완전 연결 계층(Affine)의 문제점은 ’데이터의 형상이 무시된다’는 것이다.
이미지는 통상 가로, 세로, 채널(색상)의 3차원 데이터이다. 그러나 완전연결 계층에 입력할 때는 3차원 데이터를 1차원 데이터로 평탄화 시켜야 한다. 이미지는 3차원 형상이며 이 형상에는 공간적 정보가 담겨져 있다. 그러나 완전 연결을 하게 되면 모든 입력 데이터를 동등한 뉴런(같은 차원의 뉴런)으로 취급하여 공간적 정보가 많이 사라지게 된다. 이 때 사용하는 것이 Convolution(합성곱)이다.
합성곱에서는 뉴런을 필터(filter) 혹은 커널(kernal) 이라고 부른다. 약간의 차이가 있다면 필터는 뉴런의 개수, 커널은 입력에 곱하는 가중치를 뜻한다.
Filter always extend the full depth of the input volume 이 적혀있는데 이는 filter는 항상 입력 채널의 수만큼 확장이 되어야 한다는 뜻이다. 3 channel을 가진 image의 filter도 똑같은 3 depth를 가져야 한다. 이어 가중치 행렬$W$를 전치하여 $WT$ 를 input data $x$와 곱해주고 편향 $b$를 더한다 $(WTx + b)$.
입력 데이터가 커널(필터)를 거쳐 출력된 형태를 feature map 이라고 한다. 커널(필터)의 크기는 사용자의 필요에 따라 달라질 수 있으며 보통 커널은 입력이미지의 크기보다 작다.
패딩(Padding)은 합성곱 연산을 수행하기 전에 입력 데이터 주변을 특정 값(주로 0)으로 채우는 것을 뜻한다. 패딩은 주로 출력 크기를 조정할 목적으로 사용한다. 예를 들어 (4,4) 입력 데이터에 (3,3) 필터를 적용하면 출력은 (2,2) 가 되어 입력보다 2만큼 줄어드는데 이와 같이 계속 진행하다 보면 출력 크기가 줄어들어 합성곱 연산을 적용할 수 없을 때가 오는데 이를 방지하기 위해 사용한다.
스트라이드(Stride)는 필터를 적용하는 위치의 간격을 뜻한다.
위 그림은 합성곱 연산의 처리 흐름(배치처리) 된 것을 보여준다.
합성곱 layer는 합성곱 연산을 통해서 feature map을 출력하는 layer이며, 최종 출력층에서 에러를 줄일 수 있는 kernel의 가중치를 학습시키는 것이다.
합성곱 신경망을 통해서 feature map을 출력하면 3차원 이미지를 flatten 하면서 잃는 공간적인 정보를 최소화하고, 완전 연결(fully-connected-layer)를 사용했을 때 보다 같은 출력을 얻는데 적은 가중치가 필요하다는 장점이 있다.
2. Pooling
Pooling은 세로 가로 방향의 공간을 줄이는 연산이다. 특정한 크기의 커널(필터)이 입력 이미지를 훑으며 최대, 평균 등의 값을 출력하는 것이다. 합성곱 신경망에서 합성곱 층 다음에는 pooling 층을 추가하는 것이 일반적이다. 이미지 인식 분야에서는 주로 최대 풀링을 사용한다.
Pooling은 Convolution과 다른 점은 일반적으로 겹치는 부분 없이 sliding 한다는 점이다. 이 외에도 Pooling 계층의 특징은 다음과 같다.
- 학습해야 할 매개변수가 없다.
- 채널 수가 변하지 않는다.
- 입력의 변화에 영향을 적게 받는다.
3. Summary
3.1. 3x3 kernel을 가진 filter가 sliding 하며 convolve하는 과정
3.2. 각 channel 별로 처리되어 하나의 channel을 만든다. filter 전체는 하나의 출력 channel을 만든다.
3.3. 각 filter 출력마다 bias가 하나씩 더해져 최종 출력을 만든다.
'Study > cs231n' 카테고리의 다른 글
[cs231n] 7. Training Neural Networks 2 (0) | 2024.04.17 |
---|---|
[cs231n] 6. Training Neural Networks (0) | 2024.04.17 |
[cs231n] 4. Introduction graphs (0) | 2024.04.17 |
[cs231n] Loss Functions and Optimization 요약 (0) | 2024.04.04 |