Searching Parameterized AP Loss for Object Detection

1 Introduction . The past decade has witnessed the significant success of deep neural networks in object detection , in which loss functions play an indispensable role in training networks . To evaluate the object detection methods , the Average Precision ( AP ) metric is usually used , which captures the performance of localization and classification simultaneously . However , as in most object detectors [ 26 ] , the training of localization and classification sub-tasks are driven by two separate losses ( see Figure 1 ) . For example , the L1/smooth-L1 [ 11 ] or GIoU [ 38 ] losses are usually employed for localization , while the cross-entropy or Focal [ 25 ] losses are usually used for classification . Such a mis-alignment between network training and evaluation may well lead to performance degradation . To mitigate this mis-alignment issue , a straight-forward solution is to approximate the AP metric in network training . Because the AP metric is non-differentiable , many works [ 3 , 5 , 13 , 40 , 35 ] have explored hand-crafted losses based on the mathematical formula of the AP metric . [ 3 ] replaces the non-differentiable parts in the AP metric with hand-crafted differentiable approximations . The loss gradient is obtained by taking derivation with respect to the hand-crafted function . However , as both [ 5 ] and our experiments show , such a hand-crafted AP approximated loss produces lower ∗Equal contribution . †This work is done when Chenxin Tao and Zizhang Li are interns at SenseTime Research . ‡Corresponding author . 35th Conference on Neural Information Processing Systems ( NeurIPS 2021 ) . performance than the commonly used cross-entropy and L1/smooth-L1 losses . Another line of works try to estimate the gradient for the AP metric directly [ 5 , 13 , 40 , 35 ] . These works try to manually design the loss gradient . Therein , the AP approximated gradient only drives the training of the classification branch , while the training of the localization branch is still supervised by traditional regression losses . In practice , these methods still do not address the mis-alignment issue well . The common issue of existing approaches is they do not optimize over the numerous approximations of the non-differentiable discrete AP metric . The AP metric itself is a piecewise constant function , whose differentiable approximations have infinite possibilities . The hand-crafted approximations / gradients may well be sub-optimal for driving network training . Instead of manually determining the surrogate loss form , we propose to approximate the non-differentiable parts with a family of continuous parameterized functions , which helps to represent the numerous AP approximations in a unified formula . Then , an efficient parameter search procedure is employed to find out the desired loss function , so as to optimize the trained object detector ’ s performance on the evaluation set with the AP metric . Because the parameterized AP approximations constitute a compact search space , the search process would be very effective . To this end , we propose the Parameterized AP Loss , which is built on top of the AP metric to mitigate the mis-alignment between network training and evaluation . It utilizes parameterization to construct the search space so that the optimal parameters can be searched automatically . Specifically , we first explicitly reformulate the AP metric for object detection as a function of classification scores and box coordinates . Then we replace the non-differentiable components in the reformulated function with parameterized functions . Finally , to obtain the optimal loss function for network training , we search the parameters through a reinforcement-learning-based search process , which aims to maximize the AP score on the evaluation set . We evaluate the searched Parameterized AP Loss on various object detectors , including RetinaNet [ 25 ] , Faster R-CNN [ 37 ] and Deformable DETR [ 42 ] . Extensive experiments on the COCO benchmark [ 23 ] demonstrate that the proposed Parameterized AP Loss consistently outperforms existing delicately designed losses . The main contributions of our work can be summarized as : • By reformulating the AP metric and introducing differentiable parameterized substitutions , Parameterized AP Loss can represent numerous AP approximations in a unified formula , which captures classification and localization sub-tasks simultaneously in a single loss function . • Instead of hand-crafting AP losses or gradient approximations , our approach automatically searches for the optimal parameter , optimizing for the trained object detector performance . • Extensive experiments on different object detectors demonstrate that the searched Parameterized AP Loss consistently outperforms the existing losses . 2 Related work . Hand-crafted Loss Functions for Object Detection . Designing loss functions has been an active direction in the field of object detection for long . Cross-entropy and smooth-L1 losses are widely used for the classification and localization sub-tasks , respectively [ 26 ] . For the classification subtask , to mitigate the imbalance problem in one-stage detectors , Focal Loss [ 25 ] and GHM [ 17 ] propose to adjust the weight of loss or gradient for each predicted box . DR Loss [ 34 ] proposes to convert the classification problem into a ranking problem . For the localization sub-task , a series of works [ 38 , 41 ] introduce IoU variants for better localization . GFL [ 22 ] and GFLv2 [ 21 ] point out that the classification and localization branches are separately trained but compositely used in inference , so they merge the localization representation into the classification branch for a joint optimization . But such combination is still not consistent with the AP metric . Recent works [ 5 , 30 ] have noticed the mis-alignment issue between network training and evaluation , and try to address it with specifically designed surrogate loss functions . AP Loss [ 5 ] replaces the classification task with a ranking task derived from the AP metric via a hand-crafted errordriven gradient . aLRP Loss [ 30 ] extends the framework of AP Loss , and unifies classification and localization losses under the LRP metric [ 29 ] . These loss functions are all hand-crafted , and may well be sub-optimal in guiding network training . In contrast , our proposed Parameterized AP Loss is automatically searched , which can better align the network training and evaluation . Direct Optimization for the AP Metric . Pioneer works [ 13 , 40 , 35 ] have also tried to use the AP metric as training objective . Due to the non-differentiable nature of the AP metric , these works adopt different methods to estimate the back-propagated gradient . [ 13 ] uses finite difference and linear envelope to derive the pseudo-gradients . [ 40 ] applies the loss-augmented inference for the gradient estimation . [ 35 ] resorts to reinforcement learning for policy gradient . While these works take a step towards direct optimization for the AP metric , they all focus on the gradient for the classification task , ignoring the localization task , which may well be sub-optimal for the optimization of AP metric . By contrast , our proposed Parameterized AP Loss deals with these two tasks simultaneously in a single loss function , and thus better align training and evaluation processes . Another line of works try to approximate the AP metric via interpolation or neural network [ 27 , 32 , 8 ] . [ 27 ] refactors the computation process and interpolates the loss value with differentiable functions . [ 32 ] learns an embedding for prediction and target , so the Euclidean distance between them approximates the metric value . [ 8 ] trains a network for sorting operation , so as to construct a differentiable surrogate . Although these methods use differentiable functions to approximate AP metric , they ignore the training process . Our proposed Parameterized AP Loss , however , is searched to directly optimize the AP metric during evaluation , and thus consider the training behavior of loss function . This leads to a more effective loss function for network training . Searching Loss Functions for Object Detection . Recent works [ 28 , 19 ] have also tried to search suitable loss functions for object detection . In these methods , loss functions are formulated as computational graphs composed of basic mathematical operators . Since the combinations of operators are randomly chosen , the search space is very sparse with a large number of unpromising loss functions . Thus , they have to design specific techniques to accelerate the search process . [ 28 ] also relies on hand-crafted initialization . Nevertheless , their searched loss functions only gain marginal improvement on detection tasks . On the other hand , these methods search for separate losses for the localization and classification sub-tasks , thus the mis-alignment between network training and evaluation still exists . Our proposed Parameterized AP Loss constitutes a compact search space , where different loss functions are represented by different parameters . Since the parameterized search space is continuous , the search process would be more effective than the discrete combinatorial optimization in [ 28 , 19 ] . Moreover , Parameterized AP Loss drives the localization and classification training with a single unified loss , which better mitigates the mis-alignment issue . Hyper-Parameter Optimization . Previously , grid search or random search [ 1 ] are commonly used for hyper-parameter tuning . As the search space becomes more complex , many efficient hyperparameter optimization methods have been proposed . Bayesian optimization [ 2 , 14 ] aims to build a prediction model from history data and use it to select the most promising hyper-parameters for evaluation . Bandit-based methods [ 15 , 20 , 10 ] view it as a resource allocation problem and allocate most of the computational resource to the most promising hyper-parameters . Evolutionary algorithms [ 36 , 33 ] evolve the optimal hyper-parameters from a population of models . Reinforcement learning techniques [ 43 ] have also been used to explore the search space via sampling candidates and adjusting the sampling policy . The introduced parameters in our proposed Parameterized AP Loss are indeed hyper-parameters , which fit the hyper-parameter optimization methods . In this work , we adopt reinforcement learning to search for the optimal parameters because of its simplicity and efficiency . Other efficient hyperparameter optimization algorithms can also be employed . 3 Method . In this section , we present how Parameterized AP Loss is constructed to better align the training target with the evaluation metric . The overview of our method is illustrated in Figure 2 . 3.1 Revisiting AP Metric . AP metric is the most widely used evaluation metric for object detection . Given an image , we assume an object detector outputs N detected bounding boxes for each category as B = { ( bi , si ) } Ni=1 . Here , bi ∈ R4 denotes the box coordinates of the i-th prediction , and si ∈ R is its corresponding classification score . In the AP metric , these predictions will be matched with a set of ground-truth bounding boxes G. Each prediction will be assigned with zero or one ground-truth bounding box . Those predictions assigned to ground-truth bounding boxes constitute the positive set P , while other predictions form the negative set N . Then , the AP metric score is defined as the area under the precision-recall curve . Following the above notations , it can be written as AP = 1 |P| ∑ i∈P p ( i ) , ( 1 ) where p ( i ) denotes the precision of the predictions , whose classification scores are higher than that of the i-th prediction . Following [ 5 , 3 ] , Eq . ( 1 ) can be explicitly calculated as the function of classification scores AP ( { si } Ni=1 ) = 1 |P| ∑ i∈P 1− rank – ( si ) rank ( si ) = 1 |P| ∑ i∈P 1− ∑ j∈N H ( sj − si ) 1 + ∑ j∈B , j 6=iH ( sj − si ) , ( 2 ) where rank– ( si ) and rank ( si ) denote the ranks of the classification score si among the negative prediction set N and the whole prediction set B , respectively . H ( · ) is the Heaviside step function , H ( x ) = { 1 , if x > 0 , 0 , otherwise . ( 3 ) Eq . ( 2 ) explicitly includes the classification scores into the AP calculation , which helps previous works [ 5 , 3 ] to explore surrogate losses for the classification task . However , the localization task is also very important for object detection , which is just implicitly contained in Eq . ( 2 ) .

Summary: This paper proposes a Parameterized AP Loss to better align the network training and evaluation in object detection. The main technical contributions include: 1) It proposes a parameterized loss function by reformulating the AP metric and replacing the non-differentiable component with parameterized functions. 2) It automatically searches for the optimal parameters of the proposed loss function through a reinforcement-learning-based search process. 3) Finally, it demonstrates competitive results on COCO.