Deeper Learning

R-CNN, Fast R-CNN, Faster R-CNN 본문

AI/Deep Learning

R-CNN, Fast R-CNN, Faster R-CNN

Dlaiml 2021. 3. 14. 16:22

2-stage detectors

2-stage detector는 객체가 존재할 가능성이 높은 영역(ROI: Region of Interest)을 추출하고 CNN을 통해 class와 boundig box의 위치를 찾는다.

R-CNN, Fast R-CNN, Faster R-CNN 등이 2-stage detector에 속하며, YOLO, SSD 등이 1-stage detector에 속한다.

 

2-stage detectors인 R-CNN, Fast R-CNN, Faster R-CNN에 대해 매우 간략하게 차이점과 발전과정을 중심으로 작성하고자 한다.

(자세한 각 알고리즘에 대한 설명은 후에 따로 작성할 예정)

R-CNN

 

Region Proposals with CNN(R-CNN)은 object detection을 수행하는 모델로 다음과 같은 단계로 이루어져 있다.

 

R-CNN

Selective Search 알고리즘을 사용하여 input image에서 2k의 region proposals을 추출한다.

Selective Search 알고리즘은 sub-segmentation을 수행하여 매우 많은 수의 초기 영역을 생성하고 Greedy 알고리즘을 통해 비슷한 영역을 통합하여 region proposals이 이루어진다.

 

이렇게 2k 개의 영역은 모두 같은 size로 변환되고 feature를 추출하기 위한 CNN 모델에 input으로 주어진다.

CNN의 output인 feature map은 bbox regression과 svm을 사용한 class classification에 사용된다.

 

R-CNN bbox-regression

4 Modules in R-CNN

  • Region Proposal 
  • CNN (input: extracted region proposals, output: fixed-length feature vector)
  • Linear SVM (input: fixed-length feature vector, output: classification results)
  • bbox regression (input: fixed-length feature vector, output: Regureesion results for bbox)

 

Fast R-CNN

Fast R-CNN은 R-CNN의 단점인 연산량을 획기적으로 줄이고 성능 또한 다소 향상된 모델이다.

 

Fast R-CNN

Fast R-CNN은 전체 input image를 CNN에 input으로 주어 feature map을 생성하고 ROI의 경우 projection 만을 하기 때문에 기존 R-CNN과 다르게 모든 ROI가 CNN을 통과하지 않기 때문에 연산량이 크게 줄었다.

 

ROI projection은 CNN에서 input과 output의 크기에 따른 비율을 ROI에 그대로 적용하여 좌표를 조정하는 것을 말한다.

ROI projection을 통해 지정된 영역을 crop 하여 ROI pooling layer를 통과시킨다.

Spartial Pyramid Pooling(SPP)를 사용하여 ROI pooling이 이루어진다.

 

SPP

지정된 feature map의 영역을 4x4, 2x2, 1x1 등 동일한 크기로 나누고 여기에서 한 칸에 해당하는 부분에서 maxpooling이 이루어진다. 이렇게 추출된 값은 linear 하게 연결되어 벡터로 변환된다.

 

SPPNet을 통해 생성된 linear feature 벡터는 FC layer를 통해 class classification과 bbox regression을 수행한다.

 

Faster R-CNN

Faster R-CNN은 Fast R-CNN의 구조에서 Region proposal을 위해 사용하던 Selective Search를 Region Proposal Network (RPN)으로 대체한 알고리즘이다.

 

Faster R-CNN

 

input image를 CNN에 통과시켜 feature map을 얻고 feature map에서 RPN을 사용하여 ROI를 추출한다.

 

RPN
Anchor boxes

sliding window를 사용하여 feature map에서 얻은 각 영역을 256-d Convolutional layer에 통과시킨다. 이때 크기가 변하지 않게 same padding을 한다.

k개의 anchor box에 대해 객체가 존재하는지 아닌지 판단, 4개의 bbox 좌표를 얻기 위해 각각 2k, 4k 차원의 벡터로 1x1 convolutional layer를 통해 차원을 변환시킨다.

 

bbox의 경우 IoU값을 통해 positive, negative sample로 labeling 할 수 있다.

 

IOU

 

학습이 완료되고 결과를 보면 하나의 객체에 대해 여러 개의 Anchor box가 true bbox 좌표와 IoU를 만족하여 생기게 된다.

 

Non-Maximum Suppression (NMS)를 사용하여 좀 더 정확하고 보기 좋은 결과를 얻을 수 있다.

NMS는 다음과 같은 단계로 이루어져 있다.

 

  1.  Select the box with the highest objectiveness score
  2.  Compare IoU of this box(1) with other boxes
  3.  Remove the bounding boxes with IoU >= 0.5 ( Remove overlapping box)
  4.  Move to next highest objectiveness score box
  5.  Repeat steps 2 ~ 4

 

NMS
R-CNN Family Structure (Object Detection for Dummies Part 3: R-CNN Family (lilianweng.github.io))

 

Reference

[1] Naver Boostcamp AI-Tech CV (오태현 교수님)

[2] Object Detection for Dummies Part 3: R-CNN Family (lilianweng.github.io)

[3] Ross Girshick. (2013). "Rich feature hierarchies for accurate object detection and semantic segmentation". arXiv:1311.2524. url

            

 

'AI > Deep Learning' 카테고리의 다른 글

BERT (Bidirectional Encoder Representations from Transformers)  (0) 2021.04.18
Multimodal Learning  (0) 2021.03.17
Semantic Segmentation  (0) 2021.03.12
Knowledge Distillation  (0) 2021.03.11
Graph Neural Network (GNN)  (0) 2021.02.26
Comments