An endoscopic polyp detection method based on improved YOLOv8
By improving the structure and loss function of the YOLO v8 model, the accuracy and efficiency issues of polyp detection in endoscopic examinations were resolved, achieving more efficient and accurate polyp identification and improving the effectiveness of early detection and treatment of colorectal cancer.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HOHAI UNIV
- Filing Date
- 2024-11-25
- Publication Date
- 2026-05-26
AI Technical Summary
Existing methods for detecting colorectal polyps have limitations in endoscopic examinations, including insufficient detection accuracy, difficulty in quickly identifying small targets, and high computational complexity, which affect the efficiency of early detection and treatment of colorectal cancer.
By adding a CA module to the YOLO v8 architecture, replacing the CloU loss function with the Wise-IoU loss function, and adding a small object detection layer to the feature output layer, the backbone, loss function, and feature map structure of the YOLO v8 model are optimized, thereby improving the performance of polyp detection.
It improves the accuracy and efficiency of polyp detection, reduces the false negative rate, enhances the detection capability in complex intestinal environments, improves the accuracy and reliability of endoscopic examinations, and reduces the fatigue of medical staff and subjective judgment differences.
Smart Images

Figure CN122090232A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of target detection and medical auxiliary diagnosis, specifically to a method for polyp target detection based on an improved YOLO v8. Background Technology
[0002] Colorectal cancer (CRC) is a malignant tumor affecting the large intestine and is one of the most serious and common types of cancer worldwide. The 5-year survival rate of CRC is significantly influenced by factors such as cancer stage and lesion location; overall, the estimated 5-year survival rate for CRC is between 48.6% and 59.4%. According to the latest statistics, approximately 150,000 people were diagnosed with CRC in 2020, and more than 50,000 died from the disease. Notably, the incidence of colorectal cancer has been rapidly increasing in recent years. New cases and deaths have nearly doubled in the past decade and continue to grow at a rate of 4-5% annually. Epidemiological studies reveal a worrying trend: the incidence of CRC in adults under 50 years of age is rising and has reached a high level. Studies show that most CRC cases develop from colorectal polyps, especially adenomatous polyps. Timely polyp removal can effectively prevent the occurrence of CRC, reducing its associated mortality rate by 70%. Therefore, accurate detection of polyps during endoscopy is crucial.
[0003] Polyp detection is a crucial task in medical image analysis, and early detection and accurate diagnosis of colorectal polyps are essential for the prevention and treatment of colorectal cancer. In recent years, deep learning technology has made significant progress in medical image analysis, particularly object detection algorithms, which have demonstrated outstanding performance in polyp detection. YOLO (You Only Look Once), as an efficient object detection algorithm, has shown great potential in polyp detection. YOLO is a real-time object detection algorithm, first proposed by Joseph Redmon et al. in 2016. Two-stage object detection algorithms have higher computational complexity and slower detection speed due to the presence of region proposal networks; while YOLO treats object detection as a regression problem, directly mapping from image pixels to bounding boxes and class probabilities, and provides a faster detection rate in real-time applications.
[0004] This invention proposes a polyp detection method based on an improved YOLO v8 architecture. By adding a CA module after C2f in the YOLO v8 architecture, replacing the CloU loss function with the Wise-IoU loss function, and adding a small object detection layer to the pyramid feature output layer, the performance of polyp detection is significantly improved. Compared with previous versions of YOLO, it has higher detection accuracy, stronger small object detection capability, and more efficient computation, making it more suitable for colonoscopy examinations in real-world scenarios. Summary of the Invention
[0005] Colorectal cancer (CRC) often develops from colorectal polyps. Accurate polyp identification is crucial for clinical treatment and helps detect potential cancerous risks early. However, insufficient lighting and a complex intestinal environment in colonoscopy images increase the difficulty for healthcare professionals in detecting polyps. Rapid and accurate polyp detection can significantly improve diagnostic efficiency. This invention relates to an endoscopic polyp detection method based on an improved YOLO v8 model, aiming to improve the localization accuracy and classification accuracy of polyp lesions in endoscopic images. By optimizing the YOLO v8 model's backbone, loss function, and feature map structure, its adaptability and performance in endoscopic polyp detection tasks are improved. The main contents include: image data acquisition, dataset creation, data preprocessing, polyp detection model construction, polyp detection model training, and polyp detection model testing. The specific key steps are as follows:
[0006] Step 1: Obtain the CVC-ClinicDB endoscopic polyp public dataset.
[0007] Step 2, Dataset Construction. The dataset format must conform to the requirements of YOLO v8 code. YOLO v8 generally supports COCO and YOLO formats; if it is not one of these formats, the VOC format can be converted to COCO or YOLO format using methods such as Python scripts.
[0008] Step 3, data preprocessing, the specific processing steps are as follows:
[0009] 3.1 Data cleaning: Ensure that there are no missing image data or incorrect labels in the dataset. If incorrect labels or missing data are found, delete them.
[0010] 3.2 Data Augmentation: To improve the model's generalization ability, data augmentation methods such as Mosaic, MixUp, CutMix, and random pruning are used. The specific steps are as follows:
[0011] 3.2.1 Visualize the data bounding box and store the image and label data in different directory file structures.
[0012] 3.2.2 Data augmentation is performed using technologies such as code integration with Mosaic, while setting batch size, data shuffling, and number of threads.
[0013] 3.3 Divide the dataset into training, validation and test sets according to an appropriate ratio.
[0014] Step 4: Based on the features of endoscopic polyp images, construct an improved YOLO v8 detection model. The specific steps are as follows:
[0015] 4.1 Add an attention module to the original model backbone structure. Add a CA module after the C2f module in the backbone to help the model better focus on important features after feature compression. After the image data is converted into a three-channel matrix and input into the model, it is downsampled through a convolutional layer with k=3, s=2, and p=1. Each downsampling result is denoted as f. In the YOLO v8 backbone, the input matrix undergoes five downsampling operations, denoted as f1, f2, f3, f4, and f5. A CA module is added after f2 and f5 through the C2f module. f5 passes through SPPF and enters the head, undergoing two upsampling operations and concatenation to obtain p1. It is then downsampled and concatenated with f5 to become p2. p2 is then downsampled again and concatenated with f5 to obtain p3. A CA module is added after p1, p2, and p3 respectively.
[0016] 4.2 Replace the original model's loss function. Replace the CIoU loss function used for bounding box position regression in YOLO v8 with the WIoU loss function. The WIoU loss can be expressed as: WIoU Loss = 1 - W·IoU, where the weight W is mainly based on factors such as the distance, scale, and aspect ratio between the predicted and ground truth bounding boxes to refine the IoU loss calculation. Positional bias weights. Where d represents the Euclidean distance between the center points of the predicted box and the ground truth box, and c represents the diagonal length of the smallest bounding box containing both the predicted and ground truth boxes. The weight of the loss function increases when the center point distance is large. Scale difference weights Where S pre S represents the area of the prediction box. ture This represents the area of the ground truth bounding box. When the area of the predicted box and the ground truth bounding box differs significantly, the loss weight increases, thus prompting the model to fit the size of the target bounding box more accurately. Aspect Ratio Difference Weight Where, r pred and r gt These are the aspect ratios of the predicted bounding box and the ground truth bounding box, respectively; when the aspect ratios differ significantly, the weight of the loss will also increase.
[0017] 4.3 A small object detection layer is added by adding an extra Detect module after the SPPF output. f5, after passing through SPPF, enters the Head layer, undergoes two upsampling operations and concatenation to obtain p1. Then, it is downsampled and concatenated with f5 to obtain p2. p2 is downsampled and concatenated with f5 to obtain p3. These three matrices then enter the Detect module for bounding box regression. Next, f2 and the upsampled p3 (i.e., p4) are concatenated, and after passing through the C2f module, another Detect is performed. This adds bounding box regression for 160×160 matrices to the existing YOLO v8, focusing on small object detection.
[0018] Step 5, training the polyp detection model, the specific steps are as follows:
[0019] 5.1 Reduce the number of worker threads or the amount of data read in batches to reduce hardware bottlenecks.
[0020] 5.2 Use a validation set to monitor training progress and apply an early stopping strategy to prevent overfitting. If the validation loss does not decrease after several epochs, stop training.
[0021] 5.3 Adjust the learning rate. Select an appropriate initial learning rate and use learning rate scheduling strategies such as cosine annealing to improve training stability.
[0022] 5.4 Multi-scale training. Images of different resolutions are introduced to train the model to enhance its scale adaptability.
[0023] Step 6, testing the polyp detection model, the specific steps are as follows:
[0024] 6.1 In model testing, input the test set into the model, observe the performance difference between the training set and the test set, and determine whether the model is overfitting or underfitting.
[0025] In section 6.2, accuracy, recall, and mAP are used as performance metrics to measure model detection performance. Accuracy: the proportion of detected polyp regions that are accurately predicted; Recall: the proportion of all actual polyp regions detected by the model; mAP: combines accuracy and recall, providing a more comprehensive reflection of the model's detection capabilities across different categories. During training, observing the trend of mAP with epochs helps understand the model's learning status. Typically, mAP gradually increases as training progresses until it reaches a plateau. If mAP starts to decline at a certain point, it may be a sign of overfitting, requiring measures such as data augmentation or adjusting the learning rate.
[0026] Beneficial effects
[0027] For the task of detecting colorectal polyps, the endoscopic polyp target detection method based on the improved YOLO v8 proposed in this invention has excellent recognition performance, accurately identifying polyp regions in endoscopic images, reducing the false negative rate, and improving the accuracy and reliability of endoscopic polyp examination. For medical personnel, this invention can effectively assist them in quickly and accurately identifying polyp regions in the complex intestinal environment during endoscopic examinations, reducing the risk of false negatives and false positives, avoiding clinical errors caused by human fatigue or subjective judgment differences, improving the accuracy of pathological analysis and disease diagnosis, and providing assistance for the early detection and treatment of colorectal cancer. For medical institutions, this invention can improve the utilization efficiency of endoscopic examination equipment and the work efficiency of examination personnel, while ensuring the standardization and consistency of disease diagnosis, and improving the overall quality of endoscopic polyp examination. Attached Figure Description
[0028] Figure 1 This is a flowchart of the endoscopic polyp detection method based on improved YOLO v8 proposed in this invention.
[0029] Figure 2 CA module diagram
[0030] Figure 3 Improved YOLO v8 architecture diagram
[0031] Figure 4 Diagram of the architecture transformation for adding small object detection to YOLO v8
[0032] Figure 5 Loss curve for training set
[0033] Figure 6 mAP curve of the test results Detailed Implementation
[0034] The technical solutions in the implementation of this invention will now be explained in more detail and completely with reference to the accompanying drawings. Obviously, the following embodiments are only part of this invention, and all other embodiments obtained by those skilled in the art without inventive effort are within the scope of protection of this invention.
[0035] Step 1: Using the public dataset CVC-ClinicDB, check whether the images in the files and their corresponding label files correspond one-to-one to prevent data omissions. Here, a Python script is used to check whether the image files and their corresponding label files in the dataset correspond.
[0036] Step 2: Most models currently support Pascal VOC, COCO, and YOLO formats. First, convert the dataset to the corresponding data format and pair it with the label file. This model uses the COCO format.
[0037] Step 3, preprocess the data, specifically including the following steps:
[0038] The first step is to reconfirm that there are no missing images or labels in the dataset, and that the image file names and corresponding label names do not match.
[0039] The second step is to adjust the directory structure to include image source files and tag folders; using PyTorch's DataLoader, implement the _len_ and _getitem_ methods, and integrate image enhancement techniques such as Mosaic, MixUp, CutMix, and random cropping.
[0040] Step 3: The dataset is divided into a training set, a validation set, and a test set. The training set consists of 90% of the total dataset, totaling 1B90 images; correspondingly, the test set consists of the remaining 10% of the dataset, totaling 314 images; the validation set, as a subset of the training set, consists of 10% of the training set, totaling 1B9 images.
[0041] Step 4: Construct a polyp detection model. The specific steps are as follows:
[0042] The first step is to add CA modules after several C2f functions in the Backbone and Head sections. See the attached document for details on the CA modules. Figure 2 The input image data is downsampled five times to generate feature maps f1, f2, f3, f4, and f5. After f2 and f5, and after f5 undergoing SPPF (Spatial Pyramid Pooling-Fast) processing, it enters the Head section. In the Head section, the feature map dimensionality is increased through upsampling, and it is then concatenated with f3 and f4 to form new feature maps p1, p2, and p3. A Channel Attention (CA) module is added after p1, p2, and p3 respectively. See the appendix for details. Figure 3 .
[0043] The second step involves adding a small object detection module on top of the 160×160 feature map, with connections similar to those used for the 80×80 and 40×40 feature maps. f5, after SPPF (Spatial Pyramid Pooling-Fast) processing, enters the Head section. In the Head section, the feature map's dimension is increased through upsampling, and it is concatenated with f3 and f4 respectively to obtain feature maps p1, p2, and p3. These three feature maps then enter the Detect module for bounding box regression. To enhance the detection capability of small objects, f2 is concatenated with the upsampled p3 (denoted as p4) and further processed through the C2f module. The processed feature map also enters the Detect module for bounding box regression. In this way, a 160×160 feature map for bounding box regression is added to the existing YOLO v8, and the SPPF output layer is expanded from three layers to four layers. See the appendix for details. Figure 4 .
[0044] The third step is to replace the original CloU loss function in YOLO v8 with the Wise-IoU (WIoU) loss function. Specifically, the WIoU loss function is: WIoU Loss = 1 - W·IoU. In terms of code implementation, it is necessary to define the WIoU loss function, modify the eps parameter in wiou_loss, and use the defined WIoU loss function in the forward function that calculates the loss.
[0045] Step 5: Following the data partitioning method in Step 3, and ensuring image data integrity, the preset learning rate is 0.001, batch size is 8, momentum is 0.9, epochs are 200, StepLR is used for Ir_scheduler, and Adam is used for optimizer. The model is initialized using pre-trained weights to accelerate the training process, with weight decay set to 0.0005. See the appendix for the loss curve during training. Figure 5 .
[0046] Step 6: Test the model's performance using pre-assigned test set data. After inputting the test set into the model, observe the difference in performance between the training and test sets. If the model's mAP is very high on the training set but significantly low on the validation or test set, it is likely that the model is overfitting. This means the model has learned too concretely from the training data and cannot generalize well to unseen data. Conversely, if the model's mAP is low on both the training and validation sets, it is underfitting. See the appendix for specific test results. Figure 6 .
[0047] The above description is merely a preferred embodiment of the present invention. It should be noted that, for those skilled in the art, several improvements and modifications can be made without departing from the technical principles of the present invention. For example, in the improved method, the selection of the feature network is not limited to the network mentioned, but can also select other networks suitable for the image data to be processed according to the method proposed in the present invention. The improved method is not limited to the model itself, and other object detection models are also applicable, such as Faster R-CNN, SSD, Mask R-CNN, etc. The model can not only process endoscopic polyp images, but can also be applied to other similar types of image data. These improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A method for endoscopic polyp detection based on improved YOLO v8, which enhances the ability to identify polyp lesions by specifically optimizing the model's backbone, loss function, and pyramid feature map output. Its features include: The main steps include: image data acquisition, data preprocessing, polyp detection model construction, polyp detection model training, and polyp detection model testing.
2. The endoscopic polyp detection method based on improved YOLO v8 according to claim 1, characterized in that, The following improvements were made to the YOLO v8 architecture: a Channel Attention (CA) module was added after the C2f module; the Wise-IoU (WIoU) loss function was used to replace the original CIoU loss function; and a small target detection layer was added after the SPPF (Fast Spatial Pyramid Pooling) output.
3. The method for constructing the polyp detection model according to claim 2, characterized in that, After the image data is input into the model, it undergoes five downsampling operations to generate feature maps f1, f2, f3, f4, and f5. A CA module is added after the C2f module for f2 and f5. After SPPF, f5 enters the Head section, where upsampling increases the feature map dimension. It is then concatenated with f4 and f3 to form feature maps p1, p2, and p3, respectively. A CA module is then added after each of p1, p2, and p3.
4. The method for constructing the polyp detection model according to claim 2, characterized in that, The WIoU loss function replaces the CIoU loss function used in the initial YOLO v8 to regress the predicted bounding box position. In object detection tasks, it can assign greater weight to small objects, thereby improving the model's detection accuracy for small objects. The WIoU loss can be expressed as: WIoU Loss = 1 - W·IoU, where the weight W is mainly refined based on factors such as the distance between the predicted and ground truth boxes, scale, and aspect ratio to refine the IoU loss calculation. 4.1 Calculate the position deviation weight Where d represents the Euclidean distance between the center points of the predicted box and the ground truth box, and c represents the diagonal length of the smallest bounding box containing both the predicted and ground truth boxes. When the center point distance is large, the weight of the loss function also increases. 4.2 Calculate the scale difference weight Where S pre S represents the area of the prediction box. true The area represents the ground truth bounding box. When the area of the predicted bounding box and the ground truth bounding box differs significantly, the loss weight will be larger, thus prompting the model to fit the size of the target bounding box more accurately. 4.3 Calculate the aspect ratio difference weight Where, r pred and r gt These are the aspect ratios of the predicted bounding box and the ground truth bounding box, respectively. When the aspect ratios differ significantly, the weight of the loss function also increases.
5. The method for constructing the polyp detection model according to claim 2, characterized in that, An additional small object detection layer is added to the 160×160 feature map (similar to the connection method between 80×80 and 40×40); as described in claim 3. After SPPF, f5 enters the Head, and the feature map dimension is increased by upsampling. It is then concatenated with f4 and f3 to obtain feature maps p1, p2, and p3. These three matrices are subsequently entered into the Detect module for bounding box regression. Therefore, the approach here is to concatenate f2 with the upsampled p3, i.e., p4, and then perform another Detect through the C2f module, adding bounding box regression for the 160×160 matrix to the original YOLO v8.
6. The endoscopic polyp detection method based on improved YOLO v8 according to claim 1, characterized in that, The key steps in training for polyp detection are as follows: 6.1 Obtain the CVC-ClinicDB endoscopic polyp dataset, convert the dataset to a format suitable for the model, and perform data augmentation (such as Mosaic, MixUp, CutMix, etc.). Then, divide the dataset into training, validation, and test sets according to the proportions. 6.2 It is necessary to consider the performance bottleneck of the physical machine, reduce the number of worker threads or reduce the amount of data read in each batch; 6.3 Use a validation set to monitor the model’s performance at different training stages. Prevent overfitting by using an early stopping strategy. If the validation loss no longer decreases after a certain number of rounds, stop training. 6.4 Select an appropriate initial learning rate and use learning rate scheduling strategies such as cosine annealing to prevent instability during training; 6.5 Multiple image resolutions allow the model to adapt to inputs of different scales.