(RetinaNet) Focal Loss for Dense Object Detection

HyungSeop Lee·2024년 3월 7일
0

Paper Info

  • paper : Focal Loss for Dense Object Detection
  • author : Tsung-Yi Lin, Priya Goyal, Ross Girshick, Kaiming He, Piotr Dollár
  • subject : 2017 IEEE International Conference on Computer Vision (ICCV)

Abstract

  • one-stage detector들은 two-stage detector들에 비해
    faster and simpler한 potential이 있다.
    하지만 accuracy측면에서는 아직 two-stage detector들에 비해 한참 멀었다.

  • In this paper, we investigate why this is the case.
    (왜 one-stage detector들의 accuracy가 two-stage detector들에 비해 떨어지는지 밝혀낼 것이다.)

  • 우리는 the extreme foreground-background class imbalance이 중요한 원인임을 발견했다.
    ➡️ 이를 해결하기 위해,
    standard cross entropy loss를 reshape하여 well-classified examples에 대해서 assign된 loss에 가중을 낮추는 방식을 사용했다.
    ➡️ 이와 같은 새로운 Focal Loss는 training을 일부 hard examples에 focus시키고,
    training 중에 easy negatives들이 detector를 overwhelming하는 것을 방지한다.

  • 우리의 효율적인 Focal Loss를 평가하기 위해서 simple dense detector인 RetinaNet을 design하고 train시켰다.


1. Introduction

  • two-stage detector들의 success에도 불구하고 나오는 질문은 :
    simple one-stage detector도 similar accuracy를 달성할 수는 없을까?이다.
    최근 YOLO and SSD 같은 one-stage detector들은 two-stage method들에 비해
    accuracy를 10-40%만 줄이면서 faster detector임을 보였다.

  • 하지만 이 논문에서는 더 나아가,
    처음으로 FPN 또는 Mask R-CNN의 variants인 Faster R-CNN과 같이
    more complex two-stage의 state-of-the-art COCO AP와 일치하는
    one-stage object detector를 소개할 것이다.

  • 위 결과를 달성하기 위해서,
    우리는 주요 장애물로써, training 시에 class imbalance가 발생한다는 것을 알아냈다.
    그리고 우리는 class imbalance를 제거할 수 있는 new loss(= focal loss)를 소개할 것이다.

  • two-stage detector들은 class imbalance 문제를
    two-stage cascade and sampling heuristics로 해결할 수 있었다.

    • The proposal stage에서는
      cadidate object locations의 숫자를 급격히 줄이면서
      대부분의 background samples를 filtering out하였다.
    • The second classification stage에서는
      a fixed foreground-to-background ratio (1:3)
      또는 online hard example mining(OHEM)과 같은
      sampling heuristics을 사용하여 foreground와 background 간의 관리 가능한 balance를 유지할 수 있었다.
  • 반면에,
    one-stage detector들은
    image 전체에 균일하게 sampling된
    훨씬 더 많은 the set of candidate object locations를 처리해야 한다.
    two-stage detector처럼 similar sampling heuristics을 적용할 수는 있지만,
    여전히 training procedure은 쉽게 classified되는 background examples에 의해
    dominated되어질 수 있어서 비효율적이다.

    이 논문에서는 이전에 class imbalance 문제를 다룰 수 있는 이전의 접근법들에 비해
    더욱 효율적으로 동작하는 new loss function을 제안할 것이다.
    the new loss function은 dynamical하게 scaled되는 cross entropy loss이다.
    이때 scaling factor는 correct class가 증가함에 따라 0으로 감소하게 된다.
    Figure 1. 참고.

    이 scaling factor(γ\gamma)는
    training 중 easy examples의 contribution을 자동으로 줄일 수 있으며,
    model을 빠르게 hard examples에 focus하도록 만들 수 있다.

    실험 결과, 우리의 Focal Loss를 사용한 one-stage detector는
    the sampling heuristics or hard example mining, 이전에 one-stage detectors를 training시키기 위한 state-of-the-art techniques들에 비해
    high-accuracy로 train시킬 수 있다.

  • To demonstrate the effectiveness of the proposed focal loss,
    우리는 an input image에서 object locations를 dense sampling하는
    a simple one-stage object detector인 RetinaNet
    을 design했다.
    이 design은 effective in-network feature pyramid와 anchor boxes를 사용하는 것을 특징으로 한다.

    ResNet-101-FPN backbone을 base로 한 RetinaNet
    COCO test-dev AP가 39.1을 달성하며 초당 5fps에서 작동한다.
    이는 Figure 2.에서 볼 수 있듯이,
    이전에 발표된 best single-models results from both one and two-stage detectors들을 능가한다.


2. Related Work

(skip)


3. Focal Loss

  • Focal Loss
    training 동안 foreground and background classes가 (1 : 1000)인 극한의 scenario에서
    one-stage object detection을 다루기 위해 design되었다.

  • 우리는 Cross Entropy(CE) loss for binary classification으로부터 focal loss를 소개할 것이다.


3.1. Balanced Cross Entropy


3.2. Focal Loss Definition


3.3. Class Imbalance and Model Initialization

  • Binary classification models은 기본적으로
    y=1y=-1 or y=1y=1을 출력할 확률이 동일하도록 initialized된다.
    이러한 initialization 상태에서 class imbalance가 존재할 경우,
    빈도가 높은 class로 인한 loss가 전체 loss를 dominate하고
    초기 training에서 instability를 초래할 수 있다.

  • 이를 극복하기 위해,
    training 시작 시 model이 예측하는 rare class(foreground)에 대한
    pp값에 대한 'prior(사전)'개념을 도입했다.

    • 우리는 prior을 π\pi로 표시하고,
      rare class의 examples에 대한 model의 estimated pp가 낮도록 설정했다. (e.g. 0.01)
    • 이것은 model initialization의 변경이지, loss function의 변경은 아님.
    • 우리는 prior를 도입한 initialization이 class imbalance의 경우에
      cross entropy와 focal loss 모두에 대한 training stability를 향상시킨다는 것을 발견했다.

3.4. Class Imbalance and Two-stage Detectors

  • Two-stage detector들은
    cross entropy loss without use of α\alpha-balancing or our proposed loss로 train되어진다.
    대신에, two-stage detector들은 두가지 mechanism을 통해 해결한다.
    1. a two-stage cascade
    2. biased minibatch sampling
  • Our proposed focal loss는 이러한 mechanism을 loss function을 통해
    직접적으로 해결하기 위해 one-stage detection system에 design되어졌다.

4. RetinaNet Detector

  • RetinaNet
    backbone network와 two task-specific subnetworks로 이루어진
    a single, unifed network이다.
    • The backbone
      전체 input image에 대한 convolutional feature map을 계산하고
      off-the-self convolutional network이다.
    • The first subnet
      backbone's output에 대한 convolutional object classification을 수행한다.
    • The second subnet
      convolutional bounding box regression을 수행한다.

Feature Pyramid Network Backbone

  • We adopt the Feature Pyramid Network(FPN) as the backbone network for RetinaNet.

    간단히 말해서,
    FPN은 standard convolutional network를
    top-down pathway and lateral connections를 추가하여
    a single resolution input image에 대해서
    multi-scale feature pyramid를 효율적으로 만들어내는 network이다.
    pyramid의 each level은 different scale의 object를 detecting하는 데에 사용되어,
    multi-scale prediction을 향상시킬 수 있다.

  • FPN 논문에서 처럼,
    우리는 ResNet architecture 위에 FPN을 구축했다.
    우리는 level P3P_3-P7P_7까지의 pyramid를 구성했다.
    여기서 ll은 pyramid level을 indicates한다.
    (PlP_l은 input보다 2l2^l배 낮은 resolution을 갖음)
    또한 FPN 논문에서 처럼
    all pyramid level에 C=256C=256 channels를 갖는다.
    하지만 FPN과는 몇 가지 차이점이 있다.
    (아래의 minor modifications들ㄹ은 accuracy를 유지하면서 speed를 향상시킴)

    1. we don't use the high-resolutino pyramid level P2P_2 for computational reasons
    2. P6P_6 is computed by strided convolution instead of downsampling
    3. we include P7P_7 to improve large object detection.

Anchors

  • we use translation-invariant anchor boxes similar to those in RPN variant in FPN.
    The anchors have areas of 32232^2 to 5122512^2 on pyramid levels P3P_3 to P7P_7, respectively.
    As in FPN, at each pyramid level we use anchors at three aspect ratios {1:2, 1;1, 2:1}

  • For densor scale coverage than in FPN,
    at each level we add anchors of sizes {20/3,21/3,22/32^{0/3}, 2^{1/3}, 2^{2/3}} of the original set of 3 aspect ratio anchors.

  • In total there are A=9A=9 anchors per level
    and across levels they cover the scale range 32 - 813 pixels with respect to the network's input image.
    (32 = 32×20/3\times 2^{0/3}, 813 = 512×22/3\times 2^{2/3})

  • Each anchor is assigned a length KK one-hot vector of classification targets,
    where KK is the number of object classes, and a 4-vector of box regression targets.

  • We use the assignment rule from RPN[Faster R-CNN]
    but modified for multi-class detection and with adjusted thresholds

    • anchors are assigned to ground-truth object boxes using a IoU threshold of 0.5; and to back-ground if their IoU is in [0, 0.4).
    • As each anchor is assigned to at most one object box,
      we set the corresponding entry in its length KK label vector
      to 1 and all other entries to 0.
    • If an anchor is unassigned,
      which may happen with overlap in [0.4, 0.5),
      it is ignored during training.
    • Box regression targets are computed as the offset between each anchor and its assigned object box, or omitted if there is no assignment.

      (요약) 만약 GT와의 IoU가
      0.5 이상이면 positive anchor.
      0.4보다 미만이면 negative anchor.
      그 사이 값이라면 training 시 무시. (regression subnetwork에 들어가지 않음)

Classification Subnet

  • Classification subnet predicts the probability of object presence at each spatial position for each of the AA anchor and KK object classes.
    This subnet is a small FCN attached to each FPN level;
    parameters of this subnet are shared across all pyramid levels.
    • Taking an input feature map with CC channels from a given pyramid level,
    • the subset applies four 3×33 \times 3 conv layers,
      each with CC filters and each followed by ReLU activations, followed by a 3×33 \times 3 conv layer with KAKA filters.
    • Finally sigmoid activations are attached to output the KAKA binary predictions per spatial locations.
      We use C=256C=256 and A=9A=9 in most experiments.

Box Regression Subnet

  • In parallel with the object classification subnet,
    we attach another small FCN to each pyramid level for the purpose of regressing the offset from each anchor box to a nearby ground-truth object, if one exists.
    The design of the box regression subnet is identical to the classification subnet except that it terminates in 4A4A linear outputs per spatial location
    • For each of the AA anchors per spatial location,
      these 4 outputs predict the relative offset between the anchor and the ground-truth box
      (we use the standard parameterization from R-CNN)
    • we note that unlike most recent work,
      we use a class-agnostic bounding box regressor which uses fewer parameters and we found to be equally effective.
      (class-agnostic bbox 참고 : https://cvml.tistory.com/3
      간단히 말해, bbox 위치 좌표 4개만 regression하고, classification은 하지 않음)

4.1. Inference and Training

Inference

  • RetinaNet forms a single FCN comprised of a ResNet-FPN backbone, classification subnet, and a box regression subnet.

  • 속도를 향상시키기 위해,
    우리는 FPN level 당 최대 1k개 top-scoring predictions으로부터
    box predictions만 decode했다.
    이때, detector confidence는 0.05로 thresholding했다.
    모든 level에서의 top predictions은 merge되어지고,
    0.5 threshold값을 사용하여 nms를 거쳐 final detections을 얻는다.

Focal Loss

  • we use the focal loss as the loss on the output of the classification subnet.
    • we find that γ=2\gamma=2 works well in practice
      and RetinaNet is relatively robust to γ[0.5,5]\gamma \in [0.5, 5].
    • the focal loss is applied to all~100k anchors in each sampled image.
    • the total focal loss of an image is computed as the sum of the focal loss over all ~ 100k anchors,
      normalized by the number of anchors assigned(not total anchors) to a ground-truth box
      왜냐하면 focal loss에서 미미한 loss값을 받는 대부분의 anchor가 easy negative이기 때문에, 할당된 anchor 개수로 normalization을 수행.

Initialization

  • we experiment with ResNet-50-FPN and ResNet-101-FPN backbones.
    • The base ResNet-50 and ResNet-101 models are pretrained on ImageNet1k
    • new layers added for FPN are initialized as in FPN.
    • all new conv layers except the final one in the RetinaNet subnets
      are initialized with bias b=0b=0 and a Gaussian weight fill with σ=0.01\sigma=0.01
    • for the final conv layer of the classification subnet,
      we set the bias initialization to b=log((1π)/π)b=-log((1-\pi)/\pi),
      where π\pi specifies that at the start of training every anchor should be labeled as foreground with confidence of ~π\pi.
      (π\pi는 training 시작 시 모든 anchor가 약 π\pi의 confidence로 foreground label되어져야 한다는 것을 지정 ???)
      (#3.3. part에 나온 'prior' 개념)
      we use π=.01\pi=.01 in all experiments.
    • this initialization prevents the large number of background anchors from generating a large, destabilizing loss value in the first iteration of training.

Optimization

profile
model compression

0개의 댓글