# An Improved Lightweight YOLOv8 Network for Early Small Flame Target Detection
## 4 Yolov8 Improvements
### Improvement of Loss Function  
The loss function of YOLOv8 consists of two parts, the class classification loss and the bounding box regression loss. The original bounding box regression loss of YOLOv8 is CIoU (compatible intersection over union) [15] and DFL (deep feature loss) [16]. The CIoU improves the calculation method of the IoU, more accurately measuring the overlap between target boxes, making the loss function more accurately guide the training of the target detection model. During training, the CIoU can better predict the bounding box offset between the prediction box and the real box, which helps to improve the positioning accuracy of the target detection model. DFL introduces the distribution focal loss function, which can effectively deal with the problem of sample imbalance, improve the attention of the target detection model to difficult samples, and help to improve the generalization ability of the model [17; 18]. However, since our task is mainly aimed at early fire detection, the early stage of fire occurrence is mostly small targets. The calculation of the CIoU is relatively complex and requires additional computational overhead, which may increase the time cost of training and inference and currently, the CIoU has a problem with the design of aspect ratio weight, which may damage the quality of regression samples; DFL introduces additional hyperparameters which need to be tuned, increasing the complexity of model training. In response to the above problems, researcher [PERSON] and others [19] proposed a new NWD (normalized Wasserstein distance) loss function. The similarity between the bounding boxes is calculated through the Gaussian distribution to which they correspond by means of a 2D Gaussian model. In the event of no or minimal overlap, the similarity between distributions can nevertheless be quantified, rendering this approach particularly well suited to measuring the similarity between small objects. In the case of smaller objects, it is not uncommon for background pixels to be present within their bounding boxes. This is due to the fact that real-world objects do not always conform to a strictly rectangular shape. In these bounding boxes, the concentration of foreground pixels and background pixels is observed to be at the center and edge of the bounding box, respectively. In order to more accurately describe the weight of different pixels within the bounding box, the bounding box can be modeled as a two-dimensional (2D) Gaussian distribution, where the center pixel of the bounding box is assigned the highest weight and the importance of pixels gradually decreases from the center to the edge. In particular, for a horizontal bounding box \(R=(cx,cy,w,h)\), \((cx,cy)\), \(w\), and \(h\) represent the center coordinates, width, and height, respectively. The equation of the inscribed ellipse can be expressed as follows:  
\[\frac{(x-\mu_{x})^{2}}{\sigma_{x}^{2}}+\frac{(y-\mu_{y})^{2}}{\sigma_{y}^{2}}=1 \tag{5}\]  
where \((\mu_{x},\mu_{y})\) is the center coordinate of the ellipse and \(\sigma_{x}\) and \(\sigma_{y}\) are the semi-axis lengths along the \(x\) and \(y\) axes, respectively. Therefore, \(\mu_{x}=c_{x}\), \(\mu_{y}=c_{y}\), \(\sigma_{x}=w^{2}\), and \(\sigma_{y}=h_{2}\). The probability density function of a 2D Gaussian distribution is usually represented as  
\[f(X|\mu,\Sigma)=\frac{\exp{(-\frac{1}{2}(x-\mu))}^{T}\Sigma^{-1}(x-\mu))}{2\pi |\Sigma|^{\frac{1}{2}}} \tag{6}\]  
where \(x\), \(\mu\), and \(\Sigma\) represent the coordinate \((x,y)\) of the Gaussian distribution, the mean vector, and the covariance matrix. \[(X-\mu)^{T}\Sigma^{-1}(X-\mu)=1 \tag{7}\]  
The ellipse represented in Formula (5) will serve as the density contour for the two-dimensional Gaussian distribution. Accordingly, the horizontal bounding box \(R=(c_{x},c_{y},w,h)\)can be modeled as a two-dimensional Gaussian distribution, \(\mathcal{N}(\mu,\Sigma)\), where \(\mu\) and \(\Sigma\) represent the mean vector and the covariance matrix of the Gaussian distribution, respectively. \[\mu=