# Object Detection in Drone Imagery via Sample Balance Strategies and Local Feature Enhancement
## 3 Methods
### Adaptive Selection for Positive and Negative, and Easy and Hard Samples
Algorithm 1 is shown as below:  
```
1:\(G\) is a set of ground-truth boxes in the image
2:\(A\) is the set of all anchor boxes generated from FPN features levels
3:\(k\) is a hyper-parameter with a default value of 9
4:\(\delta\)1 is the parameter which limits the amount of easy-samples with a default value of 1
5:\(\delta\)2 is the parameter which limits the amount of hard-samples with a default value of 2
6:Output:\(EP\) is a set of easy-positive samples
7:\(EN\) is a set of easy-negative samples
8:\(HN\) is a set of hard-negative samples
9:for each ground-truth \(g\in G\)do
10:\(C\leftarrow\) select the \(k\) anchors from each level in \(A\), and \(c_{g}^{k}\in C\) that have the closest center are closet to the center of ground-truth \(g\)
11: compute the IoU between \(c_{g}^{k}\) and \(g\): \(d_{g}^{k}=loU(c_{g}^{k},g)\)
12: compute the mean of the top \(k\) anchors: \(m_{g}^{k}=\sum_{k}\frac{d_{g}^{k}}{k}\)
13: compute the standard deviation of the top \(k\) anchors: \(s_{g}^{k}=\sqrt{\frac{\sum_{k}(d_{g}^{k}-m_{g}^{k})}{k}}\)
14: compute the IoU of the upper threshold: \(t_{upper}^{k}=m_{g}^{k}+s_{g}^{k}\)
15: compute the IoU of the lower threshold: \(t_{lower}^{k}=m_{g}^{k}-s_{g}^{k}\)
16:endfor
17:for each candidate \(c_{g}\in C_{g}\)do
18:if\(IoU(c_{g}^{k},g)\geq t_{upper}^{k}\) and center of \(c\) in \(g\)then
19:\(EP=EP\cup c_{g}^{k}\)
20:endif
21:endfor
22:for each candidate \(c_{g}\in C_{g}\)do
23:if\(IoU(c_{g}^{k},g)\leq t_{lower}^{k}\)then
24:\(EN=EN\cup c_{g}^{k}\)
25:if\(count(EN)\geq\delta 1\times count(EP)\)then
26: break
27:endif
28:endfor
29:for each candidate \(c_{g}\in C_{g}\)do
30:if\(t_{lower}^{k}\leq IoU(c_{g}^{k},g)\leq m_{g}^{k}\)then
31:\(HN=HN\cup c_{g}^{k}\)
32:if\(count(HN)\geq\delta 2\times count(EP)\)then
33: break
34:endif
35:endif
36:endfor
37:return\(EP,EN\cup HN\)
```  
**Algorithm 1** Adaptive selection for positive and negative and easy and hard samples. We define \(G\) as a set of ground-truth boxes in the images. For each ground-truth \(g\), we select the \(k\) anchor boxes whose center are closest to the center of \(g\), based on L2 distance. As described in Lines 1 to 7, we compute the mean and standard deviation of the top \(k\) anchors, the IoU of the upper threshold as \(t^{k}_{upper}=m^{k}_{g}+s^{k}_{g}\), and the IoU of the lower threshold as \(t^{k}_{lower}=m^{k}_{g}-s^{k}_{g}\). Then, we select the positive samples sets and negative samples sets in from Line 8 to Line 21. When the value of the IoU is more above than the \(t^{k}_{upper}\), the quality of candidates will be high, and they are will be divided into easy-positive samples whose that have a supposedly high IoU threshold is supposed to be high. Besides, the amount of negative samples are limited to less than \((\delta 1+\delta 2)\) times the amount of positive samples. Thus, the candidates whose with an IoU below the \(t^{k}_{lower}\) are divided into the sets of easy-negative samples. Moreover, the candidates whose with an IoU is no more than the mean of the top \(k\) anchors and not less than \(t^{k}_{lower}\), will be divided into hard-negative samples.