A real-time blood cell detection method based on improved blood cell extraction and multi-scale attention
By introducing an improved method of SPD-Conv layer, Swin Transformer and WDLoss function, the feature extraction and multi-scale attention of blood cell detection are enhanced, the detection problems of small targets and low-resolution images are solved, and high-precision and efficient blood cell detection is achieved.
Patent Information
- Application Number
- CN202411701780.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-26
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2044-11-26
AI Technical Summary
Existing deep learning algorithms have insufficient detection accuracy for small targets and low-resolution images in blood cell detection, making it difficult to meet the diversity and complexity requirements of practical applications.
The spatial-to-depth convolutional (SPD-Conv) layer is used to enhance feature extraction, and the Swin Transformer is combined to implement the multi-scale attention mechanism. The c2f module is simplified, and the Wasserstein distance loss (WDLoss) function is used to optimize the model structure and loss function to improve detection accuracy.
The accuracy and real-time processing performance of blood cell detection are significantly improved, especially the recognition ability in complex backgrounds, which improves the efficiency and generalization ability of the model.
Smart Images

Figure CN119559636B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of medical image analysis, and in particular to a real-time blood cell detection method based on improved blood cell extraction and multi-scale attention. Background Art
[0002] The application of deep learning technology has driven significant progress in the field of medical image analysis, particularly in automated blood cell detection. Accurately identifying and counting blood cells is crucial for diagnosing blood disorders and monitoring health. However, traditional manual methods are time-consuming and error-prone, limiting their utility in modern clinical practice. In recent years, the rapid advancement of deep learning in image recognition and object detection has made automated blood cell detection feasible. Although the YOLO family of algorithms is widely accepted for its real-time detection capabilities, the detection of small objects such as blood cells and in low-resolution images still needs to be optimized.
[0003] To address these challenges, much research has focused on improving deep learning algorithms, particularly the YOLO family of algorithms, to meet the needs of hematology applications. These improvements encompass innovations in model architecture, enhancements to specific components, and customized solutions for hematology-specific features. For example, some studies have enhanced feature extraction capabilities and introduced multi-scale attention mechanisms to improve the accuracy of small object detection. Furthermore, other studies have reduced complexity by simplifying model components and utilizing novel loss functions to improve object localization accuracy.
[0004] Although the above methods have improved the performance of blood cell detection to a certain extent, in the face of the diversity and complexity in practical applications, further exploration and optimization are still needed. In view of this, the present invention proposes a new method - a real-time blood cell detection method based on improved blood cell extraction and multi-scale attention, which aims to enhance feature extraction through the spatial to depth convolution (SPD-Conv) layer, use Swin Transformer to implement the multi-scale attention mechanism, simplify the c2f module to reduce the complexity of the model, and adopt the Wasserstein distance loss (WDLoss) function to improve positioning accuracy. Empirical analysis shows that the present invention achieved an average precision (mAP) of 94.0% on the BCCD blood cell dataset, showing superior performance. It is expected that this technology will promote the automation of blood cell analysis, improve the efficiency of clinical workflows, reduce human errors, and provide strong technical support for the diagnosis and management of blood diseases. Summary of the Invention
[0005] This paper aims to address the problems of the existing technology and proposes a method for enhancing blood cell detection. This method improves the detection accuracy of small objects such as blood cells by improving feature extraction capabilities and introducing a multi-scale attention mechanism. It is applicable to low-resolution images. By using spatial-to-depth convolution (SPD-Conv), Swin Transformer, and Wasserstein distance loss (WDLoss), the goal of this paper is to significantly improve the accuracy of blood cell detection while ensuring real-time performance.
[0006] The technical embodiment of the present invention is: a real-time blood cell detection method based on improved blood cell extraction and multi-scale attention, comprising the following steps:
[0007] S1. Model construction: constructing a real-time blood cell detection model, which includes a multi-scale feature extraction module, a multi-scale feature fusion module, a multi-scale feature enhancement module and a detection module;
[0008] S2. Image acquisition and processing: High-resolution image data containing blood cells are obtained from a public blood cell image database for preprocessing, and the processed image dataset is divided into a training set, a validation set, and a test set;
[0009] S3, Feature Extraction and Fusion: The blood cell image data of the training set and validation set in S2 are input into the S1 model, and the SPD-Conv layer is used to extract multi-scale features. The obtained feature maps are then fused. A simplified c2f module is used for feature fusion at each scale, and then the Swin Transformer is used to construct a multi-scale feature representation, allowing the model to focus on key areas in the image to obtain a fused feature map.
[0010] S4, multi-scale detection: The fused feature map obtained in step S3 is input into the detection module. A multi-scale detection strategy is adopted. Using the adjusted and fused feature map, three detection heads of different scales are used to detect large, medium, and small targets in the image, respectively, to finally obtain the detection frame of the blood cells.
[0011] S5. Iterative training: Set the loss function of the blood cell detection model and iteratively train the model;
[0012] S6. Repeat S3-S5 until a real-time blood cell detection model based on multi-scale features is trained.
[0013] S7, post-processing and output: Use the blood cell image data of the test set in step S2 to input into the trained model for detection, filter out redundant bounding boxes through non-maximum suppression technology, retain the detection results with the highest confidence and output them to evaluate the effect of blood cell detection.
[0014] To further illustrate the above scheme, the feature extraction module of the blood cell detection model consists of a regular convolutional layer and multiple SPD-Conv convolutional layers, which are responsible for extracting image features for subsequent use by the network. In step S3, the SPD-Conv layer replaces the standard convolutional layer to extract image features. See Equation 1.
[0015] F SPD =SPD-Conv(I) Formula 1
[0016] Where I is the input image, F SPD Feature map obtained for the SPD-Conv layer;
[0017] Formula 2-Formula 4 visualizes the calculation process of the SPD-Conv layer:
[0018] f x,y =X[{i|(i+x)modγ=0},{j|(j+y)modγ=0}] Formula 2
[0019]
[0020] X'=Conv(X',C',stride=1) Formula 4
[0021] where X, X', X" are the feature maps of the input, SPD and Conv stages respectively, γ is the downsampling factor, and f x,y is the sub-feature map that has been sliced and diced, and C' is the count of the required output channels; assuming that the size of the input feature map X is H×W×C, where H and W are the height and width respectively, and C is the number of channels, after the SPD layer, the feature Figure X The size of ' becomes Then, convolution operation is performed on X' through the non-strided convolution layer to reduce the number of channels, further refine the features, and output the features. Figure X The size of " can be adjusted to
[0022] As a further description of the above scheme: In step S3, a simplified c2f module is used for feature fusion to minimize the computational load and simplify the model architecture while maintaining excellent detection performance;
[0023] As shown in Formula 5, the simplified c2f module can be expressed as:
[0024] c2f SSW (X1,X2,...,X n )=concat(UpSample(Conv(X1)),X2,...,X n ) Formula 5
[0025] Where X1 is the feature map of the original c2f module 1024 channels, X2,...,X n It is the remaining feature map with a small number of channels. After simplification, X1 is eliminated, and the remaining feature maps are upsampled, convolved, and spliced to form the final fused feature map;
[0026] Swin Transformer is then used to construct a multi-scale feature representation, allowing the model to focus on key areas in the image. Formula 6 describes the feature fusion process, and Formula 7 describes the feature enhancement process:
[0027] F multi =c2f simplified (F1,F2,...,F n ) Formula 6
[0028] F swin =SwinTransformer(F multi ) Formula 7
[0029] where F1, F2, ..., F n Represents features at different levels, F multi is the fused multi-scale feature, F swin It is a feature that is refined and enhanced through multi-scale feature processing.
[0030] As a further description of the above scheme: the computational complexity of the window-based multiple self-attention (W-MSA) in the Swin Transformer is shown in Formula 8:
[0031] Ω(W-MSA)=4hwR 2 +2M 2 hwR Formula 8
[0032] Among them, h and w are the number of image blocks, hw is the total number of blocks, R is the number of channels, and M is the number of blocks in each window. When M is constant, the complexity increases linearly with the image size.
[0033] The working process of the self-attention module in Swin Transformer is shown in Formula 9:
[0034]
[0035] Where Q, K, and V represent the query matrix, key matrix, and value matrix, respectively. d represents the dimension of the key vector. In addition, B represents the relative position bias matrix.
[0036] In a specific Swin Transformer layer, the self-attention module operates under a shifted window configuration, allowing the model to capture information across different windows and enhance global perception capabilities; Swin Transformer improves the model's detection accuracy of blood cells by integrating relative position information into the calculation of attention weights.
[0037] To further illustrate the above solution, in step S4, a multi-scale detection strategy is employed. Using the adjusted fused feature map, three different-scale detection heads are employed to detect targets corresponding to the large, medium, and small scales in the image, respectively. Large, medium, and small targets here refer to the relative size and scale of the area occupied by the target in the image. Each detection head is specifically designed to handle targets of a specific scale. In this way, the entire detection system can more effectively cover targets of different sizes, thereby improving overall detection performance. The detection process is shown in Equation 10:
[0038] B,C,S=DetectionHead(F swin ) Formula 10
[0039] Where B is the bounding box prediction, C is the category prediction score, and S is the confidence score;
[0040] In step S4, after the target is detected, anchor box regression and classification probability calculation are performed. The anchor box regression method in YOLOv8 is used to adjust the position and size of the prediction box according to the regression parameters output by the prediction head. The Sigmoid function is used to calculate the probability of each bounding box to ensure that the output meets the blood cell classification specifications, as shown in formulas 11, 12, and 13:
[0041]
[0042] P class =σ(C) Formula 13
[0043] where Δx B and Δy B are the regression parameters of width and height, w pred and h pred Represents the width and height of the predicted bounding box, w true and h true They represent the width and height of the actual bounding box, σ is the Sigmoid function, and C is the category prediction score.
[0044] As a further description of the above scheme: In step S5, the blood cell detection model uses the WDLoss function and the Distribution Focal Loss (DFL) function to calculate the regression loss, and uses the Varifocal Loss (VFL) function to determine the classification loss. The calculation formula is as follows:
[0045] L total =L WDLoss +λL DFL Formula 14
[0046] Among them L total is the total regression loss, L WDLoss For WDLoss, L DFL is DFL, λ is the balance factor;
[0047] The WDLoss function is calculated as follows:
[0048] Feature extraction: First, the input image x is extracted through the blood cell detection model network to generate a feature map f(x);
[0049] Generate bounding box: Generate a bounding box based on the extracted feature map f(x);
[0050] Calculation of WDLoss function: WDLoss function calculates the prediction box The Wasserstein distance between the ground truth box b is given by the corresponding two-dimensional Gaussian distribution and N(b), and the calculation formula is shown in Formula 15:
[0051]
[0052] Among them, NWD represents the normalized Wasserstein distance, For the prediction box The corresponding Gaussian distribution model, N(b) is the Gaussian distribution model corresponding to the real box b.
[0053] As a further description of the above scheme: in step S6, after each iterative training is completed, the validation set in the blood cell dataset is used to evaluate the performance of the real-time blood cell detection model based on improved blood cell extraction and multi-scale attention to prevent the model from overfitting.
[0054] As a further description of the above scheme: In step S7, non-maximum suppression (NMS) is used to filter out redundant bounding boxes and retain the detection results with the highest confidence. This process is shown in Formula 17:
[0055] NMS({b i})={b i '} Formula 17
[0056] where {b i} is the set of all detected bounding boxes, {b i '} is the set of bounding boxes after non-maximum suppression (NMS);
[0057] After training, the real-time blood cell detection model based on improved blood cell extraction and multi-scale attention will be able to accurately identify and count various blood cell types. The output process is shown in Formula 18:
[0058] Output={b i '|P class >θ} Formula 18
[0059] Where θ is the confidence threshold and Output is the final output set of bounding boxes containing location information and categories.
[0060] The present invention has the following advantages: It provides a real-time blood cell detection method based on improved blood cell extraction and multi-scale attention. The SPD-Conv layer enhances feature extraction capabilities, the Swin Transformer provides a multi-scale attention mechanism, the optimized c2f module reduces model complexity, and the Wasserstein distance loss (WDLoss) function improves positioning accuracy. This method not only improves the accuracy of blood cell detection but also demonstrates excellent real-time processing performance, demonstrating its practical application value. By improving feature extraction and incorporating a multi-scale attention mechanism, the model also improves recognition capabilities in complex backgrounds. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] Figure 1 A flow chart of the solution of the present invention;
[0062] Figure 2 is a structural diagram of the blood cell detection model of the present invention;
[0063] Figure 3 This is a detection channel diagram of the blood cell detection model of the present invention;
[0064] Figure 4 A diagram showing the proportions of the data set used in the present invention;
[0065] Figure 5 A diagram showing the number of instances of the dataset used in the present invention;
[0066] Figure 6 This is the SPD-Conv layer structure diagram used in the present invention;
[0067] Figure 7 This is a structural diagram of the Swin Transformer used in the present invention;
[0068] Figure 8 This is an example diagram of the mosaic data enhancement technology used in the present invention;
[0069] Figure 9 This is a diagram showing the effect of the blood cell counting function of the present invention;
[0070] Figure 10 The present invention trains the trend diagram of each indicator;
[0071] Figure 11 This is the evaluation index diagram of the present invention;
[0072] Figure 12 This is a comparison chart of the confusion matrix between the present invention and YOLOv8;
[0073] Figure 13 This is a visual comparison chart of the detection results of the present invention and YOLOv8. DETAILED DESCRIPTION
[0074] To make the objectives, technical solutions, and advantages of the present invention more apparent, the present invention will be further described in detail below with reference to the accompanying drawings. It is hereby stated that any directional terms such as "up," "down," "left," "right," "front," "back," "inside," and "outside" that appear or will appear herein are based solely on the accompanying drawings and are not intended to limit the present invention.
[0075] like Figures 1-6 As shown, a real-time blood cell detection method based on improved blood cell extraction and multi-scale attention includes the following steps:
[0076] S1. Model construction: Build a real-time blood cell detection model based on improved blood cell extraction and multi-scale attention;
[0077] S2. Image acquisition and processing: Acquire high-resolution image data containing blood cells from a public blood cell image database; preprocess the acquired blood cell image data and divide the processed image dataset into a training set, a validation set, and a test set;
[0078] S3, Feature Extraction and Fusion: The blood cell image data from the training and validation sets in S2 are input into the model for multi-scale feature extraction. The resulting feature maps are then fused, using a simplified c2f module for feature fusion at each scale. This aims to reduce the computational load and simplify the model architecture while maintaining excellent detection performance. Subsequently, the Swin Transformer is used to construct a multi-scale feature representation, enabling the model to focus on key areas in the image, improving its ability to recognize complex details of blood cells and enhancing the overall accuracy of the model.
[0079] S4, multi-scale detection: The fused feature map obtained in step S3 is input into the detection module. A multi-scale detection strategy is adopted. Using the adjusted and fused feature map, three detection heads of different scales are used to detect large, medium, and small targets in the image, respectively, to finally obtain the detection frame of the blood cells.
[0080] S5. Iterative training: Set the loss function of the blood cell detection model and iteratively train the model;
[0081] S6. Repeat S3-S5 until a real-time blood cell detection model based on multi-scale features is trained.
[0082] S7, post-processing and output: Use the blood cell image data of the test set in step S2 to input into the trained model for detection, filter out redundant bounding boxes using the non-maximum suppression (NMS) technique, retain the detection results with the highest confidence and output them to evaluate the effectiveness of blood cell detection.
[0083] In step S1, the blood cell detection model includes a multi-scale feature extraction module, a multi-scale feature fusion module, a multi-scale feature enhancement module and a detection module; the multi-scale feature extraction module enhances the feature extraction capability by adopting a space-to-depth convolution layer; the multi-scale feature fusion module optimizes and reorganizes the c2f module at multiple scales, thereby simplifying the model complexity and facilitating feature fusion and gradient flow optimization; the multi-scale feature enhancement module integrates the attention mechanism of SwinTransformer and adopts innovative mechanisms such as hierarchical design, shift window mechanism and relative position deviation to further refine and enrich multi-scale features and realize multi-scale feature representation, thereby enhancing the model's recognition capability of multi-scale features and optimizing the utilization of global context information.
[0084] It needs to be further explained that, Figure 2 As shown in the figure, the backbone of the blood cell detection model consists of a regular convolutional layer, multiple SPD-Conv convolutional layers, and a c2f module, which is responsible for extracting image features for subsequent use by the network. The neck component, located between the backbone and the head, refines the features extracted by the backbone and integrates the features. The head component defines the detection network structure of the blood cell detection model and uses the extracted features to generate the final detection results. The entire workflow of the model is shown in the figure. Figure 2 As shown, a more intuitive detection channel diagram is shown in Figure 3 shown.
[0085] In step S1, several high-resolution blood cell image data are selected from the BCCD public dataset.
[0086] In step S2, the data set is divided into training set, validation set and test set according to the ratio of 7:1:2. Figure 4 and Figure 5 shown.
[0087] It should be noted that the resolution of the dataset images is 640×480. The dataset contains a total of 364 images, which are divided into training set, validation set and test set in a ratio of 7:1:2. Among them, 254 images are used for training, 37 images are used for validation, and 73 images are used for testing.
[0088] In step S4, during the extraction module process, the blood cell image data of the training set and the validation set need to be input into the blood cell detection model for multi-scale feature extraction; in step S3, the feature maps are fused from multiple scales by using the optimized c2f module to minimize the computational load and simplify the model architecture while maintaining excellent detection performance.
[0089] It should be noted that in step S3, the SPD-Conv layer is used instead of the standard convolution layer to more effectively extract image features. Formula 1 illustrates this process.
[0090] F SPD =SPD-Conv(I) Formula 1
[0091] Where I is the input image, F SPD Feature maps obtained for the SPD-Conv layer.
[0092] It should be further explained that the SPD-Conv layer is a novel convolutional neural network (CNN) building block designed to solve the difficult problems in low-resolution image and small object detection. The entire SPD-Conv execution process is as follows: Figure 6As shown in Figure 2, SPD-Conv consists of two components: an SPD (space-to-depth) layer and a non-strided convolutional layer. The SPD layer downsamples the feature maps, preserving information while retaining all data in the channel dimension. Following the SPD layer, a non-strided convolutional layer is used to prevent the SPD layer from increasing the number of channels. Building on the concepts of SPD-Conv, we made key adjustments to ensure seamless integration within the model architecture and optimal performance. While effective, the original stride of 2 in SPD-Conv can lead to indiscriminate information loss, which can affect the model's ability to discern subtle features. Therefore, we innovatively set the stride to 1, eliminating the risk of information loss and ensuring that features at each layer are preserved and utilized to the greatest extent possible, fundamentally improving detection accuracy. Furthermore, the original approach of appending an SPD-Conv layer after each convolutional layer increases model complexity, compromises computational efficiency, and increases the likelihood of overfitting. To address this issue, we boldly removed the traditional convolutional layers preceding the SPD-Conv layer and directly utilize the SPD-Conv layer for feature extraction. This modification significantly reduces the complexity of the overall model, effectively alleviates overfitting, and ensures that the model can more robustly learn the intrinsic patterns of the data during training.
[0093] Formulas 2, 3, and 4 visualize the computational flow of the SPD-Conv layer. By optimizing the process, we aim to provide a more refined and richer feature representation for the model without losing information integrity.
[0094] f x,y =X[{i|(i+x)modγ=0},{j|(j+y)modγ=0}] Formula 2
[0095]
[0096] X'=Conv(X',C',stride=1) Formula 4
[0097] where X, X', X" are the feature maps of the input, SPD and Conv stages respectively, γ is the downsampling factor, and f x,y is the sub-feature map that has been sliced and diced, and C' is the count of the required output channels. Assume that the size of the input feature map X is H×W×C, where H and W are the height and width respectively, and C is the number of channels. After the SPD layer, the feature Figure X The size of ' becomes Then, convolution operation is performed on X' through the non-strided convolution layer to reduce the number of channels, further refine the features, and output the features. Figure X The size of " can be adjusted to
[0098] By introducing and optimizing the SPD-Conv layer, we address the complexities of low-resolution images and small object recognition, while also improving the model's efficiency and generalization capabilities. This marks a significant advancement in blood cell detection, ensuring the model can handle complex scenarios with greater accuracy and reliability, setting a new standard for performance in medical image analysis.
[0099] It should be noted that in step S3, we use a simplified c2f module for feature fusion, removing the 1024-channel component. This reduces model complexity and improves computational efficiency. The c2f module in the original model fuses features from different levels, achieving multi-scale feature representation, which is crucial in object detection tasks, especially for identifying objects of varying sizes. However, the original c2f module contains multiple branches, each corresponding to feature maps at a different depth. One of these branches has 1024 channels, which undoubtedly increases model complexity and processing overhead. While a large number of channels can capture rich feature information, it also introduces unnecessary computational overhead, especially when processing low-resolution images and small objects. By removing this component, we are able to reduce model size, lower resource requirements, and simplify the model structure, enabling the model to maintain high detection accuracy while achieving faster processing speed and lower latency. The simplified c2f module retains other branches with lower channel counts to facilitate feature fusion and gradient flow optimization. This ensures that the model effectively identifies and localizes objects of varying sizes, especially small objects, while keeping overall computational cost under control. This simplification strategy enhances the model’s utility without compromising its detection performance, making it more suitable for scenarios requiring real-time processing and constrained resources. This is particularly advantageous in environments where processing large amounts of data or where resources are limited.
[0100] As shown in Formula 5, the simplified c2f module can be expressed as:
[0101] c2f SSW (X1,X2,...,X n )=concat(UpSample(Conv(X1)),X2,...,X n ) Formula 5
[0102] Where X1 is the feature map of the original c2f module 1024 channels, X2,...,X n It is the remaining feature map with a small number of channels. After simplification, X1 is removed and the remaining feature maps are upsampled, convolved, and concatenated to form the final fused feature map.
[0103] We then use the Swin Transformer to construct a multi-scale feature representation, allowing the model to focus on key areas in the image, enhancing its ability to identify complex details of blood cells and improving the accuracy of the model in capturing blood cell features. Equations 6 and 7 describe this process of feature fusion and enhancement.
[0104] F multi =c2f simplified (F1,F2,...,F n ) Formula 6
[0105] F swin =SwinTransformer(F multi ) Formula 7
[0106] where F1, F2, ..., F n Represents features at different levels, F multi is the fused multi-scale feature, F swin It is a feature that is refined and enhanced through multi-scale feature processing.
[0107] It should be further explained that the hierarchical design of Swin Transformer can gradually build multi-scale feature representations starting from the bottom of the image, thereby effectively understanding complex visual objects in deep networks. The structural diagram of Swin Transformer is shown in the figure below. Figure 7 As shown in Figure 8, the moving window mechanism can effectively calculate self-attention within non-overlapping local windows while ensuring smooth cross-window message communication. This design not only saves computing resources but also ensures the efficiency of the model in processing high-resolution images. The addition of relative position deviation further improves the model's sensitivity to spatial relationships. Combining positioning information with attention calculation improves the model's positioning accuracy in tasks such as small target detection. The computational complexity of window-based multiple self-attention (W-MSA) in the Swin Transformer is shown in Formula 8.
[0108] Ω(W-MSA)=4hwR 2 +2M 2 hwR Formula 8
[0109] Among them, h and w are the number of image blocks, hw is the total number of blocks, R is the number of channels, and M is the number of blocks in each window. When M is constant, the complexity increases linearly with the image size.
[0110] The working process of the self-attention module in Swin Transformer is shown in Equation 9.
[0111]
[0112] Where Q, K, and V represent the query matrix, key matrix, and value matrix, respectively, and d represents the dimension of the key vector. In addition, B represents the relative position bias matrix. In a specific Swin Transformer layer, the self-attention module operates under a shifted window configuration, allowing the model to capture information across different windows and enhance global perception capabilities. By incorporating relative position information into the calculation of attention weights, the Swin Transformer significantly improves the model's detection accuracy for small targets (such as blood cells).
[0113] Specifically, the Swin Transformer works with the c2f module, which performs initial feature fusion. The Swin Transformer then further refines and enriches the multi-scale features, enhancing the model's recognition capabilities. This combination ensures that the model can accurately focus on multi-scale feature maps, especially when identifying small objects such as blood cells, significantly improving detection accuracy and efficiency.
[0114] In step S4, a multi-scale detection strategy is employed. Using the adjusted and fused feature maps, three different-scale detection heads are used to detect objects corresponding to large, medium, and small scale information in the image. Large, medium, and small objects, respectively, occupy large, medium, and small areas in the image. The specially designed detection heads effectively identify objects of different scales, improving overall detection accuracy.
[0115] In this embodiment, the detection sizes of the target row detection are:
[0116] The detection feature map size corresponding to P3 / 8 is 80×80, which is used to detect small targets larger than 8x8. The detection feature map size corresponding to P4 / 16 is 40×40, which is used to detect medium targets larger than 16×16.
[0117] The detection feature map size corresponding to P5 / 32 is 20×20, which is used to detect large targets with a size of more than 32×32.
[0118] The detection process is shown in formula 10.
[0119] B,C,S=DetectionHead(F swin ) Formula 10
[0120] Where B is the bounding box prediction, C is the category prediction score, and S is the confidence score.
[0121] It's important to note that in step S5, after detecting the target, anchor box regression and classification probability calculation are performed. Using the anchor box regression method in YOLOv8, the position and size of the predicted box are adjusted based on the regression parameters output by the prediction head. The sigmoid function is used to calculate the likelihood of each bounding box, ensuring that the output meets the blood cell classification specifications, as shown in Equations 11, 12, and 13.
[0122]
[0123] P class =σ(C) Formula 13
[0124] where Δx B and Δy B are the regression parameters of width and height, w pred and h pred Represents the width and height of the predicted bounding box, w true and h true They represent the width and height of the actual bounding box, σ is the Sigmoid function, and C is the category prediction score.
[0125] In step S5, the blood cell detection model uses the WDLoss function and the Distribution Focal Loss (DFL) function to calculate the regression loss, while the Varifocal Loss (VFL) function is used to determine the classification loss. The WDLoss function optimizes the Wasserstein distance loss, provides effective gradient information, and improves the detection accuracy of small objects (such as blood cells), even if the predicted box does not overlap or completely contains the ground truth box. In addition, DFL solves problems related to class imbalance and sample difficulty. The calculation process of the regression loss is shown in Formula 14. In general, the combination of these two loss functions helps improve the performance of the model, especially in small target detection and solving sample imbalance.
[0126] L total =L WDLoss +λL DFL Formula 14
[0127] Among them L total is the total regression loss, L WDLoss For WDLoss, L DFL is the DFL, and λ is the balancing factor. After comparing specific experimental data, λ was ultimately set to 1.5. After calculating the loss function, the model uses the calculated loss value through the backpropagation algorithm to adjust its internal parameters to minimize the overall loss and improve performance.
[0128] It should be further explained that in step S5, in order to improve the positioning accuracy of small objects (such as blood cells), we improved the loss function and replaced the traditional CIoU loss with the WDLoss function. The WDLoss function generates more effective gradient information by calculating the Wasserstein distance between the expected box and the actual box, especially when the target is completely enclosed in another box or lacks any overlap. The design of the WDLoss function is based on the Gaussian distribution model to represent the bounding box. The WDLoss function is calculated as follows:
[0129] 1. Feature extraction: First, the input image x is subjected to feature extraction through the blood cell detection model network to generate a feature map f(x).
[0130] 2. Generate bounding box: Generate a bounding box based on the extracted feature map f(x).
[0131] 3. Calculation of WDLoss function: WDLoss function calculates the prediction box The Wasserstein distance between the ground truth box b is given by the corresponding two-dimensional Gaussian distribution and N(b). The calculation formula is shown in Formula 15.
[0132]
[0133] Where NWD represents the normalized Wasserstein distance. For the prediction box The corresponding Gaussian distribution model, N(b) is the Gaussian distribution model corresponding to the real box b.
[0134] The WDLoss function uses a two-dimensional Gaussian distribution model to represent the true and predicted bounding boxes. This allows it to provide effective gradient information even when there is little or no overlap between the predicted and true bounding boxes, making model training more efficient. This function's advantage lies in its smoother gradients and its particular suitability for detecting small objects with minimal overlap. In situations where small objects are difficult to precisely match with their ground-truth bounding boxes, the WDLoss function calculates the normalized Wasserstein distance between Gaussian distributions to more accurately measure the difference between the predicted and true bounding boxes, thereby improving the accuracy of small object detection. In a blood cell detection model, the WDLoss function's application pipeline involves starting with the input image, performing feature extraction, generating predicted bounding boxes, and finally optimizing the loss function by calculating the Wasserstein distance between the predicted and true bounding boxes. This improves the accuracy and stability of small object detection, which is crucial for tasks such as blood cell detection. This approach also provides valuable insights for other computer vision tasks requiring small object detection.
[0135] In step S6, after each iterative training is completed, the validation set in the blood cell dataset is used to evaluate the performance of the real-time blood cell detection model based on improved blood cell extraction and multi-scale attention to prevent the model from overfitting.
[0136] It should be further explained that in order to solve the problem of limited blood cell image data sets, the present invention uses a technique called mosaic data enhancement to optimize the training data. This enhancement technique acts in iterative training. The purpose is to improve the network's recognition accuracy for different types of targets, especially small targets, and improve the overall efficiency of the training process. This enhancement method combines four different images by selecting a batch of data from the training set and merging them in a random sampling manner. First, the images are subjected to independent random resizing steps, and then the images are spliced and combined according to specific rules to form a fixed-size rectangular composite training sample, such as Figure 8 As shown, the enhancement process is shown in Formula 16.
[0137]
[0138] Among them, I1, I2, I3, and I4 are four randomly selected images, and ⊕ is the image stitching operation.
[0139] In step S7, non-maximum suppression (NMS) is used to filter out redundant bounding boxes and retain the detection results with the highest confidence. This process is shown in Equation 17.
[0140] NMS({b i})={b i '} Formula 17
[0141] where {b i} is the set of all detected bounding boxes, {b i '} is the set of bounding boxes after non-maximum suppression (NMS).
[0142] After training, the real-time blood cell detection model based on improved blood cell extraction and multi-scale attention will be able to accurately identify and count various blood cell types, thereby supporting the accuracy and efficiency of medical diagnosis. The output process is shown in Equation 18.
[0143] Output={b i '|P class >θ} Formula 18
[0144] Where θ is the confidence threshold and Output is the final output set of bounding boxes containing location information and categories.
[0145] It should be further explained that blood cell counting is an important part of routine biomedical and clinical laboratory testing. It is mainly used to measure the number of red blood cells, white blood cells and platelets in human blood. It is a key tool for evaluating the overall health of an individual, assisting in the diagnosis of various diseases, and monitoring the effectiveness of treatment. Therefore, in the final output results, the present invention not only realizes the detection of blood cells, but also completes the counting of blood cells and intuitively displays the counting results. This achievement helps medical staff obtain more comprehensive information support in diagnosis and treatment decisions, and has a positive effect on promoting clinical diagnosis and pathological research. Specific blood cell count results are shown in Figure 9 .
[0146] It should be noted that the experiment was conducted using a 64-bit Windows operating system, and mAP, precision, and recall were used as evaluation metrics. The specific experimental configuration is shown in Table 1.
[0147] Table 1 Experimental configuration information
[0148]
[0149] It's important to note that to assess the effectiveness of our blood cell detection model, we conducted a rigorous performance evaluation. By comparing the model's performance before and after improvements on various key metrics, we confirmed the effectiveness and advantages of our blood cell detection model. We conducted experiments on the BCCD dataset for up to 300 training epochs. Figure 10 The following table shows the changing trends of the model in terms of precision, recall and mean average precision (mAP). As the training iterations progress, the performance of the model steadily improves and eventually reaches a stable state, producing the best results. The best results of the model are shown in Figure 2. Figure 11 shown.
[0150] This technical solution is compared with other test models. The model performance comparison results are shown in Table 2 and Figure 12 、 Figure 13 As shown in the figure, a higher mAP index indicates a better blood cell detection effect.
[0151] Table 2 Model performance comparison information
[0152]
[0153] It should be noted that this technical solution achieved significant improvements in multiple performance metrics when compared with other tested models, surpassing the performance of previous research models. This demonstrates that the proposed detection algorithm outperforms similar algorithms and achieves a 1.6 percentage point improvement in mean average precision (mAP) compared to the YOLOv8 model.
[0154] To further evaluate the effectiveness of the various improvements presented in this paper, we conducted an ablation study using YOLOv8n as a baseline model for a comprehensive analysis. We sequentially removed or replaced the SPD-Conv layer, the Swin Transformer attention mechanism, the simplified c2f module, and the WDLoss function, observing their impact on model performance. A represents the SPD-Conv layer, B represents the Swin Transformer attention mechanism, C represents the simplified 1024-channel portion of the c2f module, and D represents the use of the WDLoss function in place of the original loss function. The ablation study results are shown in Table 3.
[0155] Table 3 Ablation experiment results
[0156]
[0157] It should be further explained that each improvement of the present invention, whether alone or in combination, has a significant positive impact on the average precision of blood cell testing, with the improvement in mAP ranging from 0.6% to 1.6%. After combining all improvements, the mAP increased by 1.6%, which is the best improvement. These results not only verify the effectiveness of each improvement step, but also highlight the excellent performance of the present invention in blood cell testing tasks. The model of the present invention combines multiple innovative technologies, making breakthrough progress in the academic field. It has important practical value, helps to improve the accuracy and efficiency of blood testing, and promotes the development of the medical and health field.
[0158] The embodiments of the present invention have been described in detail above with reference to the accompanying drawings. However, the present invention is not limited to these exemplary embodiments. Within the scope of knowledge of those skilled in the art, various optimizations and modifications can be made to the embodiments without departing from the core spirit and basic principles of the present invention.
Claims
1. A real-time blood cell detection method based on improved blood cell extraction and multi-scale attention, characterized in that, The following steps are involved: S1. Model construction: constructing a real-time blood cell detection model, which includes a multi-scale feature extraction module, a multi-scale feature fusion module, a multi-scale feature enhancement module and a detection module; S2. Image acquisition and processing: High-resolution image data containing blood cells are obtained from a public blood cell image database for preprocessing, and the processed image dataset is divided into a training set, a validation set, and a test set; S3, Feature Extraction and Fusion: The blood cell image data of the training set and validation set in S2 are input into the S1 model, and the SPD-Conv layer is used to extract multi-scale features. The obtained feature maps are then fused. A simplified c2f module is used for feature fusion at each scale, and then the Swin Transformer is used to construct a multi-scale feature representation, allowing the model to focus on key areas in the image to obtain a fused feature map. S4, multi-scale detection: The fused feature map obtained in step S3 is input into the detection module. A multi-scale detection strategy is adopted. Using the adjusted and fused feature map, three detection heads of different scales are used to detect large, medium, and small targets in the image, respectively, to finally obtain the detection frame of the blood cells. S5. Iterative training: Set the loss function of the blood cell detection model and iteratively train the model; S6. Repeat S3-S5 until a real-time blood cell detection model based on multi-scale features is trained. S7, post-processing and output: Use the blood cell image data of the test set in step S2 to input into the trained model for detection, filter out redundant bounding boxes through non-maximum suppression technology, retain the detection results with the highest confidence and output them to evaluate the effect of blood cell detection.
2. The real-time blood cell detection method based on improved blood cell extraction and multi-scale attention according to claim 1, characterized in that: The feature extraction module of the blood cell detection model consists of a conventional convolutional layer and multiple SPD-Conv convolutional layers, which are responsible for extracting image features for subsequent use by the network. In step S3, the process of extracting image features by the SPD-Conv layer is shown in Formula 1. F SPD = SPD-Conv(I) Formula 1 Where I is the input image, F SPD Feature map obtained for the SPD-Conv layer; Formula 2-Formula 4 visualizes the calculation process of the SPD-Conv layer: f x,y = X[{i|(i + x) mod γ = 0}, {j|(j + y) mod γ = 0}] Formula 2 X'=Conv(X',C',stride=1) Formula 4 where X, X', X" are the feature maps of the input, SPD and Conv stages respectively, γ is the downsampling factor, and f x,y is the sub-feature map that has been sliced and diced, and C' is the count of the required output channels; assuming that the size of the input feature map X is H×W×C, where H and W are the height and width respectively, and C is the number of channels, after the SPD layer, the size of the feature map X' becomes Then, a convolution operation is performed on X' through a non-strided convolution layer to reduce the number of channels and further refine the features. The size of the output feature map X" can be adjusted to 3. The real-time blood cell detection method based on improved blood cell extraction and multi-scale attention according to claim 1, characterized in that: In step S3, a simplified c2f module is used for feature fusion to minimize the computational load and simplify the model architecture while maintaining excellent detection performance; As shown in Formula 5, the simplified c2f module can be expressed as: c2f SSW (X1,X2,...,X n )=concat(UpSample(Conv(X1)),X2,...,X n ) Formula 5 Where X1 is the feature map of the original c2f module 1024 channels, X2,...,X n It is the remaining feature map with a small number of channels. After simplification, X1 is eliminated, and the remaining feature maps are upsampled, convolved, and spliced to form the final fused feature map; Swin Transformer is then used to construct a multi-scale feature representation, allowing the model to focus on key areas in the image. Formula 6 describes the feature fusion process, and Formula 7 describes the feature enhancement process: F multi =c2f simplified (F1,F2,...,F n ) Formula 6 F swin = SwinTransformer(F multi ) Formula 7 where F1, F2, ..., F n Represents features at different levels, F multi is the fused multi-scale feature, F swin It is a feature that is refined and enhanced through multi-scale feature processing.
4. The real-time blood cell detection method based on improved blood cell extraction and multi-scale attention according to claim 3, characterized in that: The computational complexity of window-based multiple self-attention in the Swin Transformer is shown in Formula 8: Ω(W-MSA) = 4hwR 2 + 2M 2 hwR Equation 8 Among them, h and w are the number of image blocks, hw is the total number of blocks, R is the number of channels, and M is the number of blocks in each window. When M is constant, the complexity increases linearly with the image size. The working process of the self-attention module in Swin Transformer is shown in Formula 9: Where Q, K, and V represent the query matrix, key matrix, and value matrix, respectively. d represents the dimension of the key vector. In addition, B represents the relative position bias matrix. In a specific Swin Transformer layer, the self-attention module operates under a shifted window configuration, allowing the model to capture information across different windows and enhance global perception capabilities; Swin Transformer improves the model's detection accuracy of blood cells by integrating relative position information into the calculation of attention weights.
5. The real-time blood cell detection method based on improved blood cell extraction and multi-scale attention according to claim 1, characterized in that: In step S4, a multi-scale detection strategy is adopted. By adjusting the fused feature map, three different scale detection heads are used to detect targets corresponding to the large, medium, and small scale information in the image. The detection process is shown in Formula 10: B,C,S=DetectionHead(F swin ) Formula 10 Where B is the bounding box prediction, C is the category prediction score, and S is the confidence score; In step S4, after the target is detected, anchor box regression and classification probability calculation are performed. The anchor box regression method in YOLOv8 is used to adjust the position and size of the prediction box according to the regression parameters output by the prediction head. The Sigmoid function is used to calculate the probability of each bounding box to ensure that the output meets the blood cell classification specifications, as shown in formulas 11, 12, and 13: P class = σ(C) Equation 13 where Δx B and Δy B are the regression parameters of width and height, w pred and h pred Represents the width and height of the predicted bounding box, w true and h true They represent the width and height of the actual bounding box, σ is the Sigmoid function, and C is the category prediction score.
6. The real-time blood cell detection method based on improved blood cell extraction and multi-scale attention according to claim 1, characterized in that: In step S5, the blood cell detection model uses the WDLoss function and the Distribution Focal Loss (DFL) function to calculate the regression loss, and uses the Varifocal Loss (VFL) function to determine the classification loss. The calculation formula is as follows: L total =L WDLoss +λL DFL Formula 14 Among them L total is the total regression loss, L WDLoss For WDLoss, L DFL is DFL, λ is the balance factor; The WDLoss function is calculated as follows: Feature extraction: First, the input image x is extracted through the blood cell detection model network to generate a feature map f(x); Generate bounding box: Generate a bounding box based on the extracted feature map f(x); Calculation of WDLoss function: WDLoss function calculates the prediction box The Wasserstein distance between the ground truth box b is given by the corresponding two-dimensional Gaussian distribution and N(b), and the calculation formula is shown in Formula 15: Among them, NWD represents the normalized Wasserstein distance, For the prediction box The corresponding Gaussian distribution model, N(b) is the Gaussian distribution model corresponding to the real box b.
7. The real-time blood cell detection method based on improved blood cell extraction and multi-scale attention according to claim 1, characterized in that: In step S6, after each iterative training is completed, the validation set in the blood cell dataset is used to evaluate the performance of the real-time blood cell detection model based on improved blood cell extraction and multi-scale attention to prevent the model from overfitting.
8. The real-time blood cell detection method based on improved blood cell extraction and multi-scale attention according to claim 1, characterized in that: In step S7, non-maximum suppression (NMS) is used to filter out redundant bounding boxes and retain the detection results with the highest confidence. This process is shown in formula 17: NMS({b i })={b i '} Formula 17 where {b i } is the set of all detected bounding boxes, {b i '} is the set of bounding boxes after non-maximum suppression (NMS); After training, the real-time blood cell detection model based on improved blood cell extraction and multi-scale attention will be able to accurately identify and count various blood cell types. The output process is shown in Formula 18: Output={b i '|P class >θ} Formula 18 Where θ is the confidence threshold and Output is the final output set of bounding boxes containing location information and categories.
Citation Information
Patent Citations
Target detection method based on fine-grained features
CN118887378A
Contextual visual-based SAR target detection method and apparatus, and storage medium
US20230184927A1