# DGANet: Dynamic Gradient Adjustment Anchor-Free Object Detection in Optical Remote Sensing Images
## 3 Proposed Approach
### Dynamic Gradient Adjustment for Classification Function  
This region is focused on classification in anchor-free object detection where the class (foreground and background) of images, as well as easy and hard examples, are quite imbalanced. Concerning this issue, we propose a dynamic refinement mechanism to inhibit these two disharmonies based on updated Focal Loss and GHM. Both of them originate from the multi-classification cross entropy loss:  
\[L_{CE}(p,p^{*})=\left\{\begin{array}{ccc}-\log(p)&if&p^{*}=1\\ -\log(1-p)&if&p^{*}=0\end{array}\right. \tag{1}\]  
In Equation (1), \(p^{*}\in\{0,1\}\) denotes the ground-truth label for a certain class and \(p\in[0,1]\) is the probability predicted by the detector.  
Experiments show that the large class imbalance, as well as disharmony between easy and hard examples, limits the improvement of detector performance. We propose the dynamic gradient adjustment focal loss to settle the problem:  
\[L_{DGA}(p)=\frac{1}{N}{\sum}\left\{\begin{array}{ccc}\frac{-\gamma(1-p)^{ \alpha}\log(p)}{GD(\beta)}&if&p^{*}=1\\ \frac{-(1-\gamma)(1-p^{*})^{\alpha}p^{\alpha}\log(1-p)}{GD(\beta)}&if&p^{*} \
eq 1\end{array}\right. \tag{2}\]  
The input image \(I\) is defined as \(I\in R^{W\times H\times 3}\) with width \(W\) and height \(H\). The detector extracts the targets as points, and then maps all ground truth keypoints onto a heatmap \(Y\in[0,1]^{\frac{W}{\gamma}\times\frac{H}{\gamma}\times C}\). \(C\) indicates the number of classes, while \(\eta\) is the down-sampling factor of the network. The heatmap \(Y\) is expected to be equal to 1 at target centers and adjacent positions are decreasing in order. The values on the heatmap are not less than 0. Refering to the practice of CornerNet [32] and CenterNet [36], the ground truth center points of targets are mapped using a 2D Gaussian kernel \(p^{*}=\exp[-\frac{(x-\widetilde{p}_{x})^{2}+(x-\widetilde{p}_{y})^{2}}{2 \widetilde{p}_{y}^{2}}]\), where \(\widetilde{p}_{x}\) and \(\widetilde{p}_{y}\) are the target center points after down-sampled, while \(\sigma_{p}\) is a standard deviation which changes with the size of the object. In Equation (2), \(\gamma\) is used to harmonize positive and negative examples, while \(\alpha\) and \(\beta\) are hyper parameters of the updated Focal Loss, respectively. \(N\) is the number of center-points in an image, and it is applied to normalize all positive focal losses instance to 1.  
Meanwhile, \(GD(g)\) in Equation (2) is introduced to dynamically refine the loss function by reducing weight of easy examples and hard examples. GHM adds the \(GD(g)\) in Equation (1) to improve the performance of one-stage detectors. Gradient density \(GD(g)\) and gradient norm \(g\) are defined as follows:  
\[GD(g)=\frac{1}{l_{e}(g)}{\sum_{k=1}^{N}\delta_{e}(g_{k},g)} \tag{3}\]  
Figure 3: Illustrations of the DLA34 backbone network. The deformable convolutional layer is used for up sample instead of common inverse convolution in deep layer aggregation.  
\[g=|p-p^{*}|=\left\{\begin{array}{ccc}1-p&if&p^{*}=1\\ p&if&p^{*}\
eq 1\end{array}\right. \tag{4}\]  
In Equation (3), \(g_{k}\) is the gradient norm of the \(k\)-th example, and \(\delta_{e}(g_{k},g)\) is a function indicating whether \(g_{k}\) is located in the interval centered at \(g\) with a valid length \(l_{e}(g)=\min(g+\frac{1}{2}\epsilon,1)-\max(g-\frac{1}{2}\epsilon,0)\).  
Thus, gradient density \(GD(g)\) represents the ratio of examples in the specific interval to all examples. It is a dynamically varying value determined by predictions. \(GD(g)\) is used to down-weights the contribution of outliers as well as easy examples.