Real-time blood cell detection method based on improved blood cell extraction and multi-scale attention

By using the combination method of SPD-Conv layer, Swin Transformer and WDLoss function in hemocell detection, the problem of low detection accuracy and insufficient image processing capability of small object is solved, and the high accuracy and real-time performance is greatly improved.

CN119559636AActive Publication Date: 2025-03-04KUNMING UNIV OF SCI & TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411701780.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-26
Publication Date
2025-03-04
Estimated Expiration
2044-11-26

AI Technical Summary

Technical Problem

The prior art has problems in the detection of small targets and insufficient image processing capabilities of low-resolution images in blood cell detection, especially under the diversity and complexity of practical applications.

Method used

By using space-to-depth convolution (SPD-Conv) layer to enhance feature extraction capabilities, using Swin Transformer to implement a multi-scale attention mechanism, simplifying the c2f module to reduce model complexity, and using the Wasserstein distance loss (WDLoss) function to improve positioning accuracy.

Benefits of technology

It significantly improves the accuracy and real-time processing performance of blood cell detection, improves the recognition ability in complex backgrounds, and achieves an average accuracy of 94.0% (mAP).

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119559636A_ABST
    Figure CN119559636A_ABST
Patent Text Reader

Abstract

The invention discloses a real-time blood cell detection method based on improved blood cell extraction and multi-scale attention. The feature extraction capability is enhanced by adopting the SPD-Conv layer, the multi-scale attention mechanism is provided by the Swin Transform, the model complexity is reduced by optimizing the c2f module, and the positioning precision is improved by utilizing the Wasserstein distance loss (WDLoss) function, so that the accuracy of blood cell detection is improved, the excellent real-time processing performance and the practical application value of the blood cell detection method are displayed, and the method is suitable for popularization and application. And the recognition capability under a complex background is improved by improving feature extraction and adding a multi-scale attention mechanism.
Need to check novelty before this filing date? Find Prior Art

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, especially in automated blood cell detection. Accurately identifying and counting blood cells is essential for diagnosing blood diseases and monitoring health conditions. However, traditional manual methods are time-consuming and error-prone, which limits their utility in modern clinical practice. In recent years, with the rapid development of deep learning in image recognition and object detection, automated blood cell detection has become feasible. Although the YOLO family of algorithms are widely accepted for their real-time detection capabilities, the detection of small objects such as blood cells and low-resolution images still needs to be optimized.

[0003] To address these challenges, many studies have focused on improving deep learning algorithms, especially the YOLO family of algorithms, to meet the needs of hematology applications. These improvements cover innovations in model architecture, enhancements to specific components, and customized solutions for hematology features. For example, some studies have improved the accuracy of small target detection by enhancing feature extraction capabilities and introducing multi-scale attention mechanisms. In addition, there are studies that reduce complexity by simplifying model components while using new loss functions to improve the accuracy of target positioning.

[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 space-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 use the Wasserstein distance loss (WDLoss) function to improve the positioning accuracy. Empirical analysis shows that the present invention achieves 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] The present invention aims to solve the problems in the prior art and proposes a method for enhancing blood cell detection. The method improves the detection accuracy of small targets such as blood cells by improving feature extraction capabilities and introducing a multi-scale attention mechanism, and is suitable for low-resolution images. By using spatial to deep convolution (SPD-Conv), Swin Transformer and Wasserstein distance loss (WDLoss), the goal of the present invention is to significantly improve the accuracy of blood cell detection while ensuring real-time performance.

[0006] The technical implementation scheme 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, the model comprising 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 data set 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 the 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, and a simplified c2f module is used to fuse features at each scale. Subsequently, the Swin Transformer is used to construct a multi-scale feature representation, so that the model can focus on the 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, and a multi-scale detection strategy is adopted. The adjusted and fused feature map is used to detect large, medium and small targets in the image through three detection heads of different scales, and finally the detection frame of blood cells is obtained;

[0011] S5. Iterative training: setting the loss function of the blood cell detection model and iteratively training 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] As a further description of the above scheme: the feature extraction module of the blood cell detection model consists of a regular convolution layer and multiple SPD-Conv convolution layers, which are responsible for extracting image features for subsequent use by the network; in step S3, the SPD-Conv layer replaces the standard convolution layer to extract image features. See formula 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, a non-strided convolutional layer is used to perform convolution operations on X' 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 removed, and the remaining feature maps are upsampled, convolved, and concatenated to form the final fused feature map;

[0026] Then, Swin Transformer is 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, and 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] As a further description of the above scheme: In step S4, a multi-scale detection strategy is adopted, and the adjusted fused feature map is used to use three different scale detection heads to detect targets corresponding to the large, medium and small scale information in the image. The 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 specially 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 the overall detection performance. The detection process is shown in Formula 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, anchor box regression and classification probability calculation are performed after the target is detected. 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 regression parameters for 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 respectively, σ 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, and the calculation formula is as follows:

[0045] L total =L WDLoss +λL DFL Formula 14

[0046] Where L total is the total regression loss, L WDLoss For WD Loss, 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 and 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:

[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, and 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: the present invention provides a real-time blood cell detection method based on improved blood cell extraction and multi-scale attention, the feature extraction capability is enhanced by adopting the SPD-Conv layer, the Swin Transformer provides a multi-scale attention mechanism, the c2f module is optimized to reduce the model complexity, and the positioning accuracy is improved by using the Wasserstein distance loss (WDLoss) function. The present invention not only improves the accuracy of blood cell detection, but also demonstrates excellent real-time processing performance and its practical application value. By improving feature extraction and adding a multi-scale attention mechanism, the model also improves the recognition capability under complex backgrounds. BRIEF DESCRIPTION OF THE DRAWINGS

[0061] Figure 1 A flow chart of the scheme of the present invention;

[0062] Figure 2 is a structural diagram of the blood cell detection model of the present invention;

[0063] Figure 3 It 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 data set used in the present invention;

[0066] Figure 6 This is a diagram of the SPD-Conv layer structure used in the present invention;

[0067] Figure 7 The structure 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] Fig. 9 This is a diagram showing the effect of the blood cell counting function of the present invention;

[0070] Fig.10 Training trend charts of various indicators for the present invention;

[0071] Fig.11 This is the evaluation index diagram of the present invention;

[0072] Fig.12 This is a comparison diagram of the confusion matrix between the present invention and YOLOv8;

[0073] Fig.13 This is a visual comparison chart of the detection results of the present invention and YOLOv8. DETAILED DESCRIPTION

[0074] In order to make the purpose, technical solution and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings. It is hereby stated that the directional terms such as up, down, left, right, front, back, inside, outside, etc. that appear or will appear in the text of the present invention are only based on the accompanying drawings of the present invention, and are not specific limitations of the present invention.

[0075] like Figure 1-Figure 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: acquiring high-resolution image data containing blood cells from a public blood cell image database; preprocessing the acquired blood cell image data, and dividing the processed image data set into a training set, a validation set, and a test set;

[0078] S3, feature extraction and fusion: The blood cell image data of the training set and the validation set in S2 are input into the model for multi-scale feature extraction, and then the obtained feature maps are fused. The simplified c2f module is used for feature fusion at each scale to reduce the computational load and simplify the model architecture while maintaining excellent detection performance. Subsequently, Swin Transformer is used to construct a multi-scale feature representation, so that the model can focus on the key areas in the image, improve its ability to identify the complex details of blood cells, and thus enhance 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, and a multi-scale detection strategy is adopted. The adjusted and fused feature map is used to detect large, medium and small targets in the image through three detection heads of different scales, and finally the detection frame of blood cells is obtained;

[0080] S5. Iterative training: setting the loss function of the blood cell detection model and iteratively training 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 through non-maximum suppression (NMS) technology, retain the detection results with the highest confidence and output them to evaluate the effect 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, so as to enhance the model's recognition capability of multi-scale features and optimize the use of global context information.

[0084] It needs to be further explained that if 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 in the figure, 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, feature fusion is performed on feature maps from multiple scales by using an 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 extract image features more effectively. Formula 1 illustrates this process.

[0090] F SPD =SPD-Conv(I) Formula 1

[0091] Where I is the input image, F SPD Feature map 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 difficulties in low-resolution image and small object detection. The entire SPD-Conv execution process is as follows: Figure 6As shown in Figure 1. SPD-Conv consists of two parts: SPD (space-to-depth) layers and non-strided convolutional layers. The SPD layer handles the downsampling of feature maps, preserving information while retaining all data in the channel dimension. After the SPD layer, a non-strided convolutional layer is used to prevent the number of channels generated by the SPD layer from increasing. Building on the concept of SPD-Conv, we made key adjustments to ensure seamless integration and optimal performance within the model architecture. The original stride=2 in SPD-Conv, while effective, may result in indiscriminate information loss, thus affecting the model's ability to identify subtle features. Therefore, we innovatively set the stride to 1, eliminating the risk of information loss, ensuring that the features of each layer are retained and utilized to the greatest extent, and fundamentally improving the detection accuracy. In addition, the original method is to attach an SPD-Conv layer after each convolutional layer, which leads to increased model complexity, affects computational efficiency, and increases the possibility of overfitting. To address this issue, we boldly removed the traditional convolutional layer before the SPD-Conv layer and directly used 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, the goal is to provide a more refined and richer feature representation of 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 desired 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, a non-strided convolutional layer is used to perform convolution operations on X' 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 have solved the complex problems of low-resolution images and small object recognition, while also improving the efficiency and generalization of the model. This marks a major advancement in blood cell detection, ensuring that the model can handle complex scenes with higher 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 and remove the 1024-channel part, which reduces the model complexity and improves the computational efficiency. The c2f module in the original model fuses features at different levels and realizes multi-scale feature representation, which is crucial in object detection tasks, especially when identifying objects of different sizes. However, the original c2f module contains multiple branches, each corresponding to feature maps of different depths. One of the branches has the feature of 1024 channels, which undoubtedly increases the complexity and processing overhead of the model. Although a large number of channels can capture rich feature information, it also introduces unnecessary computational overhead, especially when dealing with low-resolution images and small objects. By removing this component, we are able to reduce the size of the model, reduce resource requirements, simplify the model structure, and enable 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 can effectively identify and locate objects of different sizes, especially small objects, while controlling the overall computational cost. This simplification strategy enhances the utility of the model without compromising its detection performance, making it more suitable for scenarios that require real-time processing and limited resources. This is particularly beneficial in environments that process large amounts of data or have limited resources.

[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 Swin Transformer to construct multi-scale feature representations, 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 the 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 from the bottom of the image, thereby effectively understanding complex visual objects in deep networks. The structural diagram of Swin Transformer is shown in Figure 7 As shown in . The moving window mechanism can effectively calculate self-attention within non-overlapping local windows while ensuring smooth message communication across windows. 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 positioning accuracy of the model in tasks such as small target detection. The computational complexity of window-based multiple self-attention (W-MSA) in 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 Formula 9.

[0111]

[0112] Among them, 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. Swin Transformer significantly improves the detection accuracy of the model for small targets (such as blood cells) by integrating relative position information into the calculation of attention weights.

[0113] Specifically, the Swin Transformer works with the c2f module, where the task of the c2f module is initial feature fusion. Then, the Swin Transformer further refines and enriches the multi-scale features, enhancing the recognition ability of the model. This combination ensures that the model can accurately focus on the multi-scale feature map, especially when identifying small targets (such as blood cells), thereby greatly improving the accuracy and efficiency of detection.

[0114] In step S4, a multi-scale detection strategy is adopted, and the adjusted fused feature map is used to use three different scale detection heads to detect targets corresponding to the large, medium and small scale information in the image. Among them, large, medium and small targets refer to objects occupying large, moderate and small areas in the image respectively. The specially designed detection head is used to effectively identify targets of different scales to improve the 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 with a size larger than 8x8. The detection feature map size corresponding to P4 / 16 is 40×40, which is used to detect medium targets with a size 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 larger 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 should be further explained that in step S5, anchor box regression and classification probability calculation are performed after the target is detected. 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.

[0122]

[0123] P class =σ(C) Formula 13

[0124] where Δx B and Δy B are regression parameters for 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 respectively, σ 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 to improve the performance of the model, especially in small object detection and solving sample imbalance.

[0126] L total =L WDLoss +λL DFL Formula 14

[0127] Where L total is the total regression loss, L WDLoss For WD Loss, L DFL is DFL, and λ is the balance factor. After specific experimental data comparison, λ is finally set to 1.5. After calculating the loss function, the model will use the calculated loss value to adjust its internal parameters through the back propagation algorithm 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 tiny 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 extracted 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 the WDLoss function: The WDLoss function calculates the prediction box The Wasserstein distance between the ground truth box b and 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 real and predicted bounding boxes, so that it can still provide effective gradient information when there is almost no overlap or no overlap between the predicted box and the real box, making model training more efficient. The advantage of this function is that it provides a smoother gradient and is particularly suitable for processing small object detection situations with almost no overlap. In the case where small objects are difficult to accurately match the actual annotation box, by calculating the normalized Wasserstein distance between Gaussian distributions, the WDLoss function can more accurately measure the difference between the predicted box and the real box. As a result, the accuracy of small object detection is improved. In the blood cell detection model, the application process of the WDLoss function includes starting from the input image, performing feature extraction, generating prediction boxes in sequence, and finally optimizing the loss function by calculating the Wasserstein distance between the predicted box and the real box, thereby improving the accuracy and stability of detecting small objects, which is very important for tasks such as blood cell detection. In addition, this method also provides useful experience for other computer vision tasks that need to process small objects.

[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. The 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 formula 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 Formula 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 assessing the overall health of an individual, assisting in the diagnosis of various diseases and monitoring treatment effects. 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 to obtain more comprehensive information support in diagnosis and treatment decisions, and has a positive effect on promoting clinical diagnosis and pathological research. For specific blood count results, see Fig. 9 .

[0146] It should be noted that the experiment was completed using a 64-bit Windows operating system, and the experiment used mAP, accuracy, and recall as evaluation indicators. The specific experimental configuration is shown in Table 1.

[0147] Table 1 Experimental configuration information

[0148]

[0149] It should be noted that in order to evaluate the effectiveness of the blood cell detection model in blood cell detection, we conducted a rigorous performance evaluation of the model. By comparing the performance of the model before and after the improvement of each key indicator, we confirmed the effectiveness and advantages of the blood cell detection model. We conducted experiments on the architecture of the present invention for up to 300 training cycles (epochs) on the BCCD dataset. Fig.10 The following figure 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, eventually reaching a stable state and producing the best results. The best results of the model are shown in Figure 1. Fig.11 shown.

[0150] This technical solution is compared with other test models. The model performance comparison results are shown in Table 2 and Fig.12 , Fig.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 the technical solution has achieved significant improvements in multiple performance indicators by comparing the results with other test models, and these results have surpassed the performance of previous research models. This shows that the detection algorithm proposed by the present invention is superior to similar algorithms, and the average precision (mAP) is improved by 1.6 percentage points compared to the YOLOv8 model.

[0154] In order to further evaluate the effectiveness of the various improvements of the present invention, we used YOLOv8n as the benchmark model for an ablation study to comprehensively analyze the model. We removed or replaced SPD-Conv, Swin Transformer attention mechanism, simplified c2f module, and WDLoss function in turn to observe the impact on model performance. A represents the SPD-Conv layer, B represents the Swin Transformer attention mechanism, C represents the simplified 1024-channel part in the c2f module, and D represents the use of the WDLoss function instead of the original loss function. The results of the ablation study 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 accuracy of blood cell detection, with the increase in mAP ranging from 0.6% to 1.6%. After comprehensive improvements, mAP increased by 1.6%, with the best improvement effect. These results not only verify the effectiveness of each improvement step, but also highlight the excellent performance of the present invention in blood cell detection tasks. The model of the present invention combines a variety of innovative technologies, has made breakthrough progress in the academic field, 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 are described in detail above with reference to the accompanying drawings, however, the present invention is not limited to these exemplary embodiments. Within the knowledge scope of those skilled in the art, various forms of optimization and modification can be made 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, the model comprising 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 data set 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 the 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, and a simplified c2f module is used to fuse features at each scale. Subsequently, the Swin Transformer is used to construct a multi-scale feature representation, so that the model can focus on the 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, and a multi-scale detection strategy is adopted. The adjusted and fused feature map is used to detect large, medium and small targets in the image through three detection heads of different scales, and finally the detection frame of blood cells is obtained; S5. Iterative training: setting the loss function of the blood cell detection model and iteratively training 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 convolution layer and multiple SPD-Conv convolution 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 removed, and the remaining feature maps are upsampled, convolved, and concatenated to form the final fused feature map; Then, Swin Transformer is 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 Formula 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, and 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, anchor box regression and classification probability calculation are performed after the target is detected. 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 regression parameters for 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 respectively, σ 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 Where L total is the total regression loss, L WDLoss For WD Loss, 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 and 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: 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, and 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