An improved YOLOX target detection method with an improved loss function
By improving the loss function of the YOLOX target detection method and integrating the center point distance and aspect ratio consistency terms, the computational complexity and accuracy problems of the CIoU loss function in small target detection are solved, achieving faster and more accurate target detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-23
- Publication Date
- 2026-03-10
AI Technical Summary
The existing CIoU loss function suffers from significant aspect ratio when dealing with small targets, which affects the regression performance. Furthermore, the calculation process is complex and cannot meet the needs of real-time detection.
By employing improved loss functions LeDIoU and LeCIoU, integrating center point distance through natural exponents, adding aspect ratio consistency terms, optimizing network parameters, and improving detection accuracy and speed.
It accelerates the regression speed between predicted and ground truth boxes, reduces the complexity of the computation process, and improves the accuracy and efficiency of target detection, making it suitable for real-time detection.
Smart Images

Figure CN115861764B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to an improved YOLOX target detection method with an improved loss function, belonging to the field of image recognition technology. Background Technology
[0002] With the development of computer technology, object detection has become a popular research area. Object detection can identify and locate objects in videos or images containing them, and it has broad prospects in fire early warning and fire detection. Object detection technology is mainly divided into traditional technology and deep learning-based object detection technology. The latter learns from a large number of images containing the target to extract target features, and its performance is far superior to traditional technology, making it the mainstream object detection algorithm.
[0003] Deep learning-based object detection methods are mainly divided into two categories: one-stage methods and two-stage methods. Two-stage methods define candidate regions in the first stage and classify these regions in the second. Representative algorithms include R-CNN, Fast R-CNN, and Faster R-CNN. These algorithms achieve high accuracy by separately detecting target regions and classifying categories, but they also have high hardware requirements and a slower detection speed. One-stage methods directly train on images to simultaneously derive the location and category information of the target bounding boxes. Typical algorithms include SSD, YOLOv3, YOLOv4, YOLOv5, and YOLOx. While one-stage methods have slightly lower accuracy than two-stage methods, their training and detection costs are significantly lower, and they offer faster detection speeds, making them suitable for real-time detection.
[0004] The loss function is used in object detection to measure the quality of predictions during training. During training, the error between the true and predicted values is calculated using the loss function, and this error is used as backpropagation parameters to progressively optimize the network parameters, thereby improving the network model. The object detection loss function consists of three parts: confidence loss, classification loss, and bounding box regression loss. The confidence and classification losses typically use the Cross-Entropy Loss (CE Loss), while the bounding box loss function uses the Intersection and Union Loss (IoU Loss), as well as its improved versions GIoU Loss, DIoU Loss, and CIoU Loss. IoU Loss cannot handle cases where two bounding boxes do not overlap. Therefore, GIoU Loss, by introducing the concept of a minimum bounding box, addresses this issue. However, when the boxes overlap, it degenerates back to IoU. To solve this problem, DIoU Loss was subsequently proposed, calculating the Euclidean distance between the center points and introducing the aspect ratio of the ground truth and predicted boxes, thus proposing CIoU Loss to address the difference in box shapes. However, when dealing with small targets, the aspect ratio of CIoU Loss leads to a larger loss, which is detrimental to regression performance. Summary of the Invention
[0005] The purpose of this invention is to provide an improved YOLOX target detection method with an improved loss function, which improves monitoring efficiency and accuracy.
[0006] To achieve the above objectives, the present invention employs the following technical solution:
[0007] Step 1: Obtain real images and video frame data to be detected, and calibrate them using the Labelme tool to generate the VOC2007 dataset;
[0008] Step 2: Enhance the labeled dataset, including flipping, enlarging, cropping, adding noise, and rotating operations;
[0009] Step 3: Divide the dataset into training and testing sets. Train the YOLOX network model on the training set to obtain a weight file, and then use the weight file to test and obtain the mAP value; the loss function L of the YOLOX network model... eDIoU Specifically as follows:
[0010] L eDIoU =1-eDIoU
[0011]
[0012]
[0013]
[0014] Where ρ(B) pr B gt B represents the distance between the center points of the ground truth bounding box and the predicted bounding box. pr B represents the prediction box. gt Represents the true bounding box. Indicates the x-coordinate of the center of the prediction box, Represents the x-coordinate of the center of the true bounding box, Indicates the ordinate of the center of the prediction box, Represents the ordinate of the center of the true bounding box;
[0015] Step 4: Select the model with the smallest mAP value in the training results as the final object detection model, input the test set into the trained object detection model, and process it to obtain the target location.
[0016] Preferably, when the center points of the predicted bounding box and the ground truth bounding box coincide, the loss function is as follows:
[0017] L eCIoU =1-(eDIoU-αυ)
[0018]
[0019]
[0020] Where α is the weighting parameter, υ is the consistency measure of aspect ratio, and w pr and h pr w represents the width and height of the prediction box. gt with h gt ρ represents the width and height of the true bounding box, e represents the Euclidean distance, and e represents the natural index.
[0021] The advantages of this invention are as follows: It accelerates the regression speed between the predicted and ground truth boxes by improving the loss function, enabling a larger descent gradient when the center point distance d is large, thus mitigating the complexity of the computation process. Furthermore, considering the case where the center points of the predicted and ground truth boxes coincide, a new loss function is added to ensure that it reflects the relationship between width and height. Attached Figure Description
[0022] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used together with the embodiments of the invention to explain the invention and do not constitute a limitation thereof.
[0023] Figure 1 This is a schematic diagram of the process structure of the present invention. Detailed Implementation
[0024] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0025] An improved YOLOX object detection method with an improved loss function includes the following steps:
[0026] Step 1: Obtain real fire image data and calibrate it using the Labelme tool to generate the VOC2007 dataset, which includes Annotation, ImageSets, and JPEGImages folders. The Annotation folder contains .xml files with target location and type information for each image. The ImageSets folder contains .txt files with the names of the training and testing images. The JPEGImages folder contains the fire image data in JPG format.
[0027] Step 2: Enhance the labeled dataset, including flipping, enlarging, cropping, adding noise, and rotating. After enhancement, not only can the number of images in the dataset be increased, but the original images can also be expanded into more complex images, increasing the complexity and diversity of the dataset.
[0028] Step 3: Train and test the data using the standard YOLOX network. Download the standard YOLOX model and modify it, adjusting the model parameters. Place the VOC2007 dataset folder generated in Step 2 in the specified location, and simultaneously modify the training set location information. Then, modify the number and name of the categories in the corresponding code files according to their names. Select a pre-trained model; this solution uses Darknet53. Place the downloaded pre-trained model data in the YOLOX folder to begin training. During runtime, the code divides the data into training and testing sets. The training process uses the CIOU-based loss function eCIOU (Exponential Complete Intersection over Union), replacing the actan function with a natural exponent to change the aspect ratio. Furthermore, in the basic DIOU part, the Euclidean distance is transformed into an exponential form through a natural exponent transformation. These elements are combined to form eCIOU, which is then embedded into YOLOX, improving performance while maintaining the same computational load and real-time performance. It can also be used as a loss function for other object detection algorithms, exhibiting good portability. The YOLOX model that replaced eCIOU was trained using the dataset from step two to obtain the improvement.pth weight file. The weight file was then used for testing to obtain the mAP value.
[0029] Step 5: Perform multiple experiments on the model from Step 4, obtain the best mAP value for each model, compare the performance and test results, and finally use the best model from Step 4 as the final model. Input the target to be detected and obtain the detection results.
[0030] The specific loss function is as follows: In YOLOX's total loss, the coordinate loss is calculated using the intersection-over-union (IoU) loss function.
[0031]
[0032] Among them B pr B represents the corresponding predicted box. gt This represents the ground-truth box.
[0033] However, during the calculation process, when the center distance between the ground truth bounding box and the predicted bounding box is too large, especially for small targets, the error is reduced by increasing the size of the predicted bounding box. Furthermore, the aspect ratio also affects the loss, making the loss reduction process more cumbersome and increasing the number of iterations required for the model to stabilize. Therefore, this paper proposes a new function for calculating the bounding box coordinate loss to improve the complexity of the DIoU calculation process. The formula is shown below.
[0034]
[0035]
[0036] Where ρ(B) pr B gt The distance between the center points of the ground truth bounding box and the predicted bounding box is represented by y = 1 - e. The natural index is used to integrate the center point distances, as shown in the formula above. -x The function's properties ensure that its value ranges between 0 and 1. Furthermore, to accelerate the regression between the predicted and ground truth boxes, it is transformed into the form d / d+1, allowing for a larger d-degree gradient when the center point distance d is large. Additionally, considering the case where the center points of the predicted and ground truth boxes coincide, a new loss component is added to eDIoU to ensure it reflects the relationship between width and height. The formula is shown below.
[0037]
[0038]
[0039] Where α is the weighting parameter, υ is the consistency measure of aspect ratio, and w pr and h pr w represents the width and height of the prediction box. gt with h gt The width and height of the true bounding box are represented by the natural exponential property to calculate the loss term, which ensures the existence of partial derivatives during gradient backpropagation. The eCIoU expression is shown in the following formula.
[0040] eCIoU=eDIoU-aυ
[0041] The final loss function is shown in the following equation.
[0042] L eDIoU =1-eDIoU
[0043] L eCIoU =1-eCIoU
[0044] Finally, it should be noted that the above descriptions are merely preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. An improved YOLOX target detection method of loss function, characterized in that, Comprising the following steps: Step 1: Obtain real image and video frame data to be detected, and calibrate through Labelme tool to generate VOC2007 data set; Step 2: Enhance the labeled data set, including flipping, zooming, cropping, adding noise, and rotating operations; Step 3: divide the data set into a training set and a test set, train the training set using a YOLOX network model to obtain a weight file, and test using the weight file to obtain an mAP value; the loss function of the YOLOX network model Specifically as follows: wherein denotes the center point distance of the real and predicted boxes, denotes the predicted box, denotes the real box, denotes the predicted box center x-coordinate, denotes the real box center x-coordinate, denotes the predicted box center y-coordinate, denotes the real box center y-coordinate; Step 4: Select the model with the minimum mAP value in the training result as the final target detection model, input the test set into the trained target detection model, and process to obtain the target position; When the prediction box and the real box center point coincide, the loss function is as follows: wherein is a weight parameter, is a measure of consistency of aspect ratio, and denotes the width-height of the predicted box, and denotes the width-height of the true box, denotes the Euclidean distance, e denotes the natural exponential.
Citation Information
Patent Citations
Insulator defect detection method based on improved YOLOv5 convolutional neural network
CN112819804A
YOLOv4 target detection algorithm for improving loss function
CN114463718A