개요 & Feature Pyramid Network, EfficientNet 설명
논문 링크: https://arxiv.org/abs/1911.09070
제목: EfficientDet: Scalable and Efficient Object Detection
Object detection 관련 논문. 이 논문에서 제시하는 핵심 아이디어는 크게 2개가 있다:
1. Efficient multi-scale feature fusion: FPN을 발전시킨 BiFPN을 제안 (FPN에 대한 내용은 접은글 참고)
ResNet같은 convolutional network는 중간중간 pooling을 하면서 feature dimension이 작아지는데, 이 때문에 spatial resolution에 대한 정보를 조금씩 잃게 된다. 하지만 이런 resolution이 특히 object detection같은 문제에서 중요하게 작용할 수 있다 (작은 물체를 정확하게 localize하기 위해서 high resolution 정보가 필요하다). 이러한 문제를 해결하는 방법 중 바로 FPN (feature pyramid network)이다:

여기서 핵심 아이디어는 Image를 convolutional network를 통과시켜서 나오는 feature들을 섞어주는 것이다: resolution이 낮은 feature을 upscaling을 하고 (그림에서 2x up, FPN에서는 단순 nearest neighbor upsampling 사용), resolution이 더 높은 feature map (1x1 convolution을 통과 후) 과 concatenate 해준다. 이렇게 feature fusion을 해주면 resolution이 높지만 semantic meaning은 적은 feature들과 & resolution이 낮지만 semantic meaning이 많은 feature들을 동시에 사용해서 object detection이 가능해진다 (그림에서 predict). EfficientDet에서는 이런 것을 더 효율적으로 하는 BiFPN을 제안한다.
2. Model scaling: EfficientNet 아이디어를 적용해서 EfficientDet의 network architecture을 설계한다 (EfficientNet 관련 내용은 접은글 참고)
EfficientNet 논문 (https://arxiv.org/abs/1905.11946)에서 자세하게 다뤘지만 모델 사이즈를 단순 무식하게 키운다고 성능이 좋아지는 것은 아니다. 모델 사이즈를 키우는 방법들은 많겠지만 간단하게 다음 3가지를 생각해 볼 수 있다:

그림이 살짝 헷갈릴 수도 있는데 (b) width scaling은 channel 수를 조절하는 것을 뜻한다 (c) depth scaling은 layer 수를 조절하는 것을 뜻한다 (d) resolution scaling은 image 사이즈를 조절하는 것을 뜻한다. EfficientNet의 핵심 아이디어는 이 세 가지 중 단순히 한 종류의 scaling만 하면 효율적인 모델 scaling을 할 수 없고 (실험적인 근거는 밑에 그림 참고), (e)처럼 동시에 scaling을 해줘야 한다는 것이다: "Intuitively, the compound scaling method makes sense because if the input image is bigger, then the network needs more layers to increase the receptive field and more channels to capture more fine-grained patterns on the bigger image" (이미지 사이즈가 커지면 더 큰 receptive field가 필요하고 (depth가 증가햐야한다는 뜻), fine-grained feature들도 소화해야하는데 그러려면 channel 수도 같이 증가해야한다는 뜻.)

동시에 scaling은 다음과 같이 한다:

여기서 \( \alpha \cdot \beta^2 \cdot \gamma^2 \approx 2\)는 고정된 \( \alpha,\beta,\gamma\)에 대해서 FLOPS가 \( 2^{\phi}\)로 scaling하기 위해서라고 한다. EfficientNet에서는 우선 \( \phi=1\)로 고정하고 \( \alpha,\beta,\gamma\)를 grid search한다 (논문에서 성능과 연산량을 기반으로 metric을 정의한다). 그리고 \( \alpha, \beta, \gamma\)를 고정하고 \( \phi\)를 찾는다.
EfficientDet에서는 이러한 방법을 적용해서 BiFPN의 architecture, detection head architecture, image resolution 등 결정한다.
BiFPN
Feature pyramid를 잘 설계하는 방법
Multi-scale feature fusion은 다른 resolution의 input feature \(\vec{P}^{in} = (P^{in}_{l_1}, P^{in}_{l_2},...)\)을 output feature \( \vec{P}^{out} = f(\vec{P}^{in} ) \)으로 변환해주는 함수 f로 정의할 수 있다. 다음 그림에 다양한 multi-scale fusion의 예시들이 있다
FPN:
- \(\vec{P}^{in} = (P^{in}_{3}, P^{in}_{4},P^{in}_{5},P^{in}_{6},P^{in}_{7})\)을 기반으로 \(\vec{P}^{in} \)를 다음과 같이 만든다 (Resize: feature의 width & height를 맞춰주기 위한 upsampling / downsampling을 뜻하는데 여기서는 upsampling)
- Feature dimension = 이미지 dimension x \( 2^{-i}\), i = layer index. 위에서 input size = 640 -> P3의 사이즈는 640/8 = 80
PANet
- FPN에서는 top-down pathway만 있는 반면 PANet에서는 bottom-up pathway도 추가된다 (resolution이 높은 feature들을 down-sampling해서 resolution이 낮은 feature들과 다시 섞어주는 연산)
- 성능은 좋지만 연산량이 많아진다
NAS-FPN
- neural architecture search (NAS)를 통해서 feature fusion잘 하는 방법을 찾아서 얻은 architecture.
- 단점: NAS를 할 때 연산량이 많이 필요하고, connectivity에 패턴을 찾기 힘들어서 이렇게 얻은 NAS-FPN을 수정하는 방식으로 더 좋은 architecture을 구하기 어렵다
BiFPN architecture
- 연산량을 단축하기 위해서 input edge가 1개밖에 없는 node는 제거한다 (Figure 2 (b)와 (d)를 비교해 보면 제거된 node들)
- input이 1개면 feature 들을 섞어주는데 기여도가 적다
- 같은 feature level에 residual connection: 연산량 증가는 적지만 feature fusion에 기여를 할 수 있다
- top-down & bottom-up 블록을 하나의 feature fusion layer로 보고, 반복을 한다 (밑에 Figure 3 참고)
Feature fusion할 때 weight를 다르게 주는 방법
- feature fusion을 할 때 서로 다른 resolution의 feature들에게 모두 같은 weight를 주는 것이 최적이 아닐 수 있다.
- 가장 무식한 방법은 \( O = \sum w_i I_i\)
- O: output feature, w: weight, I: input feature
- 단점: w에 bound가 없어서 발산할 우려가 있다
- softmax fusion: \( O = \sum_i \frac{e^{w_i}}{\sum_j e^{w_j}}\)
- 단점: softmax에 의한 연산량 증가
- Fast normalized fusion (BiFPN의 일부): \(O = \sum_i \frac{w_i}{\epsilon + \sum_j w_j }\)
- \( w_i\) 에 ReLU 연산을 해서 \( w_i \ge 0\) 만족하게 제약한다
- \(\epsilon \) = 0.0001: 발산 방지용
- 예시 (td: top-down에서 나온 intermediate feature 뜻함):
EfficientDet
Architecture (figure 3 참고)
- Backbone: EfficientNet
- Neck: BiFPN
- Classification & box regression head: conv net
- Focal loss 논문과 비슷하게 convolutional network의 parameter들은 모든 feature layer에 대해서 동일하다 (다른 feature level에 동일한 convolution 사용)
Compound scaling
- EfficientNet 논문과 비슷한 아이디어를 사용해서 network scaling factor을 구한다
- Backbone: width, depth scaling factor은 EfficientNet에서 사용한 (exponential) scaling factor을 그대로 사용 (depth (alpha) = 1.2, width (beta)= 1.1, phi: 원하는 연산량에 따라 결정)
- BiFPN: depth는 linear scaling을 한다 (이유: integer 값이어야 하는데 작은 숫자라서). Width (channel 수)는 exponential scaling. Grid search를 통해서 scaling factor = 1.35로 고정:
- Classification & box regression head: width는 bifpn과 동일 (\(W_{pred} = W_{bifpn}\)). Depth는 linear scaling \( D_{box} = D_{class} = 3 + [\phi/3]\) 사용 ([] = integer로 round down하는 함수)
- Image resolution: BiFPN에서 feature level 3~7을 사용하기 때문에 128=2^7의 배수 이어야 한다. \( R_{input} = 512 + \phi \cdot 128\) 사용.
scaling 요약:
학습 방법
- pre-training: ImageNet pretrained EfficientNet 사용
- optimizer: SGD, momentum = 0.9, weight decay = 4e-5
- lr scheduler: 0~0.16까지 linear warmup (1 epoch), 그 이후 cosine decay
- convolution 후 synchronized batch norm (momentum = 0.99, epsilon = 1e-3)
- SiLU activation
- EMA decay rate: 0.9998
- focal loss: \( \alpha = 0.25, \gamma = 1.5\), focal loss aspect ratio: 1/2, 1, 2
- horizontal flip, scale jittering (resize & crop)
- 300 epoch동안 학습 (D7은 600 epoch동안, \( phi=7\)이라는 뜻), batch size = 128
- soft NMS (evaluation)
실험 결과
보다시피 당시 나온 detector에 비해서 가성비가 좋다
Segmentation
- feature을 잘 섞는 것이 핵심 아이디어 중 하나기 때문에 BiFPN같은 경우 segmentation에도 적용이 가능하다.
- feature resolution이 높은 P2를 기반으로 EfficientDet-D4를 사용
- ImageNet pretrained EfficientNet-B4 사용
- channel size = 128 (BiFPN)
- channel size = 256 (segmentation을 위한 per-pixel classification head)
- BiFPN, classification head는 3번 반복
- 결론적으로 좋은 결과를 얻을 수 있었다:
'논문 리뷰 > object detection' 카테고리의 다른 글
[논문 리뷰] YOLOv6 (0) | 2023.07.09 |
---|---|
[논문 리뷰] YOLOX (0) | 2023.06.03 |
[논문 리뷰] PP-YOLO v1 (+v2) (3) | 2023.05.26 |
YOLOv5 정리 (2) | 2023.05.19 |
[논문 리뷰] YOLOv4 (상세 리뷰) (0) | 2023.04.11 |