Loss Rank Mining: A General Hard Example Mining Method for Real-time Detectors
Modern object detectors usually suffer from low accuracy issues, as foregrounds always drown in tons of backgrounds and become hard examples during training. Compared with those proposal-based ones, real-time detectors are in far more serious trouble since they renounce the use of region-proposing stage which is used to filter a majority of backgrounds for achieving real-time rates. Though foregrounds as hard examples are in urgent need of being mined from tons of backgrounds, a considerable number of state-of-the-art real-time detectors, like YOLO series, have yet to profit from existing hard example mining methods, as using these methods need detectors fit series of prerequisites. In this paper, we propose a general hard example mining method named Loss Rank Mining (LRM) to fill the gap. LRM is a general method for real-time detectors, as it utilizes the final feature map which exists in all real-time detectors to mine hard examples. By using LRM, some elements representing easy examples in final feature map are filtered and detectors are forced to concentrate on hard examples during training. Extensive experiments validate the effectiveness of our method. With our method, the improvements of YOLOv2 detector on auto-driving related dataset KITTI and more general dataset PASCAL VOC are over 5% and 2% mAP, respectively. In addition, LRM is the first hard example mining strategy which could fit YOLOv2 perfectly and make it better applied in series of real scenarios where both real-time rates and accurate detection are strongly demanded.
The huge imbalance between backgrounds and foregrounds is native to the realm of object detection since millions of regions can be sampled from an image, but only a few are considered as foregrounds. The imbalance issue has exerted tons of side-effects throughout the development of object detectors, as detectors tend to be dominated by backgrounds and fail to detect objects. Previous work[girshick2014rich, girshick2015fast, ren2015faster, dai2016r, he2017mask] adopted the region-proposing stage to mitigate that imbalance. Region-proposing stage proposes Regions-of-Interest(RoIs) which are more likely to contain objects to narrow the sampling spaces of subsequent detection. However, as that stage proposes thousands of RoIs for each image and only a minority of them are foregrounds, backgrounds still overnumber foregrounds by tens or hundreds to one. To tackle that problem, in some proposal-based detectors[girshick2014rich, girshick2015fast, ren2015faster], sampling strategies were adopted after RoIs being proposed for further balance. Take [girshick2015fast] for instance, after RoIs being proposed for an input image, 16 foregrounds and 48 backgrounds are sampled randomly from all RoIs and only these 64 RoIs are used for training. The pipeline of Fast-RCNN detector in [girshick2015fast] is illustrated in Fig. 1.
Apparently, the sampling strategy mentioned above has a severe shortage. It samples RoIs randomly but in each iteration, different RoIs make diverse contributions to the model and RoIs that contribute most are not always selected by the sampler. To solve this, Shrivastave et al. proposed Online Hard Example Mining(OHEM) to measure contributions of each RoI and sample most beneficial ones for training in each iteration. More specifically, OHEM can be split into three stages. Firstly, all the RoIs proposed by region-proposing stage are used to propagate forward without further sampling, and loss values are calculated for all of them. Then, all the RoIs are ranked in loss-descent order and only a fixed number of RoIs with high loss values are selected. Finally, RoI pooling layer constructs feature vectors for selected RoIs and those feature vectors used for training. OHEM boosts detection accuracy significantly, as it samples RoIs where the model performs worst for training and they tend to provide essential information to the model. Additionally, OHEM as a sampling strategy contributes to mitigating the imbalance between backgrounds and foregrounds significantly since foregrounds as minority incline to possess high loss values and are more likely to be selected by OHEM.
However, for real-time detectors that regress straightly to final predictions without using RoIs, OHEM as a sampling strategy itself serves no purpose. The general pipeline of real-time detectors are shown in Fig. 2. It is clear in Fig. 2 that no RoI is sampled when using real-time detectors to detect objects, as a result of which, RoI-free hard example mining strategies need to be proposed for alleviating the huge imbalance between backgrounds and foregrounds. Liu et al. utilized hard example mining strategies in[liu2016ssd] to select hard negative examples during training and make the ratio of foregrounds to backgrounds 1:3 compulsively. To some extent, this strategy alleviates the imbalance between foregrounds and backgrounds as backgrounds are down-sampled during training. However, all foregrounds are considered as hard examples in [liu2016ssd] and relationships between foregrounds and negatives are totally neglected. To mine foregrounds for real-time detectors more effectively, Lin et al. proposed Focal Loss[lin2017focal] method. Focal Loss modifies the loss function to increase the gradients produced by hard examples and decrease that calculated for easy ones at the same time. In this way, it boosts the accuracy of real-time detectors significantly. However, Focal Loss is not a general method for real-time detectors as it heavily depends on the definition of loss function. For instance, Focal Loss can be used to boost the detection accuracy of SSD[liu2016ssd] but it cannot be applied to YOLOv2[redmon2016yolo9000] which adopts a totally different loss function. Accordingly, the fact is that for YOLOv2 detector which is broadly used for real-time detection in many real scenarios, no existing hard example mining strategy could fit it well and help to boost its detection accuracy.
In this paper, to tackle existing problems that we have mentioned above, we propose the Loss Rank Mining(LRM) method to mine foregrounds effectively for real-time detectors. To the best of our knowledge, LRM method is the first general hard example mining method which could be applied to all state-of-the-art real-time detectors. For YOLOv2 detector which performs well on many real scenarios but have yet to be optimized by existing hard example strategies, our LRM method could help to boost its detection accuracy. Compared with [lin2017focal], we modify the final feature map which is a general structure used in all real-time detectors to represent predictions rather than adjusting loss functions which can be defined diversely in various real-time detectors. The principle of LRM is that output elements representing predictions with low loss values are filtered before backpropagation, and only predictions with high loss values contribute to training the detectors. To sum up, the contributions of our LRM method can be concluded as follows:
LRM is the first general hard example mining method which could be applied to all state-of-the-art real-time detectors for higher detection accuracy, without any side-effects on real-time detection rates.
LRM successfully boosts detection accuracy of YOLOv2 detector which has been broadly adopted in many real-time detection scenarios but yet to be optimized by existing hard example mining methods.
Ii Related Work
Ii-a Traditional Hard Example Mining Techniques
Many kinds of hard example mining techniques have been widely applied to training classic models[suykens1999least, dollar2009integral].
Boosted decision tree in [dollar2009integral] is trained with hard example mining strategy but hard examples are mined one time only. To begin with, all the positive examples and a random set of negative examples are blended together as the original training set. After reaching convergence on the original training set, the trained model is applied to the rest of negative examples. Then, only false positive examples are selected as hard ones and added to the original training set to form the final training set. Finally, the model is trained on the refreshed training set until convergence.
Another hard exampling mining technique named boostrapping is used to train Support Vector Machines(SVMs)[suykens1999least] and hard examples are mined several times in this case. A working set containing a tiny number of samples is used in boostrapping. Samples are added to and removed from this set according to some specific rules. Processes of training model to convergence on the existing working set and utilizing the trained model to modify the working set are finished alternatively. When modifying the working set, samples in the working set classified correctly by the existing model are removed from it while samples out of the working set misclassified by the model are added to it.
Ii-B Hard Example Mining in Early Object Detectors
The history of utilizing techniques of hard example mining in object detection can date back to the time when it was used to train SVMs for pedestrian detection[dalal2005histograms]. After the prevalence of CNN-based model in object detection, hard example mining still played an important role as an SVM classifier is usually attached to the top of detectors for classification, e.g.[girshick2014rich, he2014spatial].
However, after SVMs being replaced by layers consisting of neural units in subsequent object detection methods[girshick2015fast, ren2015faster], hard example mining strategies were not utilized in the training of CNN-based detectors until Online Hard Example Mining(OHEM) proposed in [shrivastava2016training]. OHEM depends on the RoIs proposed by the region-proposing stage heavily but that stage is removed in state-of-the-art real-time detectors for higher speed, which makes OHEM serve no purpose on those detectors.
Ii-C Focal Loss for Real-time Detectors
To tackle severe imbalance issues between backgrounds and foregrounds in real-time detectors, Lin et al. proposed Focal Loss[lin2017focal] and tried to modify the loss function to mine the hard examples from easy ones. However, Focal Loss depends on the definition of loss function heavily and cannot be applied to plenty of state-of-the-art real-time detectors straightly.
More specifically, Focal Loss needs the whole loss function or a specific part of it to be calculated for both foregrounds and backgrounds. The shared part of the loss function is multiplied with a self-adaptive parameter to emphasize foregrounds and de-emphasize backgrounds. In cases where the unshared part dominates the whole loss function or both sides share no part, Focal Loss is less effective or even serves no purpose.
Two multi-task loss functions broadly adopted in object detection are illustrated in Fig.3. Loss1 consists of two tasks, namely, classification loss and box regression loss. Classification loss in Loss1 is calculated for both foregrounds and backgrounds, but box regression loss is computed for foregrounds only. Though classification loss is the majority of Loss1 and Focal Loss can be applied to it, the impacts produced by box regression loss are totally neglected. Additionally, for the methods in [redmon2016you, redmon2016yolo9000] which adopt Loss2 as their loss functions, Focal Loss serves no purpose. This is mainly because Loss2 possesses four subtasks, namely, object loss, non-object loss, classification loss and box regression loss, but all of them cannot be shared by both foregrounds and backgrounds. Though replacing Loss2 with Loss1 makes Focal Loss available for those detectors, it does harm to detection accuracy significantly, as Loss2 fit those detectors better. Our experiments in Section IV-E demonstrate that for those detectors, applying Focal Loss compulsively is detrimental but using Loss Rank Mining is helpful.
In this section, we aim at detailing the LRM method that we propose to improve detection accuracy of real-time detectors. To begin with, Section III-A details the pipeline of our LRM method. Then, we introduce how to use LRM in training and inference in Section III-B.
Iii-a Loss Rank Mining Method for Real-time Detectors
For constructing a general hard example mining method for real-time detectors, common grounds shared by all the existing state-of-the-art real-time detectors must be utilized. More specifically, common points of real-time detectors can be concluded into 2 aspects. Firstly, all of them abandon the use of region-proposing stage. The computation of all potential region proposals is blended as well as implicit. No region proposal is split from whole images before final predictions being made. Secondly, for one input image, tons of predictions are made by real-time detectors in one go, and final feature map(or a group of final feature maps[lin2016feature]) is used to represent all the predicted bounding-boxes. According to the aforementioned two points, a general hard example mining method for real-time detectors must be a RoI-free one and the final feature map as a general structure should be used to filter easy examples. Accordingly, our strategy is filtering some output elements which represent well-detected bounding-boxes in final feature map for the purpose of concentrating on hard examples.
The pipeline of Loss Rank Mining method can be concluded as followsï¼ (a). For an input image, use a backbone network to extract its representative features and forward them to detection phase, and then, obtain final feature map which represents all the final predictions; (b). Reorganize and group output elements in the final feature map according to which predictions that they represent; (c). Calculate loss values for each prediction, and rank them in a loss-descent order;(d). Select top-K predictions with highest loss values and filter all the output elements that represent outer predictions. (e). Do backpropagation without gradients of those output elements which has been filtered. Details are shown in Fig. 4. Moreover, non-maximum suppression(NMS)[girshick2015fast] is used after all predictions being ranked, as co-located predictions with high Intersection-over-Union(IoU) serve similar functions during backpropagation and selecting them as hard examples for multiple times is meaningless.
|Tiny Darknet||6.97 Bn||57.1|
Iii-B Training and Inference with LRM Method
Like previous hard example mining strategies, Loss Rank Mining method is also a technique used in training phase only. In training phase, we add a LRM module after the final feature map. In LRM module, detectors’ final feature map F are multiplied by a mask matrix M of same size in an elementwise way. The mask matrix is a binary one whose values depends on whether the corresponding elements in F belong to a hard example. The operation in LRM module can be illustrated by the following equation:
where is the output of LRM module and is the symbol of elementwise product.
The values of mask matrix M are not fixed but they do not need to be learned by the model. As we have mentioned in Section III-A, these values are decided by final predictions. At the beginning of each iteration, all the elements in M are set to 0 and after F being calculated, for output elements belonging to hard examples, the corresponding elements in M are set to 1. Then calculation of is finished for backpropagation. By using for backpropagation, the partial derivative of with respect to any element in F can be calculated as follows:
where represents an element in F whose position is (i, j) and channel is c. is the corresponding element in M. It is shown clearly that by adopting the mask matrix M, output elements belonging to easy examples are prevented from backpropagation successfully.
LRM method is only used in the training phase to make the model concentrate on hard examples and adjust the direction of gradient descent to reach a better solution. For utilizing the trained model to detect objects, the LRM module is removed and the original architecture is adopted. Accordingly, adopting LRM method does not introduce any additional time consumption in the inference phase, which could boost the detection accuracy while maintaining the real-time rates.
Iv-a Experimental Setup
All the experiments are implemented on lightweight deep learning framework Darknet[redmon2013darknet] and run on several K40 GPUs. We only utilize single GPU to train a single model rather than adopting muti-GPU training strategies.
Two datasets are utilized to validate the effectiveness of our model, namely, KITTI[geiger2013vision] and PASCAL VOC[everingham2010pascal]. KITTI dataset consists of tons of objects related to the driving scenario, such as pedestrians, cars, cyclists and so forth. We set experiments on it to show that some real-time applications, like auto-driving, can profit a lot from our LRM method. Compared with KITTI, PASCAL VOC is a larger datasets and it includes objects belonging to 20 classes. It is a more general dataset and it was used to prove that LRM can improve the accuracy of real-time detectors in some more complicated scenarios.
In details, 6 classes in KITTI dataset are used in our experiments, say, car, truck, tram, van, pedestrian and cyclist. Training set and testing set are separated randomly by a ratio of 9:1. For training on PASVAL VOC, the combination of VOC2007 trainval and VOC2012 trainval are used as the training set, and VOC2007 test is used to evaluate the performance of our LRM method. All the experiments use models pre-trained on 1K-ImageNet[deng2009imagenet] and detectors are trained 45K iterations on PASCAL VOC. The resolution of input images is set to 416*416 and batch size is set to 64.
We use 2 hyperparameters to adjust our models and 10 models are constructed on each dataset, including the original detector which serves as the baseline. The first hyperparameter is the number of hard examples. This hyperparameter represents the number of predictions remained for backpropagation. The other hyperparameter is the NMS threshold, which is the limitation we put on the final predictions. The NMS method is used to remove some redundant informations. More specifically, when the IoU(Intersection-over-Union) of two predictions belonging to same classes is equal or lager than the threshold, only the one with higher loss values should be remained. When use smaller NMS threshold, stricter limitation is introduced and more redundant informations are removed.
Iv-B Model Selection
In our experiments, we adopt the YOLOv2 detector and apply LRM to it to obtain higher accuracy. Reasons why we choose this detector are various. Firstly, YOLOv2 is an excellent and prevalent real-time object detector which achieves mAP of 76.8% on PASCAL VOC with FPS of 67.[redmon2016yolo9000] Moreover, like other state-of-the-art real-time detectors, YOLOv2 faces the huge imbalance between backgrounds and foregrounds, but the aforementioned hard example mining methods including OHEM and Focal Loss serve no purpose on it as YOLOv2 removes region-proposing stage and adopt Loss2 in Fig. 3 as its loss function. Thus, using LRM to improve the accuracy of YOLOv2 detector is of great significance and all the experiments are based on a YOLOv2 detector.
For using YOLOv2 detector, a suitable backbone network must be chosen. The original version of YOLOv2[redmon2016yolo9000] adopt Darknet as it backbone network, and another implementation of YOLOv2 use a shallower Darnet named Tiny Darknet as its backbone network to decrease the amount of computation and obtain higher detection rates. Moreover, in the recent literature, a considerable number of efforts have been made in building compact neural networks to obtain higher inference speed e.g.[wang2016factorized, iandola2016squeezenet, wu2016quantized, howard2017mobilenets, zhang2017shufflenet]. As these compact networks have achieved great success in the field of image classification, we also adopt a representative one named MobileNet[howard2017mobilenets] as one of the candidate backbone networks. We use these aforementioned backbone networks to construct three YOLOv2 detectors and corresponding comparisons are illustrated in TABLE I. In TABLE I, the second column is Flops which represents the amount of computation of detectors and the third column is mAP which represents the detection accuracy on PASCAL VOC dataset.
It is clearly illustrated in TABLE I that MobileNet-based YOLOv2 detector uses least amount of computation(2.56 billion Flops) but still achieves competitive mAP(67.5%). It is no doubt that compared with the other two backbone networks, MobileNet is a more suitable one for constructing accurate and fast YOLOv2 detector. Thus, a MobileNet-based YOLOv2 detector is used as the baseline in our experiments.
Iv-C Results on KITTI
This part of experiments is used to validate the effectiveness of LRM method on auto-driving scenario. We set series of experiments on auto-driving related KITTI dataset to prove that LRM method could optimize MobileNet-based YOLOv2 detector and make it more accurate to detecting auto-driving related objects, such as persons, cars, bikes and so forth. The results are illustrated in TABLE II.
In this part of experiments, we test 9 MobileNet-based YOLOv2 detectors. All of them are optimized by LRM method but with different hyperparameters. Besides, a MobileNet-based YOLOv2 detector without any additional optimization is used as the baseline. Totally, we construct 10 diverse MobileNet-based YOLOv2 detectors to test the performance of our LRM method. When setting the number of hard examples to 128 and the NMS threshold to 0.7, LRM method achieves the highest mAP on KITTI dataset, which is 57.30%. Compared with the baseline whose mAP is 51.98%, LRM method gains a significant improvement of over 5% mAP.
More specifically, among all classes, the most significant improvements is achieved on class tram(82.16% vs. 67.55%, over 14% improvements compared with baseline). To achieve this, the number of hard examples is set to 128 and NMS threshold is set to 0.5. But referring to the class truck, the improvement is not so optimistic, even some models’ AP on class truck drops moderately. So, we can say that for different classes of data, the effectiveness of our LRM method is diverse.
We draw Fig. 5 to illustrate the impacts brought by different hyperparameters more clearly. Referring to the number of hard examples, our LRM method achieves the highest mAP when setting the number of hard examples to 128 regardless of what NMS threshold we adopt. When we set the number of hard examples to 64, setting NMS threshold to 0.5 is the best choice. This is mainly because when we only remain a small part of predictions, we should select most beneficial predictions first. However, compared with redundant predictions with higher loss values, these predictions may possesses lower loss values and not be remained. In this case, a smaller NMS threshold should be used to remove those redundant predictions and ensure that most beneficial ones are remained. But cases become totally different when increasing that number to 128 or 256. Setting NMS threshold to 0.7 achieves the highest mAP in those cases. Because when the number of hard examples grows, we still have many seats after choosing all most beneficial predictions. Some predictions with little redundancy should be remained in this case, as they still can provide some useful informations. Accordingly, a milder NMS threshold should be adopted, for remaining the moderately redundant predictions while removing those heavily redundant ones.
|Detector||Backbone||Loss Function||FL Method||LRM Method||Dataset||mAP||Improvements|
|YOLOv2||Darknet||Loss2 in Fig. 3||%||%||PASCAL VOC||75.13||-|
|Loss1 in Fig. 3||%||%||73.05||-2.08|
|Loss1 in Fig. 3||!||%||74.08||-1.05|
|Loss2 in Fig. 3||%||!||77.40||+2.27|
Iv-D Results on PASCAL VOC
In this part, we train MobileNet-based YOLOv2 detectors on a more general and complex dataset named PASCAL VOC which includes 20 classes of objects to validate the robustness of our LRM method. Experiment results demonstrate that LRM method improves detection accuracy of YOLOv2 detector significantly. Table. II shows all the details of this experiment and illustrates that all kinds of LRM-optimized YOLOv2 detectors outperform the original YOLOv2 detector. Improvements on PASCAL VOC demonstrate that LRM could help to construct more accurate real-time detectors in a wide range of real scenarios successfully, such as pedestrian detection, traffic monitoring and so forth.
Totally, we construct 9 LRM-optimized YOLOv2 detectors with different hyperparameters on PASCAL VOC. Additionally, a MobileNet-based YOLOv2 detector without any additional optimization is used as the baseline. When setting the number of hard examples to 256 and the NMS threshold to 0.7, LRM method achieves the highest mAP(70.15%) on PASCAL VOC dataset. Compared with the baseline whose mAP is 68.00%, LRM method gains a significant improvements of over 2% mAP.
More specifically, improvements that LRM brought to different classes are diverse. For some classes like bike, bottle and bus, the improvements are significant, achieving over 4% mAP. But the case is opposite in a minority of classes, among which the typical ones are class cat and dog. For class cat, after applying LRM, detection accuracy of YOLOv2 drops moderately. However, for class, dog, detection accuracy drops significantly, achieving around 3% mAP.
We utilize Fig. 6 to illustrate the impacts brought by different hyperparameters on dataset PASCAL VOC. When setting the NMS threshold to 0.5 or 1.0(equals to no nms in Fig. 6), choosing 128 predictions for backpropagation achieves the best performance. But the case is totally different when the NMS threshold is set to 0.7. In this case, choosing 128 predictions perform worst(69.51% mAP), but choosing 256 predictions achieves the highest mAP at 70.15%. This is mainly because compared with NMS 0.5 and 1.0, setting NMS threshold to 0.7 is a milder strategy which remains a part of redundant informations. In this case, predictions ranked to possess a majority of redundant informations which does harm to the model. But when enlarge the number of hard examples to 256, more predictions containing beneficial informations are chosen and detection accuracy of the model increases significantly.
Iv-E Comparisons between Loss Rank Mining and Focal Loss
In this part, we use Focal Loss method and our Loss Rank Mining method to optimize two YOLOv2 detectors, respectively. For clearer comparisons, darknet[redmon2016you] rather than MobileNet[howard2017mobilenets] is chosen as the backbone network. To make it possible for Focal Loss(FL) method to be applied to YOLOv2 detector, the original loss function defined as Loss2 in Fig. 3 is replaced by Loss1 in Fig. 3 in this part of experiments.
Results are illustrated in Table. IV. Some details like hyperparamaters are not shown in this table. When Loss2 is replaced with Loss1, mAP drops with 2.08%. Though after using FL method on this model, mAP increases with 1.03%, mAP still drops with 1.05% compared with the original YOLOv2 detector using Loss2(in Fig. 3) as its loss function. Compared with FL method, our Loss Rank Mining method could be applied to the original detector straightly and improve the detection accuracy significantly. Compared with the original YOLOv2 detector, the improvements are 2.27%(77.40% vs. 75.13% mAP).
Though using Focal Loss method on YOLOv2 detector is possible, the prerequisite of changing the original loss function to another one does harm to detection accuracy. Even after applying Focal Loss to YOLOv2, the performance is still worse than the original one(74.05% vs. 75.13% mAP). Differently, our Loss Rank Mining can be applied to YOLOv2 detector straightly without any modification in loss function. More importantly, after using LRM method, YOLOv2 detector gains over 2% mAP improvements on PASCAL VOC, compared the original one(77.40% vs. 75.13% mAP).
The reason why Loss Rank Mining method could mine foregrounds from tons of backgrounds can be explained as follows. When training real-time object detectors, the model incline to be partial to backgrounds and perform well on them. The corresponding result is that few foregrounds can be detected correctly, which is opposite the target of constructing object detectors. LRM method utilizes the fact that foregrounds tend to become hard examples. It ignores some well-predicted bounding-boxes in each iteration and make foregrounds dominate the process of gradient descent. Accordingly, LRM method emphasizes foregrounds successfully and helps to correct the deviation caused by huge imbalance between backgrounds and foregrounds.
In this work, to begin with, we point out the strong demand and great importance of utilizing hard example mining strategies in real-time detectors. Then, to tackle the shortage of general hard example mining methods for real-time detectors, we propose the Loss Rank Mining method. Our method is a general one which does not rely on additional region proposals or specific loss functions, and it can be straightly used in state-of-the-art real-time detectors to boost their detection accuracy significantly. For demonstrating the effectiveness of LRM method, series of solid experiments are set. Results illustrate that no matter on auto-driving related dataset KITTI or more general dataset PASCAL VOC, LRM method boosts accuracy of real-time detectors significantly. In addition, broadly-used YOLOv2 detector which has yet to be optimized by previous hard example mining method could benefit from our method. However, we have noticed two shortcomings of our LRM method. One is that the fixed number of hard examples is unsuitable, and our future work will concentrate on making this hyperparameter self-adaptive. The other one is that filtering easy examples straightly may lose some valuable information. We will try to alleviate the impacts of easy examples instead of neglecting them in our future work.