## 3 Materials and Methods
### Loss Function  
#### 3.2.1 Detection Loss  
In the proposed framework, we optimized the original YOLOv5 loss function to better fit a small-sized object detection task. Additionally, an additional loss function for domain adaptation is proposed. The vanilla YOLOv5 model utilizes a detection loss comprised of 3 loss functions: class loss, objectness loss and box loss. The class loss measures cross-entropy to calculate difference between the predicted and ground-truth class label. The objectness loss is based on binary cross-entropy to measure the object presence and confidence of each bounding box candidate. The box loss is a measure of predicted bounding box precision, where the complete intersection over union (CIoU) concept is used. Intersection over union (IoU) is originally based on overlapping proportions of predicted and ground truth bounding boxes, which could not be calculated in non-overlapping cases. CIoU considers the ratio of horizontal and vertical length along with the distance between box central points to overcome this. It not only allows a model to increase the overlapping area of the ground truth and the predicted box but also helps to minimize their central point distance and box aspect ratio difference. However, as shown in Figure 2, the IoU-based metrics may not work well in small-sized object detection. As the location and shape of bounding boxes are defined on a pixel grid, the sensitivity of IoU is insufficient to track bounding box accuracy in small-sized objects. Therefore, we modify the box loss to better optimize a model to detect smaller objects by assuming the bounding boxes as 2D Gaussian distributions [46].  
For a bounding box \(R=\{c_{x},c_{y},w,h\}\) where \(c_{x},c_{y}\) are box center coordinates and \(w,h\) are the width and height of the bounding box, we assume the bounding box is a 2D Gaussian distribution where the center pixel has the highest value and the value decreases from the center to the boundary. Then, the inscribed ellipse of the box can be represented as  
\[\frac{(x-c_{x})^{2}}{(\frac{w_{x}}{2})^{2}}+\frac  
\[(z-\mu)^{\intercal}\Sigma^{-1}(z-\mu)=1, \tag{3}\]  
the represented ellipse is a density contour of the Gaussian distribution. This denotes that the bounding box \(R\) can be modeled into a 2D Gaussian distribution \(\mathcal{N}(\mu,\Sigma)\) by calculating the equation as  
\[\mu=\begin{bmatrix}c_{x}\\ c_{y}\end{bmatrix},\Sigma=\begin{bmatrix}(\frac{w_{x}^{2}}{4})&0\\ 0&(\frac{w_{y}^{2}}{4})\end{bmatrix}. \tag{4}\]  
To calculate the loss between two Gaussian distributions, we can use the second-order Wasserstein distance. The Wasserstein distance between \(\mu_{1}=\mathcal{N}_{1}(\mu_{1},\Sigma_{1})\) and \(\mu_{2}=\mathcal{N}_{2}(\mu_{2},\Sigma_{2})\) is defined as  
\[W_{2}^{2}(\mu_{1},\mu_{2})=\bigg{\|}([c_{1x},c_{1y},\frac{w_{1}}{2},\frac{h_{ 1}}{2}]^{\intercal},[c_{2x},c_{2y},\frac{w_{2}}{2},\frac{h_{2}}{2}]^{\intercal })\bigg{\|}_{2}^{2}. \tag{5}\]  
To use this distance as a loss metric, it must be normalized. Therefore, it is normalized as an exponential form, yielding the normalized Wasserstein loss (WL) as:  
\[WL(\mathcal{N}_{1},\mathcal{N}_{2})=exp\left(-\frac{\sqrt{W_{2}^{2}(\mu_{1}, \mu_{2})}}{C}\right), \tag{6}\]  
where \(C\) is an empirically set constant, which is set as 12.8 in this paper. In conclusion, the final detection loss is comprised of the sum of the class loss, objectness loss and Wasserstein Loss.