## 3 Method
### Gradient Density Loss Function  
In conventional classification tasks, the cross-entropy loss function is widely utilized. The equation for the binary cross-entropy loss function is expressed as follows:  
\[L_{\text{cross-entropy}}= \begin{cases}-log(p),&\text{if }T=1\\ -log(1-p),&\text{if }T=0\end{cases}  \tag{5}\]  
where \(T\in\{0,1\}\) signifies the true class label of the sample, and the corresponding probability is denoted as \(p\in[0,1]\). Next, let us denote \"\(out\)\" as the output of the model. In this scenario, we have \(p=\text{sigmoid}(out)\). Now, by differentiating the aforementioned cross-entropy loss function with respect to the model's output, we arrive at  
\[\frac{\partial L_{\text{cross-entropy}}}{\partial\text{out}}= \begin{cases}p-1,& \text{if }T=1\\ p,&\text{if }T=0\end{cases}  \tag{6}\]  
At this juncture, the magnitude of the gradient is defined as \"\(gradnorm\)\", which can be represented as  
\[gradnorm=|p-T|= \begin{cases}1-p,&\text{if }T=1\\ p,&\text{if }T=0\end{cases}  \tag{7}\]  
where the value of \"\(gradnorm\)\" indicates the level of difficulty posed by a sample and its impact on the overall gradient. To address the challenge stemming from uneven gradient distribution due to varying sample quantities, the concept of the \"gradient density loss function\" is  
In the equation, \(N\) represents the total number of samples. This parameter is used to weigh the cross-entropy loss classification function, resulting in a new gradient density loss function. This function is designed to reduce the weight of larger gradient density intervals, thereby diminishing the impact of challenging samples on the model. This adjustment helps mitigate the influence of difficult outliers on the final accuracy. For better comprehension, let us express the above equation in an alternative form:  
\[\beta_{i}=\frac{1}{GD(gradnorm_{i})/N} \tag{12}\]  
As can be discerned, \(GD(gradnorm_{i})/N\) signifies the proportion of sample gradients within the gradient partitioning interval concerning the total sample count. If the sample count within the gradient interval is uniformly distributed, then \(\beta_{i}=1\) for every interval, implying that the gradient density parameter in that interval would hold no sway over the result. Conversely, for demanding samples characterized by higher gradient densities and larger counts, this value would diminish. This characteristic serves to counterbalance the impact of a multitude of challenging samples on the model's precision. Hence, the substitution of the classification loss function focal loss [19] with the gradient density loss function in Sparse R-CNN can be mathematically expressed as follows:  
\[L_{gcls}=\frac{1}{N}\sum_{i=1}^{N}\beta_{i}L_{cross\ entropy}(p_{i},p_{i}^{ gt})=\sum_{i=1}^{N}\frac{L_{cross\ entropy}(p_{i},p_{i}^{gt})}{GD(gradnorm_{i})} \tag{13}\]  
In this equation, \(p_{i}^{gt}\) represents the actual classification label, \(p_{i}\) represents the predicted label, and \(GD(gradnorm_{i})\) represents the count of samples falling within the ith interval after dividing the gradient magnitudes into \(N\) intervals using the parameter \(N\). The term \(L_{cross\ entropy}(p_{i},p_{i}^{gt})\) denotes the cross-entropy classification loss function. Figure 3 displays the gradient magnitude distribution of a converged model. Along the horizontal axis, the gradient magnitude is depicted, with the right side representing more challenging samples and the left side representing simpler ones. The vertical axis, on a logarithmic scale, illustrates the corresponding number of samples at each gradient magnitude. The logarithmic scale is chosen due to the substantial variance in quantities between simple and moderately difficult samples in practical scenarios. The graph highlights that the largest number of samples falls into the simple category, while moderately difficult samples are fewer in number. Remarkably, the count of extremely challenging samples increases notably, surpassing even the quantity of moderately difficult ones by a substantial margin.