Lin, Zhihao, et al. "Dynamicdet: A unified dynamic architecture for object detection." Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition. 2023.
Dynamic neural network는 DL에서 떠오르는 연구 주제이다.
adaptive inference를 통해, dynamic models은 놀라운 accuracy and computational efficiency를 달성할 수 있다.
그러나 object detection을 위한 powerful dynamic detector를 설계하는 것은
적절한 dynamic architecture와 exiting criterion(종료 기준)이 없기 때문에 challenging하다.
이러한 어려움을 해결하기 위해,
우리는 DynamicDet
이라는 a dynamic framework for object detection을 제안한다.
object detection은 많은 vision tasks 분야에서 사용되고 있는 필수적인 분야이다.
최근에, more accurate and faster detectors로 발전되고 있다.
(예를 들어, Network Architecture Search(NAS)-based detectors and YOLO series models.)
하지만 이러한 방법들은 accuracy and speed 사이의 좋은 trade-offs를 이루기 위해 여러 model들을 design and train해야 한다.
이는 다양한 application scenarios에 충분히 flexible하지 않다.
이 문제를 완화하기 위해, 우리는 object detection task를 위한 dynamic inference에 초점을 맞추고,
단 하나의 dynamic detector를 사용하여 넓은 범위의 good accuracy-speed trade-offs를 이루려고 시도했다. (Fig.1)
인간의 두뇌는 deep learning 분야에서 많은 영감을 주고 있으며, dynamic neural network([12])가 그 대표적인 예시이다.Fig. 2의 두 가지 예를 보면,
우리는 왼쪽의 "easy" image에서는 모든 object를 빠르게 식별할 수 있지만,
오른쪽 image에서는 같은 효과를 달성하는 데에 더 많은 시간이 필요하다.
즉, 우리 두뇌에서 image의 처리 속도는 image의 difficulties(난이도)에 따라 다르다.
이 특성은 image-wise dynamic neural network의 motivation이 되며,
많은 흥미로운 연구들이 제안되어왔다. (e.g., Branchnet, MSDNet, DVT).
비록 이러한 접근법들이 놀라운 성능을 달성했지만, 모두 image classification task를 위해 설계되었으며 다른 vision task, 특히 object detection에는 적합하지 않다.
image-wise dynamic detector를 설계하는 주요 어려움은 다음과 같다.
Dynamic detectors cannot utilize the existing dynamic architectures.
Dynamic detectors cannot exploit the existing exiting criteria for image classification.
DynamicDet
이라고 한다.object detector의 성능은 backbone이 추출하는 multi-scale features에 크게 의존하기 때문에
backbone은 object detection에서 매우 중요한 역할을 한다.
ResNet과 그 variants(e.g., ResNeXt, Res2Net)은 residual connection을 neural networks에 도입하여
모든 vision task에 high-quality backbone architecture family를 제공한다.
더 나아가, calculation load를 줄이기 위해 CSPNet은 duplicate(중복된) gradient information을 줄여
heavy inference를 감소시키고 efficiency를 크게 증가시켰다.
이 효과적인 architecture는 많은 lightweight detector(e.g., YOLO series models)에 영감을 주었다.
이후, global information을 더 잘 학습하기 위해 일부 transformer-based backbones(e.g., PVT, Swin Transformer)들이 제안되었다.
또한 object detection을 위해 auto-designed backbones들도 제안되었다.
예를 들어, DetNAS는 object detection task의 guidance에 따라 optimal backbone을 탐색하기 위해 one-shot suprenet을 활용한다.
비록 많은 종류의 backbone이 제안되어왔지만,
거의 모든 backbone이 one set of multi-scale features를 순차적으로 생성하는
single-pass architecture이기 때문에 모든 stages가 skip될 수 없다.
다행히도 일부 연구에서는 multiple cascaded backbones architecture를 제안하여 dynamic backbone으로 변환할 가능성을 제시한다.
예를 들어,
CBNet은 많은 identical(동일한) backbones을
composite(복합) connections로 group화하여
더 강력한 composite backbone을 만든다.
이러한 backbone은 multiple sub-backbones을 가지고 있으며
각 sub-backbone은 intermediate multi-scale features를 생성할 수 있으므로,
dynamic inference를 위해 exiting points를 추가할 수 있다.
거의 모든 detection method들은 더 나은 accuracy-speed trade-off를 위해 설계되었다.
주어진 detector에서, acc-speed trade-off를 얻는 가장 간단한 방법은 model scaling technique들을 채택하는 것이다. (e.g., channel size를 늘리거나 layer를 반복)
EfficientDet은 모든 module의 resolution, depth, width를 동시에 균일하게 scaling하여
real-time detector에서 놀라운 efficiency를 달성했다.
Sclaed-YOLOv4는 더 나은 trade-off를 추구하기 위해 depth, width, resolution 뿐만 아니라 network structure도 수정했다.
YOLOv7은 concatenation-based model을 위해 compound scaling method를 설계하여 SOTA를 달성했다.
EAutoDet은 supernet을 구축하고 다양한 HW constraints에서 적절한 scaling factor를
자동으로 검색하기 위해 Network Architecture Search(NAS)를 채택했다.
그러나 위의 모든 방법은 best trade-offs를 위해 여러 detector들을 훈련해야 한다.
(e.g., real-time detection을 위한 하나의 tiny model과 정확한 detection을 위한 또 다른 large model)
이는 막대한 training resource를 필요로 한다.
본 논문에서는 dynamic detector에 중점을 두고 하나의 dynamic detector로 광범위한 accuracy-speed trade-offs를 달성하는 것을 목표로 한다.
dynamic neural network는 image별 또는 pixels별로 adaptive computation을 할 수 있다.
우리의 DynamicDet과 가장 유사한 연구는 Adaptive Feeding이다.
Adaptive Feeding에서는 각 image가 lightweight detector(e.g., Tiny YOLO)로 detection된 후,
SVM을 사용하여 easy or hard image를 분류한다.
이후 easy image들은 fast detector(e.g., SSD300)을 통해 처리되고,
hard image들은 더 정확하지만 느린 detector(e.g., SSD500)을 통해 처리된다.
Adaptive Feeding은 이러한 multi-stage process를 dynamic inference에 도입하지만,
이는 비효율적이고 not elegant(우아하지 않다.)
반면,
제안된 DynamicDet은 두 개의 detectors와 하나의 classifier(즉, router)를 연계하여
more unified and efficient dynamic detector를 제공한다.
object detector에서 다양한 scale의 feature들은 서로 다른 역할을 한다.
일반적으로,
shallow layer의 feature는 strong spatial information and small receptive fields를 가지고 있어서
주로 small object를 detect하는 데 사용된다.
deep layer의 feature는 strong semantic information and large receptive fields를 가지고 있어서
주로 large object를 detect하는 데 사용된다.
이러한 속성은 image의 difficulty score를 predicting할 때 multi-scale information을 고려하는 것을 필수적이게 한다.
이를 기반으로, 우리는 multi-scale features에 기반한 adaptive router를 설계했다.
이는 dynamic detector에 대한 간단하지만 효과적인 decision-maker이다.
squeeze-and-excitation(SE) module에 영감 받아,
우리는 multi-scale features인 을 독립적으로 pooling하고 이를 모두 concatenate한다.는 global average pooling을 denote하고
는 channel-wise concatenation을 denote한다.
이 operation을 통해, multi-scale features 을 dimension 인 vector 로 압축한다.
그런 다음, 이 vector를 두 개의 learnable fc layers를 통해 difficulty score 로 mappting한다.는 ReLU, 는 Sigmoid activation function을 의미한다.
그리고 는 learnable parameter를 의미한다.
[59]에 따라서, 우리는 첫 번째 fc layer에서 feature dimension을 로 줄이고,
두 번째 fc layer에서는 Sigmoid를 사용하여 predicted score를 생선한다.
주목할 점은, 모든 multi-scale features를 pooling하기 때문에 router의 부담이 무시할 수 있을 정도로 작다는 것이다.
이 section에서는 위의 dynamic architecture에 대한 optimization strategy를 설명한다.
먼저, 우리는 cascaded detectors를 jointly train하며, training objective는 다음과 같다.는 각각 Input image와 ground truth를 나타낸다.
는 detector 의 learnable parameters를 의미한다.
는 detector i에 대한 training loss를 의미한다 (e.g., bbox regression loss and classification loss)
위의 training 단계 이후에, 두 개의 detectors는 objects를 detec할 수 있게 되고,
trainng 이후에는 두 detector의 parameters인 을 freeze한다.
그리고 나서,
우리는 adaptive router를 training하여 자동으로 image의 difficulty를 구분하도록 한다.
여기서 router의 Parameters를 이라 하고
predicted difficulty score은 Eq.(8)로부터 얻은 이다.
우리는 router가 "easy" images(i.e., with lower )는 faster detector(i.e., the first detector)에 할당고
"hard" images(i.e., with higher )는 more accurate detector(i.e., the second detector)에 할당하기를 원한다.
하지만 실제로 이를 구현하는 것은 단순하지 않다.
아무런 제약 없이 바로 router를 optimize하면,
router는 항상 lower training loss를 위해서 the most accurate detector를 선택하게 될 것이다.
게다가, 다음과 같이 만약 training objective에 hardware constraints를 단순히 더해준다면hyper parameter 를 시행착오로 조정해야 하므로 막대한 workforce consumption(인력 소모)가 발생한다.
위 문제를 극복하기 위해, 우리는 adaptive router에 대해 hyper parameter가 없는 optimization strategy를 제안한다.
먼저, Fig. 4.에서 보이는 것처럼, 두 detector의 image에 대한 loss difference를 기준으로 difficulty criterion을 정의한다.
구체적으로,
만약 image에 대한 두 detector의 loss difference가 충분히 작다면, 이 image는 "easy" image로 분류될 수 있다고 가정한다.
반면, loss difference가 충분히 크다면, 이는 "hard" image로 분류되어야 한다.
이상적으로는 balanced situation을 위해,
우리는 모든 image의 절반은 first detector를 거치고, 나머지 절반은 second detector를 거치길 바란다.
(내 생각 : 성능이 크게 떨어지지 않는다는 가정 하에 first detector만 거치는게 이상적이지 않은가?)
이를 달성하기 위해, 두 detector의 loss를 균형 있게 하기 위한 adaptive offset을 도입하고, gradient descent를 통해 router를 optimize한다.
실제로, 우리는 먼저 training set에서 first detector와 second detector의 training loss difference 의 median(중앙값)을 계산했다.
그런 다음, router의 training objective는 다음과 같이 formulated될 수 있다.는 first detector에 reward와 second detector에 punish를 주기 위해 사용된다.Fig. 5.에서 보여지는 qualitative analysis에 따르면,
이러한 reward and penalty 없이, second detector의 loss가 항상 first detector보다 작게 나타난다.
하지만 reward and penalty를 적용하면, 두 loss curves는 intersect(교차)하며 optimal curve를 드러낸다.
우리의 training objective는 difficulty score 를 통해
router의 모든 parameters 에 다음과 같은 gradient를 도입하여 adaptive router를 optimize하는 means(수단)을 제공한다."easy"와 "hard" images를 더 잘 구분하기 위해서,
우리는 router의 optimization direction이 image의 difficulty, 즉 두 detector 간의 loss difference와 관련되기를 기대한다.
분명히, Eq.(13)의 gradient는 이러한 기대를 가능하게 한다.
우리는 only one dynamic detector로 variable-speed inference를 달성하기 위해 difficulty score thresholds를 결정하는 간단하고 효과적인 방법을 제안한다.
구체적으로, 우리의adaptive router는 difficulty score를 예측하고, inference 중에 특정 threshold을 기준으로 어떤 detector를 사용할지 결정한다.
따라서, 우리는 다양한 thresholds를 설정하여 서로 다른 accuracy-speed trade-offs를 달성할 수 있다.
먼저,
우리는 validation set의 difficulty scores 을 계산한다.
그리고 나서, 실제 필요(e.g. target latency)에 따라 router의 threshold를 설정할 수 있다.
예를 들어,
first detector의 latency를 ,
cascaded two detectors의 latency를 ,
target latency를 라고 하면,
우리는 "hard" image의 maximum allowable proportion(최대 허용 비율) 를 다음과 같이 계산할 수 있다.그리고 threshold 은 다음과 같이 된다.여기서 은 -번째 quantile(백분위수)를 계산함을 의미한다.
주목할 점은, 이 threshold 는 validation set과 test set에 모두 robust하다는 것이다.
이는 두 set가 independent and identically distributed(독립적이고 동일한 분포 i.e., i.i.d)를 따르기 때문이다.
위의 전략을 기반으로, 하나의 dynamic detector는 single detector에서 double detector로의 accuracy-speed trade-offs를 직접적으로 다룰 수 있으며,
이는 다양한 HW constraints 하에서 여러 detector를 redesigning하고 training하는 것을 피할 수 있게 한다.
우리는 COCO benchmark에 대해서 실험했다.
모든 models은 118k training images, and tested on the 5k minival images and 20k test-dev images를 사용하여 test했다.
우리는 YOLOv7 series model을 real-time detector baseline으로 선택했으며,
Faster R-CNN과 Mask R-CNN을 two-stage detector baselines으로 사용했다.
모든 dynamic detector들은 해당 baseline model들과 same hyper-parameters로 train되어졌다.
각 dynamic detector의 easy-hard proportion을 간략하게 나타내기 위해,
예를 들어 "Dy-YOLOv7-X/10"은 dynamic YOLOv7-X model에서 10%의 image가 "hard" image로 분류되고 나머지 90%는 "easy" image로 분류됨을 의미한다.