본문 바로가기
공부/ML&DL

[머신러닝 공부] 딥러닝/SSD (object detection)

by 로디네로 2021. 4. 27.
반응형

 

YOLO V1 이후 VOLO V2 로 발전상을 공부하려 했으나 시간순서대로 짚어보는 것이 기술의 발전방향을 더 잘 이해할 수 있을 것 같아 이번엔 SSD에 대해 알아보았다.

 

 


 

 

1. 배경

 

YOLO V1에서의 grid cell 방식의 region proposal 방식이 Faster RCNN보다 훨씬 높은 FPS를 기록했다. 하지만 정확도 지표인 mAP는 낮게 나오는 문제가 있었다.

 

SSD는 region proposal 방식을 grid cell로 유지하면서 더 좋은 mAP를 낼 수는 없을까 하는 데에서 만들어진 object detection 모델이다.

 


 

2. 구조

 

1) Modified VGG Net (수정된 VGG Net)

 

SSD에서는 수정한 VGG Net을 통해 Feature extraction을 진행했다.

 

https://89douner.tistory.com/94?category=878735

 

이것이 SSD 즉 Single Shot Detector 이름의 기원이라고 볼 수 있다.

 

기존의 Detector들은 처음 훈련시킨 크기만을 입력으로 받아 이를 변형하는 과정을 거쳤다.

 

Image Pyramid, Sliding Window, Region Proposal Network 등으로 입력 이미지를 변형했다.

 

하지만 SSD는 말그대로 사진의 변형 없이 그 한장으로 훈련과 검출을 하는 Detector이다.

 

네트워크를 덜 거치기 때문에 횟수 차이에 따른 속도 향상이 일어날 수 있다.

 

 

2) Remove FC layer

 

FC layer를 제거시킨다.

 

이로써 얻을 수 있는 효과는 다음과 같다.

  1. object detection 모델에서 입력 이미지를 고정시키지 않아도 된다.
  2. parameter 개수의 급격한 감소로 속도 향상

 

 

3) Multi map scale feature maps

 

SSD도 YOLO V1 처럼 grid cell에서 고정된 개수의 default boxes를 사용하게 되어, 학습을 마친 anchor boxes가 각기 다른 output feature map에 적용되었을 때 검출할 수 있는 객체가 다양해진다.

 

ex) 

위에서와 같이 다양한 크기의 feature map을 detection 하기 위해 사용한다면 좋은 성능을 기대할 수 있을것이다.

 

 

4) Detection

3번에서의 다양한 output feature map이 어떻게 결합되는 걸까?

 

위의 그림에서와 같은 형태로 결합되는 것을 볼 수 있다.

 

각 conv layer 별로 뽑아낸 anchor box 들을 합한 개수는 8732개가 된다. (8732x(Classes+4))

 

 

5) NMS

8732(Classes+4) 개의 feature들을 뽑게되면 아래와 같이 각각의 output feature map에서 뽑은 anchor box들 때문에 하나의 객체에 대해 많은 bounding box들이 생성되게 된다.

 

https://m.blog.naver.com/sogangori/221007697796

 

난잡한 anchor box들 중 NMS를 적용하여 가장 높은 score를 보이는 box를 선택하게 된다.

 

NMS(Non Maximum Suppression)에 대한 설명은 아래 YOLO V1 포스팅에 설명

( dbstndi6316.tistory.com/279 )

 

 


 

3. 학습

 

1) Shape of anchor boxes

 

1-1 scale factor

 

Anchor box들을 생성시킬때 아래와 같이 aspect ratio가 다르기 때문에, aspect ratio를 다르게 하는 anchor box들을 생성해 주어야 한다.

 

이 때 aspect ratio의 기준이 되는 크기를 선정해주어야 한다.

 

크기가 존재해야 비율이 의미있어지기 때문이다.

SSD는 detection을 위해 총 6개의 feature map들을 사용하고 각 feature map마다 grid cell의 크기가 다르다.

 

때문에 6개의 output feature map에 따라서 scale factor를 다르게 주어야 한다.

 

아래 그림과 같이 뒤에 있는 feature map일 수록 grid cell의 크기는 커진다.

 

https://towardsdatascience.com/implementing-ssd-in-keras-part-i-network-structure-da3323f11cff

 

아래의 식을 통해서 output feature map에 따라 알맞은 scale factor값을 도출할 수 있다.

 

 

1-2 width and height

 

1-1 에서 Aspect ratio 의 scale factor를 결정했다.

 

그 다음은 aspect ratio에 따라 anchor box들의 width와 height를 정의해준다.

 

SSD는 아래와 같은 aspect ratio를 설정하고 식을 통해 scale factor 에 따라 width, height를 결정해준다.

 

이렇게해서 anchor box들의 모양을 결정하였다. 이후에는 이들의 학습이 필요할 것이다.

 


2) Bounding box regression

 

2-1 Select candidate anchor boxes by using Jaccard overlap

 

SSD는 각각의 다른 output feature map마다 anchor box들을 생성한다고 했다.

 

이러한 anchor box들 중 우리는 GT와 유사한 anchor box를 학습에 이용하고 싶다.

 

따라서 GT와 유사한 IoU 수치를 갖는 anchor box에 대해서만 학습을 진행하는데 이를 위해 jaccard overlap 방식을 사용한다.

During training we need to determine which default boxes correspond to a ground truth detection and train the network accordingly. We begin by matching each ground truth box to the default box with the best jaccard overlap(= IOU). Unlike MultiBox, We then match default boxes to any ground truth with jaccard overlap higher than a threshold(0.5).

두 영역의 IoU가 0.5 이상인 것들을 match함.

 

하지만, IoU가 0.5 이상이더라도 box의 위치가 negative 한 경우가 있을 것이다.

 

SSD에서는 jaccard overlap을 통해 선별된 anchor box들 중 가장 높은 confidence loss를 기준으로 positive example과 negative example의 비율을 3:1로 나누게 된다.

 

 

2-2 bounding box regression

 

bounding box의 좌표에 대해 학습하게 된다. (localization)

N : 검출된 박스의 개수
g : ground truth box, 실제 박스의 변수들을 의미
d : default box
c : category
l : predicted boxex, 예상된 박스의 변수들을 의미
cx, cy : offset of center
w, h : width , height
alpha : weight term, 1로 정함

 

위의 식으로 loss를 줄이는 방향으로 학습하게 된다.

 


 

4. 결과

 

https://github.com/sejongresearch/FlowerClassification/issues/18
https://github.com/sejongresearch/FlowerClassification/issues/18

 

 


 

5. References

arxiv.org/abs/1512.02325

89douner.tistory.com/93?category=878735

m.blog.naver.com/sogangori/221007697796

junjiwon1031.github.io/2017/09/08/Single-Shot-Multibox-Detector.html

nuguziii.github.io/survey/S-001/?

반응형

댓글