본문 바로가기

Data-science/deep learning

detection 복습

반응형
  • Faster R-CNN

Faster R-CNN 플로우 차트
Faster R-CNN 플로우 차트 
Faster R-CNN에 쓰이는 RPN

  • 알고리즘
feature_maps = process(image)                           # deep CNN으로 피쳐맵 추출
ROIs = region_proposal(feature_maps)                    # 피쳐맵에서 RPN으로 ROI 추출
for ROI in ROIs                                         # 각 ROI에 대해서
    patch = roi_pooling(feature_maps, ROI)              # ROI 풀링
    class_scores, box = detector(patch) # Expensive!    # ROI에 대해 class score/ box regression        
    class_probabilities = softmax(class_scores)          # class score에 대한 확률값

 

 

cf0) Anchors?

- 처음 물체 위치를 예측할 때 reference로 쓰이는 고정된 크기의 bounding box

are fixed bounding boxes that are placed throughout the image with different sizes and ratios that are going to be used for reference when first predicting object locations.

- conv feature map의 크기를 w x h x d 라고 하면, feature map w x h 내의 각 점에서 anchor set을 생성한다.  

Since we are working with a convolutional feature map of size conv_w x conv_h x conv_depth, we create a set of anchors for each of the points in conv_w x conv_h.

- conv와 pooling만 하므로 feature amp은 원본 이미지 크기와 비례한다. 이미지 크기가 w x h라면 feature map의 크기는 w/r x h/r이 된다. (r은 subsampling ratio라고 한다), feature map에서 공간상 위치마다 하나의 anchor를 정의한다면, 최종 이미지에는 r pixel 만큼 분리된 앵커 세트들이 존재할 것이다.

Anchor centers throught the original image
The RPN takes the convolutional feature map and generates proposals over the image

cf1) RPN 은 모든 conv featuremap을 input 값으로 받아 모든 anchors 에 대해서 object에 대한 roi를 output으로 배출. 각 anchor들 마다 두 개의 다른 결과 값을 가진다. (object에 대한 확률 값, bounding box regression)

the RPN takes all the reference boxes (anchors) and outputs a set of good proposals for objects. It does this by having two different outputs for each of the anchors.

 

Q0) RPN에 나온 ROI가 이후 ROI pooling에 쓰여서 classification이 되는지 아니면 deepCNN의 피쳐맵이 ROI pooling되어 classification 되는지? (피쳐맵, RPN 두개가 합쳐져서 ROI pooling이 되는 게 이해가 안됐다.)

- RPN에서 나온 ROI의 위치 정보에 해당하는 피쳐맵을 crop하기 위해 피쳐맵 정보가 필요. 해당 ROI에서 ROI pooling을 적용하여 pooling된 ROI에서 classification 및 bounding box regression을 한다.

crop the convolutional feature map using each proposal and then resize each crop to a fixed sized 14 x 14 x convdepth using interpolation (usually bilinear).

RPN을 통해 추출된 Region proposal(=ROI)에 ROI pooling을 적용한다.

 

Q1) Anchor를 통해 ROI를 찾을 때 입력 값이 피쳐 맵인데 왜 Anchor의 scale은 입력 피쳐맵의 크기보다 크게 정의되기도 하는가? 원본 영상에 다시 ROI를 투영하는 방식인가??

- Anchor는 피쳐 맵 기준으로 정의되지만, 최종 anchor는 원본 입력 이미지를 참조한다.

It’s important to understand that even though anchors are defined based on the convolutional feature map, the final anchors reference the original image.

 

Q2) 왜 classification을 두 번이나 하는가? (RPN에서 한 번, 마지막 단에서 한 번)

- After the RPN step, we have a bunch of object proposals with no class assigned to them. 

RPN에서 object classification을 하고, 후단의 FC  layer에서 해당 object의 class를 classification 한다.

 

Q3) 왜 bounding box regression을 두 번이나 하는가? (RPN에서 한 번, 마지막 단에서 한 번)

- object가 예측된 category에 맞게 기존 제안된 bounding box를  더 잘 맞게 수정한다.

Better adjust the bounding box for the proposal according to the predicted class.

 

Q4) 마지막 detection 단의 regression에서의 nms와 RPN에서의 nms는 어떤 차이가 있는가?

RPN에선 IOU가 특정 값 이상인 경우 제거해버린다.

Region-based CNN 혹은 detection 단계에선 IOU가 아닌 확률 값을 본다.

제안된 영역 중 어떤 것이 가장 높은 확률을 가진 class 인지, 또 배경 class 확률 값이 가장 높은 제안 영역은 무시한다. 이후 배경으로 예측된 영역들을 제외하고 최종 물체들 중에 nms를 적용한다.

   - 이때, 이 물체들을 클래스 별로 확률 값에 따라 sorting한다. 그리고 각 클래스 별로 nms를 적용  

 

- RPN nms : IoU threshold

- Region-based CNN nms (class-based nms) : probability threshold

After getting the final objects and ignoring those predicted as background, we apply class-based NMS.

This is done by grouping the objects by class, sorting them by probability and then applying NMS to each independent group before joining them again.

 

  The way NMS works is :

-> 처음엔 object가 존재할 확률 값으로 특정 값 이하의 cell들을 다 버린다. (확률기반 nms)

-> 이후 예측한 object 후보들 사이에서 사장 큰 확률 값을 가진 cell을 채택하고,

-> 마지막으로 남은 cell들 중에서 예측한 cell과 IOU가 0.5 이상인 cell들을 버린다. (IOU 기반 nms)
→ It first discards all those cells where probability of object being present (calculated in final softmax layer) is <= 0.6
→ Then it takes the cell with largest probability among candidates for object as a prediction
→ Finally we discard any remaining cell with Intersection over union value >= 0.5 with the prediction cell.

 

  • Mask R-CNN

Mask R-CNN flow
Mask R-CNN detail

ref) https://medium.com/@jonathan_hui/what-do-we-learn-from-region-based-object-detectors-faster-r-cnn-r-fcn-fpn-7e354377a7c9

 

What do we learn from region based object detectors (Faster R-CNN, R-FCN, FPN)?

In this series, we will take a comprehensive journey on object detection. In Part 1 here, we cover the region based object detectors…

medium.com

https://tryolabs.com/blog/2018/01/18/faster-r-cnn-down-the-rabbit-hole-of-modern-object-detection/

 

Faster R-CNN: Down the rabbit hole of modern object detection | Tryolabs Blog

Previously, we talked about object detection, what it is and how it has been recently tackled using deep learning. If you haven’t read our previous blog post, we suggest you take a look at it before continuing. Last year, we decided to get into Faster R-CN

tryolabs.com

 

반응형