Classification method of urine red blood cells based on supervised contrastive learning

By constructing an SRRN network model based on supervised contrastive learning, combined with Euclidean distance and cross-entropy loss function, the problem of difficulty in traditional urine red blood cell classification is solved, efficient and accurate identification of urine red blood cells is achieved, and classification accuracy and efficiency are improved.

CN114863425BActive Publication Date: 2024-10-29HARBIN ENG UNIV
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202210346555.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-31
Publication Date
2024-10-29
Estimated Expiration
2042-03-31

AI Technical Summary

Technical Problem

Traditional urine red blood cell morphological analysis relies on manual inspection, which takes a long time and is difficult to meet the physical examination needs of kidney disease patients in areas where professional doctors are lacking. Digital image processing algorithms are difficult to achieve accurate classification of urine red blood cells.

Method used

A method based on supervised contrastive learning was used to construct an SRRN network model, combined with ResNet-50 and VGG-19 networks, and the Euclidean distance loss function and cross-entropy loss function were used to extract and classify urine red blood cell images, and the TTA strategy was used to improve the model accuracy.

Benefits of technology

It improves the accuracy and efficiency of urine red blood cell classification and achieves accurate identification of urine red blood cells. Especially when the data set is small and the image is unclear, the recall rate and precision rate of the classification results are significantly improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114863425B_ABST
    Figure CN114863425B_ABST
Patent Text Reader

Abstract

The present invention provides a method for classifying urine red blood cells based on supervised contrastive learning, comprising the following steps: step one: collecting and expanding a data set; step two: constructing an SRRN feature extraction network model based on a ResNet-50 convolutional neural network; step three: constructing a loss function; step four: training the SRRN feature extraction network; step five: training a classifier; and step six: testing the model. The present invention improves the accuracy of a test set by 0.36% after training with an SRRN network model; improves the accuracy of a test set by 0.49% after training with a contrast loss function based on Euclidean distance; improves the accuracy of a model on a test set by 0.71% after fine-tuning the classifier with a weight penalty mechanism; and uses a TTA strategy in the model testing phase, improves the accuracy of the model on the test set by 0.13%, and finally the accuracy of the present invention reaches 92.39%.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of medical image processing, and in particular relates to a method for classifying urine red blood cells based on supervised contrast learning. Background Art

[0002] Patients with kidney disease often have hematuria, and the morphology of red blood cells in urine can more accurately reflect the type of kidney disease. The diagnosis of hematuria must first distinguish whether it is glomerular hematuria or non-glomerular hematuria. Glomerular hematuria is mainly composed of abnormal red blood cells in urine; non-glomerular hematuria is generally normal red blood cells in urine. The morphological analysis of red blood cells in urine is known as "in vitro renal biopsy" and has important clinical significance in the localization diagnosis of hematuria. Traditional morphological analysis of red blood cells in urine mainly relies on manual observation of the morphological changes of red blood cells in urine sediment and recording of relevant indicators. Therefore, the traditional manual inspection method has a long inspection cycle on the one hand, and on the other hand, it is difficult to meet the physical examination needs of patients with kidney disease in areas where there is a shortage of professional physicians.

[0003] In response to the current demand for intelligent classification of urine red blood cells and the difficulty of traditional digital image processing algorithms to achieve accurate classification of urine red blood cells, the present invention utilizes relevant knowledge of deep learning to improve the accuracy and efficiency of urine red blood cell classification. Summary of the invention

[0004] The technical problem solved by the present invention is: to provide a urine red blood cell classification method to improve the classification accuracy and efficiency, apply the current advanced science and technology to the field of medical image processing, and reduce the burden on doctors.

[0005] The technical solution adopted by the present invention is:

[0006] A method for classifying urine red blood cells based on supervised contrastive learning comprises the following steps:

[0007] Step 1: Collect urine red blood cell images to construct training sets and test sets; collect urine red blood cell images, perform category annotation, and randomly divide the collected images into training sets and test sets according to proportion; the collected urine red blood cell images are divided into normal red blood cells, ring red blood cells, shadow-shaped red blood cells, crescent-shaped red blood cells, donut-shaped red blood cells, shrunken red blood cells, acanthoid red blood cells, lateral red blood cells and erect red blood cells according to their morphological characteristics, and data enhancement preprocessing is performed on the categories with less data in the training set, and the data enhancement preprocessing includes rotation and flipping to obtain a larger number of training images;

[0008] Step 2: Build an SRRN network based on ResNet-50; on the basis of the ResNet-50 convolutional neural network, remove the bottom 5 convolutional layers and replace them with an upsampling module, which can double the spatial resolution of the image. The upsampling module includes a convolution kernel, two residual blocks and a sub-pixel convolution module;

[0009] Step 3: Construct a loss function; add Euclidean distance loss to the supervised contrast loss, use the intercepted VGG-19 network to extract image feature vectors, calculate the Euclidean distance between each image feature vector, and calculate the loss value based on this Euclidean distance;

[0010] Step 4: Train the SRRN network model; set the training parameters of the SRRN network model, use the cifar10 dataset to train the SRRN network model, and train the SRRN feature extraction network in two stages: in the first stage, use the traditional supervised contrast loss function to train the model; in the second stage, use the contrast loss based on Euclidean distance and the supervised contrast loss function to jointly train the feature extraction network until convergence;

[0011] Step 5: Train the classifier. Use the training set prepared in step 1 to train the classifier. The training of the classifier is divided into two stages: the first stage uses the cross entropy loss function to train the classifier until convergence; the second stage fine-tunes the classifier model according to the weights, where the weights are determined by the classification probability values ​​of each category, and higher loss weights are set for categories that are more difficult to classify.

[0012] Step 6: Test the model; test the SRRN network model and classifier model trained in steps 4 and 5. The test model uses the TTA strategy to test the image.

[0013] The present invention also includes the following technical features:

[0014] Furthermore, in the step one, the ratio of the training set to the test set is 4:1; the training set and its corresponding labels are used to train the classifier, and the test set and its corresponding labels are used to test the performance of the obtained urine red blood cell recognition and classification model, and all the crescent-shaped red blood cells and shrunken red blood cells in the training set are horizontally flipped to double the data, and all the spinous red blood cells in the training set are rotated 90 degrees, 180 degrees, and 270 degrees to triple the data.

[0015] Furthermore, the convolution kernel size of the first convolution kernel in the step 2 is 9, the channel is 64, and the step size is 1. The residual module is composed of two convolution kernels, the convolution kernel size is 3, the channel is 64, and the step size is 1. The sub-pixel convolution module is composed of a convolution kernel and a sub-pixel cleaning module. A convolution kernel with a convolution kernel size of 3, a channel of 64, and a step size of 1 is added after the upsampling module.

[0016] Furthermore, the loss function calculation formula in step 3 is:

[0017] L=L sup +εL euc ;

[0018] Where L sup It represents the contrast loss function, L euc Represents the contrast loss function based on Euclidean distance. ε is a positive parameter with a value of 0.43. It controls the proportion of the contrast loss function based on Euclidean distance in the total loss. The calculation process of the total loss is divided into three parts: input image preprocessing, calculation of the loss function based on cosine similarity, and calculation of the loss function based on Euclidean distance.

[0019] Input image preprocessing: Assuming a MinBatch contains N images, each image is randomly augmented twice. Two new images will be obtained for each image, and a total of 2N new images will be obtained as subsequent network input for training;

[0020] Calculation of loss function based on cosine similarity: After the image is calculated by the feature extraction network, 2N images will generate 2N feature vectors. Each feature vector is normalized, and each feature vector falls on a hypersphere with a radius of 1. The feature vector obtained is: Z 1 ,Z 2 ,…,Z i ,…,Z j ,…,Z 2N , the loss function formula based on cosine similarity is:

[0021]

[0022]

[0023] Among them, τ is a constant greater than 0 and is set to 0.1. This loss function indicates that for any image i, the greater the cosine similarity of the feature vectors of all images j of the same type as image i, the smaller the loss value; the smaller the sum of the cosine similarities of the feature vectors of images k of different classes, the better; then, a contrast loss function based on Euclidean distance is added to the total loss function, so that the network learns the similarity of the direction and actual distance of the feature vector;

[0024] Calculation of loss value based on Euclidean distance: 2N pictures, after intercepting the VGG-19 network, the feature vector obtained is X 1 ,X 2 ,…,X i ,…,Xj ,…,X 2N , the new loss function is:

[0025]

[0026]

[0027] Among them, dis(X i ,X j ) represents the Euclidean distance between the feature vectors obtained by intercepting the image through the VGG-19 network, and m represents the lower limit threshold of the Euclidean distance between feature vectors of different categories, which is set to 1.

[0028] Furthermore, the step four is specifically as follows: download the cifar10 dataset, uniformly adjust the image to a size of 20×20×3 as the input of the SRRN network, optimize the SRRN network model using a stochastic gradient descent optimizer, set the SRRN network training parameters such as the initial learning rate to 0.0005, the batch size to 64, and the total training rounds to 480, of which the first 300 rounds are the first stage, and the network is trained using a supervised contrast loss function until convergence. The network is trained using the loss function constructed in step three for the next 180 rounds, and the SRRN network model is saved.

[0029] Furthermore, the step 5 is specifically as follows: the classifier is optimized using a stochastic gradient descent optimizer, and the classifier training parameters are set such as the initial learning rate is set to 0.5, the batch size is 256, and the total number of training rounds is 130. The classifier training is divided into two stages. The first stage uses a cross entropy loss function and trains for 100 rounds. The second stage trains for 30 rounds. The loss function formula used is:

[0030]

[0031] Where N is the total number of samples in the test set, K is the number of classification categories, is the indicator function, which is 1 when the sample category label is K, otherwise it is 0. nk is the probability of the sample being in the Kth class, σ is a positive parameter, set to 0.3.

[0032] Furthermore, the model prediction in step six uses the TTA strategy to perform a 180-degree rotation data augmentation operation on the predicted sample, and the original image and the image after data augmentation are sent to the feature extraction network and the classifier network to obtain different results. The results of the original image and the image after data augmentation are summed as the final prediction probability.

[0033] Compared with the prior art, the present invention has the following beneficial effects:

[0034] 1. The present invention combines supervised contrastive learning and transfer learning to solve the problem of small urine red blood cell data sets and difficult classification. The cifar10 data set is used to train the weights of the feature extraction module for subsequent extraction of urine red blood cell features. The present invention evaluates the classification results of nine types of urine red blood cells in the urine red blood cell test set, including normal red blood cells, ring red blood cells, shadow-shaped red blood cells, crescent-shaped red blood cells, doughnut-shaped red blood cells, shrunken red blood cells, thorn-shaped red blood cells, lateral red blood cells, and upright red blood cells. The accuracy of the training-based ResNet-50 network contrastive learning model is 90.70%, and the recall rate and precision rate of each category are shown in Table 1.

[0035] Table 1 (Unit: %)

[0036] RBC-1 RBC-2 RBC-3 RBC-4 RBC-5 RBC-6 RBC-7 RBC-8 RBC-9 Recall 93.92 97.14 75.1 77.32 97.37 88.79 59.57 93.19 99.48 Accuracy 73.54 85.43 92.68 57.69 91.93 89.62 58.33 99.7 93.69

[0037] 2. Aiming at the characteristics of small size and unclear image of urine red blood cells, the present invention proposes a SRRN network model. This network is a modification based on the ResNet-50 convolutional neural network. A sub-pixel convolution module is added to the bottom of the ResNet-50 network to make it more suitable for classification tasks of small images (image spatial resolution size 16 to 24). After using the SRRN network structure, the accuracy rate obtained on the urine red blood cell test set is 91.06%, and the recall rate and precision rate of each category are shown in Table 2.

[0038] Table 2 (Unit: %)

[0039] RBC-1 RBC-2 RBC-3 RBC-4 RBC-5 RBC-6 RBC-7 RBC-8 RBC-9 Recall 84.46 94.86 78.66 82.47 94.74 84.11 55.32 95.31 98.97 Accuracy 82.24 88.77 91.28 60.61 91.72 92.78 44.83 99.71 87.27

[0040] 3. The loss function of traditional supervised contrastive learning uses cosine similarity to measure the similarity between feature vectors. The loss function in the present invention is based on supervised contrastive learning and adds Euclidean distance. Euclidean distance reflects the absolute difference in the numerical value of feature vectors, while cosine similarity reflects the relative difference in the direction of feature vectors. Examine the similarity of urine red blood cell image features from many aspects. Let the model learn more detailed features. The Euclidean distance between the pixels of each image alone will cause the model to over-learn the pixel differences between images. In order to make the model pay more attention to the differences between inherent detail features. The present invention calculates the Euclidean distance between images not by directly calculating the Euclidean distance between image pixels, but by extracting urine red blood cell image features using the intercepted VGG-19 network, and calculating the Euclidean distance between feature maps extracted by the intercepted VGG-19 network. The accuracy of the model trained with the contrast loss function based on Euclidean distance reached 91.55% on the test set, and the recall and precision of each category are shown in Table 3.

[0041] Table 3 (Unit: %)

[0042] RBC-1 RBC-2 RBC-3 RBC-4 RBC-5 RBC-6 RBC-7 RBC-8 RBC-9 Recall 87.16 93.71 75.1 84.54 94.74 84.11 55.32 96.69 99.48 Accuracy 87.16 85.86 91.79 60.74 92.31 92.78 49.06 99.62 88.53

[0043] 4. The present invention introduces a weight penalty mechanism in the cross entropy loss function to address the low precision and recall rates of some categories. After the classifier is trained to convergence, the weights corresponding to different categories are determined according to the difficulty of classifying different categories by the network, and higher loss weights are set for more difficult classification tasks. The difficulty of classifying different categories is measured by the probability values ​​corresponding to each category during the training process. After the weight penalty mechanism is introduced, the accuracy of the entire model on the urine red blood cell test set is 92.26%, and the recall and precision of each category are shown in Table 4.

[0044] Table 4 (Unit: %)

[0045] RBC-1 RBC-2 RBC-3 RBC-4 RBC-5 RBC-6 RBC-7 RBC-8 RBC-9 Recall 87.16 93.14 79.84 84.54 94.08 84.11 55.32 97.24 99.48 Accuracy 87.76 88.11 91.4 64.06 94.08 92.78 50.98 99.53 88.94

[0046] 5. In the present invention, the spatial resolution of the input image is small, the pooling layer is used less in the SRRN network model, and the rotation invariance of the feature extraction network is poor. Therefore, the TTA strategy is used in the test model stage. The accuracy of the entire model on the urine red blood cell test set is 92.39%, and the recall rate and precision rate of each category are shown in Table 5.

[0047] Table 5 (Unit: %)

[0048] RBC-1 RBC-2 RBC-3 RBC-4 RBC-5 RBC-6 RBC-7 RBC-8 RBC-9 Recall 83.78 92.0 77.47 90.72 95.39 87.85 70.21 97.15 98.45 Accuracy 88.57 88.95 92.89 63.31 94.77 92.16 51.56 99.81 90.09 BRIEF DESCRIPTION OF THE DRAWINGS

[0049] Figure 1 This is a sample of urine red blood cells;

[0050] Figure 2 It is the SRRN network model structure diagram and data flow;

[0051] Figure 3 It is the loss function calculation method for the second stage of SRRN network model training;

[0052] Figure 4 A flow chart for testing the TTA strategy;

[0053] Figure 5 This is the confusion matrix obtained by combining supervised contrastive learning with transfer learning to classify urine red blood cells.

[0054] Figure 6 This is the confusion matrix obtained using the SRRN network model on the urine red blood cell test set data;

[0055] Figure 7 This is the confusion matrix obtained by the SRRN network model on the urine red blood cell test set after adding the Euclidean distance loss;

[0056] Figure 8 This is the confusion matrix obtained by training the classifier using the method in step 5;

[0057] Fig. 9 This is the confusion matrix obtained using the TTA strategy when testing the model;

[0058] Fig.10 Flowchart of the urine red blood cell classification method based on supervised contrastive learning. DETAILED DESCRIPTION

[0059] In order to specifically illustrate the features and advantages of the present invention, specific implementation modes of the present invention are further described below in conjunction with the accompanying drawings.

[0060] Embodiment 1:

[0061] A method for classifying urine red blood cells based on supervised contrastive learning comprises the following steps:

[0062] Step 1: Collect and expand the data set; collect urine red blood cell images, perform category annotation, and divide the collected images into training sets and test sets according to a certain ratio; the collected urine red blood cell images are divided into nine categories according to their morphological characteristics: normal red blood cells, ring red blood cells, shadow-shaped red blood cells, crescent-shaped red blood cells, donut-shaped red blood cells, shrunken red blood cells, acanthoid red blood cells, lateral red blood cells, and upright red blood cells. The data enhancement preprocessing for the categories with less data in the training set mainly includes rotation and flipping to obtain more training images;

[0063] Step 2: Construct a feature extraction network model. Based on the ResNet-50 convolutional neural network, the convolutional neural network structure is modified to address the low resolution and unclear image details of urine red blood cell images. A sub-pixel convolution module is added to the bottom of the ResNet-50 convolutional neural network to enlarge the image in order to extract more accurate features. This network model is suitable for small-resolution images and is named SRRN (Small Resolution Residual Network).

[0064] Step 3: Construct a loss function; add Euclidean distance loss to the supervised contrast loss, use the intercepted VGG-19 network to extract image feature vectors, calculate the Euclidean distance between each image feature vector, and calculate the loss value based on this Euclidean distance;

[0065] Step 4: Train the SRRN network model; set the training parameters of the SRRN network model, use the cifar10 dataset to train the SRRN network model, and train the SRRN feature extraction network in two stages. In the first stage, the traditional supervised contrast loss function is used to train the model. In the second stage, the contrast loss based on Euclidean distance and the supervised contrast loss function are used to jointly train the feature extraction network until convergence;

[0066] Step 5: Train the classifier. Use the urine red blood cell training set prepared in step 1 to train the classifier. The training of the classifier is divided into two stages. In the first stage, the cross entropy loss function is used to train the classifier until convergence. In the second stage, the classifier model is fine-tuned according to the weights, where the weights are determined by the classification probability values ​​of each category. Set a higher loss weight for the categories that are more difficult to classify.

[0067] Step 6: Test the model; test the SRRN network model and classifier model trained in steps 4 and 5, and use the test set prepared in step 1 to test the actual learning ability of the model. The test model uses the Test Time Augmentation (TTA) strategy to test the image.

[0068] The present invention also includes such structural features:

[0069] 1. The data set in step 1 is randomly divided into a training set and a test set at a ratio of 4:1. The urine red blood cell image training set and the training set labels are used to train the classifier, and the urine red blood cell test set and its corresponding labels are used to test the performance of the obtained urine red blood cell recognition and classification model. All the crescent-shaped red blood cells and wrinkled red blood cells in the training set are horizontally flipped, and all the thorn-shaped red blood cells in the training set are rotated 90 degrees, 180 degrees, and 270 degrees.

[0070] 1. The data set of step 1 is randomly divided into a training set and a test set at a ratio of 4:1. The urine red blood cell image training set and the training set labels are used to train the classifier, and the urine red blood cell test set and its corresponding labels are used to test the performance of the obtained urine red blood cell recognition and classification model. All the crescent-shaped red blood cells and wrinkled red blood cells in the training set are horizontally flipped, and all the thorn-shaped red blood cells in the training set are rotated 90 degrees, 180 degrees, and 270 degrees. The specific operation is: the formed elements in the urine are obtained by centrifugation, and are called urine sediment. The initial image of the urine sediment is collected using a microscope, and all the urine red blood cell images are selected. In this way, the data set required for the experiment is preliminarily obtained. Then the data is randomly divided into a urine red blood cell image training set and a urine red blood cell image test set at a ratio of about 4:1. For some categories with less data in the training set, such as the fourth category of crescent-shaped red blood cells and the seventh category of thorn-shaped red blood cells, data enhancement is used to expand the samples. The main methods of data enhancement are horizontal flipping and rotation (90 degrees, 180 degrees, 270 degrees).

[0071] 2. The step 2 constructs the feature extraction network model SRRN, which is more suitable for images with smaller spatial resolution such as urine red blood cells. On the basis of the ResNet-50 convolutional neural network, the bottom 5 convolutional layers are removed and replaced with an upsampling module, which can double the spatial resolution of the image. The upsampling module includes a convolution kernel, two residual blocks and a sub-pixel convolution module. The specific operation is: the SRRN network replaces the bottom part of the convolution of the ResNet-50 convolutional neural network with an upsampling module. The upsampling module includes convolutional layers and sub-pixel convolutions. This module is responsible for amplifying the input image to facilitate the subsequent network to extract fine-grained features of the image.

[0072] 3. The loss function used by the SRRN network model in the second stage in step 3 is the weighted sum of the supervised contrast loss function and the contrast loss function based on the Euclidean distance. The specific method of calculating the contrast loss function based on the Euclidean distance is: use the intercepted VGG-19 network to extract the feature vector of the image, calculate the Euclidean distance between the feature vectors, and calculate the contrast loss based on this Euclidean distance. The intercepted VGG-19 network is only used to calculate image features, and is not added as a submodule to the SRRN network model, and the module is no longer used in the subsequent inference process.

[0073] 4. The training of the SRRN network model in step 4 is divided into two stages. The first 300 rounds are the first stage, using a supervised contrast loss function to train the network, and the last 180 rounds use the loss function constructed in step 3 to train the network.

[0074] 5. The training of the classifier in step 5 is divided into two stages. The first stage uses the cross entropy loss function to train the classifier until convergence. The second stage introduces a weight penalty mechanism in the cross entropy loss function. The weight of each category is determined by the difficulty of classification. The specific operation is: use the SRRN network model weights trained in step 4. Input the urine red blood cell training set collected in step 1 into the SRRN network model, and output it as a 2048-dimensional feature vector. Input the obtained feature vector and its label information into the cross entropy loss function. After training the classifier until convergence, adjust the weights corresponding to each category in the loss function, and continue training until the model converges.

[0075] 6. The model prediction in step six uses the TTA strategy, performs a 180-degree rotation data enhancement operation on the prediction sample, sends the original image and the data-enhanced image to the feature extraction network and the classifier network to obtain different results (the probability of being classified into each category), and sums the results of the original image and the data-enhanced image as the final prediction probability.

[0076] Embodiment 2:

[0077] The specific steps of the urine red blood cell classification method based on supervised contrast learning of the present invention are:

[0078] Step 1: Use a microscope to collect the initial image of urine sediment, collect urine red blood cell data sets, annotate data category information according to cell morphological characteristics, and divide the training set and test set. The collected urine red blood cells are divided into nine categories: normal red blood cells, ring red blood cells, shadow red blood cells, crescent-shaped red blood cells, donut-shaped red blood cells, shrunken red blood cells, thorn-shaped red blood cells, side red blood cells, and upright red blood cells. Figure 1 As shown in the figure. Since the number of crescent-shaped red blood cells, wrinkled red blood cells, and acanthocytes is small, data enhancement is used for these three types of red blood cells to expand the data set. The crescent-shaped red blood cells and wrinkled red blood cells are horizontally flipped to double the data, and the acanthocytes are rotated 90 degrees, 180 degrees, and 270 degrees to triple the data.

[0079] Step 2: If Figure 2 Shown is the SRRN network model structure diagram and data flow. Figure 2 The STAGE1 module is used to replace some convolution blocks in the ResNet-50 convolutional neural network. Figure 2The STAGE1 module in is an image upsampling module, which mainly includes two residual modules and a sub-pixel convolution module. The first convolution kernel has a kernel size of 9, 64 channels, and a stride of 1. The residual module consists of two convolution kernels, both with a kernel size of 3, 64 channels, and a stride of 1. The sub-pixel convolution module is mainly used to enlarge the image size. It consists of a convolution kernel and a sub-pixel cleaning module. A convolution kernel with a kernel size of 3, 64 channels, and a stride of 1 is added after the upsampling module. Figure 6 This is the confusion matrix obtained using the SRRN network model on the urine red blood cell test set data.

[0080] Step 3: The loss function used by the feature extraction network in the second stage is calculated as: L = L sup +εL euc . Where L sup It represents the contrast loss function, L euc represents the contrast loss function based on Euclidean distance, where ε is a positive parameter with a value of 0.43, which controls the proportion of the contrast loss function based on Euclidean distance in the total loss. The calculation process of the total loss is as follows Figure 3 As shown, it is mainly divided into three parts: input image preprocessing, calculation of loss function based on cosine similarity and calculation of loss function based on Euclidean distance.

[0081] 1. Input image preprocessing: Assume that a MinBatch contains N images. Perform data augmentation (random cropping, flipping, etc.) twice on each image. Two new images will be obtained for each image, and a total of 2N new images will be obtained as subsequent network input for training.

[0082] 2. Calculation of loss function based on cosine similarity: After the image is calculated by the feature extraction network, 2N images will generate 2N feature vectors, and each feature vector is normalized. In this way, each feature vector falls on a hypersphere with a radius of 1. The obtained feature vector is: Z 1 ,Z 2 ,…,Z i ,…,Z j ,…,Z 2N The loss function formula based on cosine similarity is:

[0083]

[0084]

[0085] Among them, τ is a constant greater than 0 and is set to 0.1. This loss function represents all pictures j of the same type as picture i for any picture i. The greater the cosine similarity of the feature vectors of pictures i and j, the smaller the loss value; the smaller the sum of the cosine similarities of the feature vectors of pictures k of different classes, the better. This loss function can only enable the network to learn the similarity of the direction of the feature vector, but simply measuring the similarity of the feature vector from the direction is one-sided. Therefore, a contrast loss function based on Euclidean distance is added to the total loss function, so that the network can learn the similarity of the direction and actual distance of the feature vector.

[0086] 3. Calculation of loss value based on Euclidean distance: 2N pictures, after intercepting the VGG-19 network, the feature vector obtained is X 1 ,X 2 ,…,X i ,…,X j ,…,X 2N . The new loss function is:

[0087]

[0088]

[0089] Among them, dis(X i ,X j ) represents the Euclidean distance between the feature vectors obtained by intercepting the VGG-19 network. m represents the lower limit threshold of the Euclidean distance between feature vectors of different categories, which is set to 1. Figure 7 This is the confusion matrix obtained by the SRRN network model on the urine red blood cell test set after adding the Euclidean distance loss.

[0090] Step 4: Train the feature extractor. Download the cifar10 dataset and resize the images to 20×20×3 as the input of the SRRN network. The SRRN network model is optimized using the stochastic gradient descent (SGD) optimizer. The SRRN network training parameters are set such as the initial learning rate is set to 0.0005, the batch size is 64, and the total number of training rounds is 480. The first 300 rounds are the first stage, and the network is trained to converge using the supervised contrast loss function. The network is trained using the loss function constructed in step 3 for the next 180 rounds, and the SRRN network model is saved. Figure 8 This is the confusion matrix obtained on the urine red blood cell test set after using the new loss function.

[0091] Step 5: Train the classifier. The classifier is optimized using the stochastic gradient descent (SGD) optimizer. The classifier training parameters are set such as the initial learning rate is set to 0.5, the batch size is 256, and the total number of training rounds is 130. The classifier training is divided into two stages. The first stage uses the cross entropy loss function and trains for 100 rounds. The second stage trains for 30 rounds, and the loss function formula used is:

[0092]

[0093] Where N is the total number of samples in the test set, and K is the number of classification categories. is an indicator function, which is 1 when the sample category label is K, otherwise it is 0. nk is the probability of a sample in the Kth class. σ is a positive parameter, set to 0.3. Figure 8 Confusion matrix on the urine red blood cell test set after training the classifier for fine-tuning.

[0094] Step 6: Test model, TTA strategy testing process is as follows Figure 4 As shown. The feature extraction model is combined with the classifier model as a test model. The image of the urine red blood cell test set and the image after data enhancement are input into the test model respectively. The predicted probabilities corresponding to the two images are obtained, and the weighted sum of the two is obtained to obtain the final probability. The weight of the original image is 3, and the weight after image enhancement is 1. Fig. 9 This is the confusion matrix on the urine red blood cell test set after using the TTA strategy when testing the model.

[0095] In summary, the present invention is in the field of medical image processing, and is a classification method for urine red blood cells based on supervised contrast learning. Step one: collect and expand the data set; step two: construct an SRRN feature extraction network model based on the ResNet-50 convolutional neural network; step three: construct a loss function; step four: train the SRRN feature extraction network; step five: train the classifier; step six: test the model; the present invention proposes that the SRRN network model is constructed on the basis of the ResNet-50 network, which is more suitable for images with small spatial resolution. Compared with the ResNet-50 network model, the accuracy of the SRRN network model on the test set after training is improved by 0.36%; the present invention adds a contrast loss function based on Euclidean distance to the supervised contrast loss function, measures the similarity between features from the two aspects of the direction and absolute distance of the feature vector, and the accuracy of the SRRN network model after training with the contrast loss function based on Euclidean distance on the test set is improved by 0.49%; the accuracy of the model after fine-tuning the classifier with a weight penalty mechanism on the test set is improved by 0.71%; the present invention uses a TTA strategy in the model testing stage, and the accuracy of the model on the test set is improved by 0.13%. Finally, the accuracy of the present invention reaches 92.39%.

Claims

1. A method for classifying urine red blood cells based on supervised contrastive learning, characterized in that: The following steps are involved: Step 1: Collect urine red blood cell images to construct training sets and test sets; Collect urine red blood cell images, perform category annotation, and randomly divide the collected images into a training set and a test set according to a proportion; the collected urine red blood cell images are divided into normal red blood cells, ring red blood cells, shadow-shaped red blood cells, crescent-shaped red blood cells, donut-shaped red blood cells, shrunken red blood cells, acanthoid red blood cells, lateral red blood cells, and erect red blood cells according to their morphological characteristics, and perform data enhancement preprocessing on the categories with less data in the training set, and the data enhancement preprocessing includes rotation and flipping to obtain a larger number of training images; Step 2: Build a SRRN network based on ResNet-50; Based on the ResNet-50 convolutional neural network, the bottom five convolutional layers are removed and replaced with an upsampling module, which can double the spatial resolution of the image. The upsampling module includes a convolution kernel, two residual blocks and a sub-pixel convolution module; Step 3: Construct a loss function; add Euclidean distance loss to the supervised contrast loss, use the intercepted VGG-19 network to extract image feature vectors, calculate the Euclidean distance between each image feature vector, and calculate the loss value based on this Euclidean distance; Step 4: Train the SRRN network model; set the training parameters of the SRRN network model, use the cifar10 dataset to train the SRRN network model, and train the SRRN feature extraction network in two stages: in the first stage, use the traditional supervised contrast loss function to train the model; in the second stage, use the contrast loss based on Euclidean distance and the supervised contrast loss function to jointly train the feature extraction network until convergence; Step 5: Train the classifier. Use the training set prepared in step 1 to train the classifier. The training of the classifier is divided into two stages: In the first stage, the cross entropy loss function is used to train the classifier until convergence. In the second stage, the classifier model is fine-tuned according to the weights, where the weights are determined by the classification probability values ​​of each category, and higher loss weights are set for categories that are more difficult to classify; Step 6: Test the model; test the SRRN network model and classifier model trained in steps 4 and 5. The test model uses the TTA strategy to test the image.

2. The method for classifying urine red blood cells based on supervised contrastive learning according to claim 1, characterized in that: In the step 1, the ratio of the training set to the test set is 4:1; the training set and its corresponding labels are used to train the classifier, and the test set and its corresponding labels are used to test the performance of the obtained urine red blood cell recognition and classification model, and all the crescent-shaped red blood cells and shrunken red blood cells in the training set are horizontally flipped to double the data, and all the spinous red blood cells in the training set are rotated 90 degrees, 180 degrees, and 270 degrees to triple the data.

3. The method for classifying urine red blood cells based on supervised contrastive learning according to claim 1, characterized in that: The convolution kernel size of the first convolution kernel in the step 2 is 9, the channel is 64, and the step size is 1. The residual module consists of two convolution kernels, both of which have a convolution kernel size of 3, a channel of 64, and a step size of 1. The sub-pixel convolution module consists of a convolution kernel and a sub-pixel cleaning module. A convolution kernel with a convolution kernel size of 3, a channel of 64, and a step size of 1 is added after the upsampling module.

4. The method for classifying urine red blood cells based on supervised contrastive learning according to claim 1, characterized in that: The loss function calculation formula in step 3 is: L=L sup +εL euc ; Where L sup It represents the contrast loss function, L euc Represents the contrast loss function based on Euclidean distance. ε is a positive parameter with a value of 0.

43. It controls the proportion of the contrast loss function based on Euclidean distance in the total loss. The calculation process of the total loss is divided into three parts: input image preprocessing, calculation of the loss function based on cosine similarity, and calculation of the loss function based on Euclidean distance. Input image preprocessing: Assuming a MinBatch contains N images, each image is randomly augmented twice. Two new images will be obtained for each image, and a total of 2N new images will be obtained as subsequent network input for training; Calculation of loss function based on cosine similarity: After the image is calculated by the feature extraction network, 2N images will generate 2N feature vectors. Each feature vector is normalized and each feature vector falls on a hypersphere with a radius of 1. The feature vectors obtained are: Z1, Z2, ..., Z i ,…,Z j ,…,Z 2N , the loss function formula based on cosine similarity is: Among them, τ is a constant greater than 0 and is set to 0.

1. This loss function indicates that for any image i, the greater the cosine similarity of the feature vectors of all images j of the same type as image i, the smaller the loss value; the smaller the sum of the cosine similarities of the feature vectors of images k of different classes, the better; then, a contrast loss function based on Euclidean distance is added to the total loss function, so that the network learns the similarity of the direction and actual distance of the feature vector; Calculation of loss value based on Euclidean distance: 2N images, after intercepting the VGG-19 network, the feature vectors obtained are X1,X2,…,X i ,…,X j ,…,X 2N , the new loss function is: Among them, dis(X i ,X j ) represents the Euclidean distance between the feature vectors obtained by intercepting the image through the VGG-19 network, and m represents the lower limit threshold of the Euclidean distance between feature vectors of different categories, which is set to 1.

5. The method for classifying urine red blood cells based on supervised contrastive learning according to claim 1, characterized in that: The step 4 is specifically as follows: download the cifar10 dataset, uniformly adjust the images to a size of 20×20×3 as the input of the SRRN network, optimize the SRRN network model using a stochastic gradient descent optimizer, set the SRRN network training parameters, set the initial learning rate to 0.0005, the batch size to 64, and the total number of training rounds to 480, of which the first 300 rounds are the first stage, and the network is trained using a supervised contrast loss function until convergence. The network is trained using the loss function constructed in step 3 for the next 180 rounds, and the SRRN network model is saved.

6. The method for classifying urine red blood cells based on supervised contrastive learning according to claim 1, characterized in that: The step 5 is as follows: the classifier is optimized using a stochastic gradient descent optimizer, the classifier training parameters are set, the initial learning rate is set to 0.5, the batch size is 256, the total number of training rounds is 130, and the classifier training is divided into two stages. The first stage uses a cross entropy loss function and trains for 100 rounds. The second stage trains for 30 rounds. The loss function formula used is: Where N is the total number of samples in the test set, K is the number of classification categories, is the indicator function, which is 1 when the sample category label is K, otherwise it is 0. nk is the probability of the sample being in the Kth class, σ is a positive parameter, set to 0.

3.

7. The method for classifying urine red blood cells based on supervised contrastive learning according to claim 1, characterized in that: The model prediction in step six uses the TTA strategy, performs a 180-degree rotation data augmentation operation on the predicted sample, sends the original image and the data augmented image to the feature extraction network and the classifier network to obtain different results, and sums the results of the original image and the data augmented image as the final prediction probability.

Citation Information

Patent Citations

  • Multi-task learning cell counting method based on convolutional neural network

    CN109166100A

  • Efficient pedestrian re-identification method based on neural network unsupervised contrast learning

    CN111611880A

  • Face verification method and apparatus based on triplet loss, and computer device and storage medium

    WO2019128367A1

  • Training method and apparatus for OCR recognition model, and computer device

    WO2021139342A1

  • Method for segmenting liver and focus thereof in medical image

    WO2021184817A1