Breast mass detection method based on improved YOLOv5s
By improving the YOLOv5s network and utilizing anchor box clustering, CBAM attention mechanism, and CIoU loss function, the problem of insufficient accuracy in breast lump detection in existing methods is solved, and higher accuracy in breast lump detection and classification is achieved.
Patent Information
- Application Number
- CN202310315756.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-28
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2043-03-28
AI Technical Summary
Existing traditional machine learning methods and YOLOv3-based breast lump detection methods have insufficient detection accuracy, making it difficult to achieve high-precision breast lump detection.
An improved YOLOv5s network is adopted, which generates suitable anchor boxes by clustering anchor boxes. The network is then trained using the CBAM attention mechanism and the CIoU loss function to improve detection accuracy.
It enables more accurate detection and classification of breast lumps, improving detection accuracy.
Smart Images

Figure CN116468675B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a detection technology, and more particularly to a method for detecting breast lumps based on an improved YOLOv5s. Background Technology
[0002] Breast cancer is one of the most common and deadliest cancers in the world. Early diagnosis is crucial for the treatment of breast cancer. The ability to quickly and accurately detect lumps from a single breast image is a necessary research question, making the improvement of the accuracy of breast lump detection a current research hotspot.
[0003] Methods for breast lump detection can be divided into two categories: traditional machine learning-based methods and deep learning-based methods. Traditional machine learning methods have failed to provide highly accurate models due to the limitations of handcrafted features extracted from raw images. In fact, compared to deep learning methods, traditional CAD systems proposed for breast lesion detection and classification cannot overcome the significant variations in lesion size and texture. Therefore, deep learning architectures can better detect breast lesion areas. Currently, deep learning-based object detection methods can be divided into two types: two-stage and one-stage. Two-stage algorithms are mainly region-based R-CNN series algorithms, such as R-CNN, Fast R-CNN, and Faster R-CNN. The other type is single-stage algorithms such as SSD and YOLO series. Some researchers have used YOLOv3 to detect breast lumps, using the K-means algorithm to generate adaptive bounding boxes from the raw data for lump detection; however, this algorithm has low recognition accuracy. Summary of the Invention
[0004] To address the issue of accurate detection of breast lumps, a breast lump detection method based on an improved YOLOv5s is proposed, which can detect lumps more accurately.
[0005] The technical solution of this invention is: a method for detecting breast lumps based on an improved YOLOv5s, specifically including the following steps:
[0006] 1) Preprocess and label mammogram images to obtain a dataset;
[0007] 2) Cluster the labeled anchor boxes in the dataset to generate anchor boxes suitable for the dataset for use in the YOLOv5s network;
[0008] 3) Use the Backbone part of YOLOv5s to extract features from the image, and add CBAM to the extracted feature map. In CBAM, first pass through a channel attention module to obtain the weighted result, and then pass through a spatial attention module to finally obtain a new feature map.
[0009] 4) Feature fusion is performed using the Neck part of YOLOv5s. The feature fusion is to fuse the feature map generated by CBAM in the Backbone part with the feature map after upsampling.
[0010] 5) Using the prediction part of YOLOv5s, the detection results of breast lumps are obtained. The prediction network model is trained iteratively using the CIoU loss function to obtain a YOLOv5s network model that meets the prediction requirements. This model is then used to detect the breast lumps to be tested and to obtain the corresponding lump location and classification.
[0011] Furthermore, the specific implementation method of step 2) is as follows:
[0012] 2-1) Cluster the length and width data of all the bounding boxes labeled in the dataset using the Kmeans method; the bounding boxes are the length and width of the labeled ground truth boxes. The anchor box data obtained after clustering replaces the 9 anchor box data of the YOLOv5s network and generates 9 new anchor box values suitable for the dataset.
[0013] 2-2) The K-means clustering center points are set to 9, and the length and width parameters of 9 anchor boxes are obtained after clustering, which are used in the YOLOv5s network.
[0014] Furthermore, the formula for the channel attention mechanism of CBAM in step 3) is as follows:
[0015]
[0016] Where σ is the sigmoid function; F is the feature map of the input CBAM; MLP is a two-layer shared multilayer inductively coupled loop (MLP); AvgPool is average pooling; MaxPool is max pooling; W0∈R C / r×C W1∈R C×C / r W0 and W1 are the weights after pooling and sharing the network, respectively, and r is the channel reduction ratio; These are two channel attention vectors;
[0017] The formula for the spatial attention mechanism of CBAM is as follows:
[0018]
[0019] Where f n×n This is a convolution operation, where n×n is the filter size.
[0020] Furthermore, the CIoU loss function formula in step 5) is as follows:
[0021]
[0022]
[0023]
[0024] Where IoU represents the intersection of the joint bounding boxes, R DIoU Represent two bounding boxes b and b gt The distance between the center points, ρ(·) represents the Euclidean distance, c represents the diagonal distance of the smallest rectangle formed by the two bounding boxes; α is the weight function, and v is used to measure the similarity of the aspect ratio W and h.
[0025] The beneficial effects of this invention are as follows: This invention is based on an improved YOLOv5s method for detecting breast lumps. It improves upon the original deep learning network, thereby enabling more accurate detection and classification of breast lumps, and providing technical support for future related lump detection. Attached Figure Description
[0026] Figure 1 This is a flowchart illustrating the steps of the breast mass detection method based on the improved YOLOv5s of this invention.
[0027] Figure 2 This is a diagram of the YOLOv5s network architecture.
[0028] Figure 3 This is a diagram of the improved network structure of YOLOv5s in this invention;
[0029] Figure 4 This is a diagram of the convolution block attention module in the method of the present invention;
[0030] Figure 5 This is the original image of a breast mass in an embodiment of the present invention;
[0031] Figure 6 This image shows the results of breast lump detection using the method of the present invention. Detailed Implementation
[0032] The present invention will now be described in detail with reference to the accompanying drawings and specific embodiments. These embodiments are based on the technical solution of the present invention and provide detailed implementation methods and specific operating procedures. However, the scope of protection of the present invention is not limited to the following embodiments.
[0033] This invention discloses a method for detecting breast lumps based on an improved YOLOv5s, such as... Figure 1The flowchart shown illustrates the steps of a breast lump detection method based on an improved YOLOv5s. First, a dataset of mammogram images is obtained and processed. Then, based on the original YOLOv5s, improvements are made. The first improvement is the redesign of the model's anchor boxes, using the K-means algorithm for clustering to generate anchor boxes suitable for the mammogram image dataset. The second improvement is the addition of a Convolutional Block Attention (CBAM) module to the backbone layer of the YOLOv5s network, and training the improved network. Adding this attention mechanism not only saves network parameters and computational power but also allows the network to focus more on the feature information of the lump during feature extraction. Finally, the mammogram image to be detected is fed into the improved YOLOv5s network for identification, obtaining the corresponding lump location and classification.
[0034] The existing YOLOv5s network architecture diagram is as follows: Figure 2 As shown, the improved YOLOv5s network structure of this invention is illustrated in the diagram below. Figure 3 As shown, the input mammogram image is fed into the improved YOLOv5s network, where feature extraction (Backbone part), feature fusion (Neck part), and prediction (Head part) are performed sequentially. The specific steps are as follows:
[0035] Step 1: Perform relevant preprocessing and annotation on mammogram images to obtain a dataset;
[0036] Step 1-1: Convert the original mammogram image into a .jpg format image;
[0037] Steps 1-2: Label each breast image using the labelImg annotation tool and generate a corresponding XML tag file. The file contains the four coordinates of the target to be detected and the given category. The four coordinates contain the length and width data of the target to be detected.
[0038] Step 2: Redesign the annotated anchor frame;
[0039] Step 2-1: Cluster the length and width data of all the bounding boxes labeled in the dataset using the K-means method; the bounding box is the length and width of the labeled ground truth box. The purpose of clustering is to make the anchor boxes generated by the network as close as possible to the length and width of the labeled ground truth boxes. The anchor box data obtained after clustering replaces the 9 anchor box data of the YOLOv5s network and generates 9 new anchor box values that are more suitable for its own dataset.
[0040] Step 2-2: Set the K-means clustering center points to 9. After clustering, obtain the length and width parameters of 9 anchor boxes, which are used in the YOLOv5s network.
[0041] Step 3: Use the Backbone part of YOLOv5s to extract features from the image, and then add CBAM after extracting the feature map, such as... Figure 4 Note the module diagram of the convolutional block shown, combined with... Figure 3 The improved feature extraction method is as follows;
[0042] Step 3-1: Input the annotated image from Step 1 into convolutional layer C3 in the Backbone part of YOLOv5s to obtain the feature map;
[0043] Step 3-2: CBAM is introduced after C3. The feature map generated by CBAM is fed into the Neck section for feature fusion (Concat). The feature map obtained from C3 enters CBAM, first passing through a channel attention module to obtain a weighted result, and then passing through a spatial attention module for final weighting to obtain a new feature map. The channel attention mechanism formula is as follows:
[0044]
[0045] Where σ is the sigmoid function; F is the feature map of the input CBAM; MLP is a two-layer shared multilayer inductively coupled loop (MLP); AvgPool is average pooling; MaxPool is max pooling; W0∈R C / r×C W1∈R C×C / r W0 and W1 are the weights after pooling and sharing the network, respectively, and r is the channel reduction ratio; These are two channel attention vectors;
[0046] The formula for spatial attention mechanism is as follows:
[0047]
[0048] Where f n×n This is a convolution operation, where n×n is the filter size;
[0049] Step 3-3: The feature map output by CBAM in the Backbone section is sent to the Neck section.
[0050] Step 4: Perform feature fusion using the Neck part of YOLOv5s;
[0051] Feature fusion involves fusing the three feature maps generated by the backbone network with the upsampled feature map. The purpose is to enrich the semantic and location information of the features, thereby enabling more accurate detection of breast lumps.
[0052] Step 5: Using the prediction part of YOLOv5s, the detection results of breast lumps are obtained. The prediction network model is iteratively trained using the CIoU loss function to obtain a YOLOv5s network model that meets the prediction requirements, which is then used to detect the breast lumps to be tested.
[0053] The CIoU loss function formula is as follows:
[0054]
[0055]
[0056]
[0057] Where IoU represents the intersection of the joint bounding boxes, R DIoU Represent two bounding boxes b and b gt The distance between the center points, ρ(·) represents the Euclidean distance, c represents the diagonal distance of the smallest rectangle formed by the two bounding boxes; α is the weight function, and v is used to measure the similarity of the aspect ratio W and h.
[0058] like Figure 5 The images shown in this example are the original images of breast lumps. The left image shows a breast image containing a benign lump, and the right image shows a breast image containing a malignant lump. Figure 6 The image shows the results of breast lump detection using the method of this invention. The left side shows the results of benign lumps detected by the improved YOLOv5s after training, and the right side shows the results of malignant lumps detected.
[0059] The embodiments described above are merely illustrative of several implementations of the present invention, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these all fall within the protection scope of the present invention. Therefore, the protection scope of this invention patent should be determined by the appended claims.
Claims
1. A method for detecting breast lumps based on an improved YOLOv5s, characterized in that, Specifically, the steps include the following: 1) Preprocess and label mammogram images to obtain a dataset; 2) Cluster the labeled anchor boxes in the dataset to generate anchor boxes suitable for the dataset for use in the YOLOv5s network; 3) Use the Backbone part of YOLOv5s to extract features from the image, and add CBAM to the extracted feature map. In CBAM, first pass through a channel attention module to obtain the weighted result, and then pass through a spatial attention module to finally obtain a new feature map. 4) Feature fusion is performed using the Neck part of YOLOv5s. The feature fusion is to fuse the feature map generated by CBAM in the Backbone part with the feature map after upsampling. 5) Using the prediction part of YOLOv5s, the detection results of breast lumps are obtained. The prediction network model is trained iteratively using the CIoU loss function to obtain a YOLOv5s network model that meets the prediction requirements. This model is then used to detect the breast lumps to be tested and to obtain the corresponding lump location and classification.
2. The breast lump detection method based on improved YOLOv5s according to claim 1, characterized in that, The specific implementation method of step 2) is as follows: 2-1) Cluster the length and width data of all the bounding boxes labeled in the dataset using the Kmeans method; the bounding boxes are the length and width of the labeled ground truth boxes. The anchor box data obtained after clustering replaces the 9 anchor box data of the YOLOv5s network and generates 9 new anchor box values suitable for the dataset. 2-2) The K-means clustering center points are set to 9, and the length and width parameters of 9 anchor boxes are obtained after clustering, which are used in the YOLOv5s network.
3. The breast lump detection method based on improved YOLOv5s according to claim 1, characterized in that, The formula for the channel attention mechanism of CBAM in step 3) is as follows: Where σ is the sigmoid function; F is the feature map of the input CBAM; MLP is a two-layer shared multilayer inductively coupled loop (MLP); AvgPool is average pooling; MaxPool is max pooling; W0∈R C / r×C W1∈R C×C / r W0 and W1 are the weights after pooling and sharing the network, respectively, and r is the channel reduction ratio; These are two channel attention vectors; The formula for the spatial attention mechanism of CBAM is as follows: Where f n×n This is a convolution operation, where n×n is the filter size.
4. The breast lump detection method based on improved YOLOv5s according to claim 1, characterized in that, The CIoU loss function formula in step 5) is as follows: Where IoU represents the intersection of the joint bounding boxes, R DIoU Represent two bounding boxes b and b gt The distance between the center points, ρ(·) represents the Euclidean distance, c represents the diagonal distance of the smallest rectangle formed by the two bounding boxes; α is the weight function, and v is used to measure the similarity of the aspect ratio W and h.
Citation Information
Patent Citations
Small target detection method based on attention mechanism
CN114202672A
FairMOT multi-class tracking method based on improved attention mechanism
CN114241053A