A medical image classification method and device based on improved triplet loss
By improving the triplet loss function, introducing gradient direction and negative sample distance parameters, and combining ResNet and SVM classifiers, the problems of training instability and difficulty in evaluating feature reliability in medical image classification are solved, achieving more efficient and accurate medical image classification.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-21
- Publication Date
- 2026-03-13
AI Technical Summary
Existing medical image classification methods for cancer diagnosis suffer from the problem that while improving classification accuracy, feature reliability is difficult to assess. Traditional triplet loss models are unstable during training and have slow convergence speed.
A medical image classification model based on improved triplet loss is constructed. An angle loss of gradient direction and a negative sample distance parameter are introduced. The convergence of the training process is accelerated by the triplet loss function, and the model is optimized by ResNet and SVM classifiers.
It improves the training efficiency and stability of medical image classification, the extracted features are more discriminative, the classification accuracy is improved, the workload of doctors is reduced, and the development of medical image diagnostic technology is promoted.
Smart Images

Figure CN120613086B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of medical image analysis and processing, and in particular to a medical image classification method and device based on improved triplet loss. Background Technology
[0002] Currently, medical images are crucial for disease diagnosis, but their diverse and heterogeneous forms, types, and features present numerous challenges for classification. While traditional convolutional neural network-based classification methods have improved accuracy, they often focus on convergence to a category, neglecting the analysis of image features and reliability assessment. In cancer research, the significant increase in cancer incidence has made cervical cancer screening a key research direction. Currently, medical image diagnosis primarily relies on pathologists manually examining tissue samples under microscopes—a time-consuming and labor-intensive process highly dependent on physician expertise and experience.
[0003] In medical cell classification, cancer cell image detection has always been a challenge. Due to the heterogeneity of cells in images, convolutional neural networks lack specificity when extracting features, and even with continuous improvements in classification accuracy, the reliability of the features is difficult to assess effectively.
[0004] Feature analysis primarily aims to learn a function or model that maps image features to a low-dimensional Euclidean space, which aligns with the concept of metric learning. In this context, metric learning offers significant advantages over conventional neural network classification methods. It can learn the general concept of distance metrics and perform efficient nearest-neighbor inference within the learned metric space. Traditional metric learning models based on triplet loss suffer from instability during training, slow convergence, and difficulty in designing reasonable margins. Summary of the Invention
[0005] This invention provides a medical image classification method and device based on improved triplet loss to solve the technical problems existing in the prior art.
[0006] The technical solution adopted by this invention to solve the technical problems existing in the prior art is as follows:
[0007] A medical image classification method based on improved triplet loss is proposed. A medical image classification model based on neural network and triplet loss function is constructed. Medical images with category labels are collected. According to the category labels, the medical images of three different categories in the collected medical images are edited into a training set to train the medical image classification model. An angle loss of gradient direction is introduced into the triplet loss function to reduce the gradient direction deviation when calculating the gradient direction, thereby accelerating the convergence of the training process.
[0008] Furthermore, each medical image triplet includes an anchor image, a positive sample image, and a negative sample image;
[0009] First, two images are extracted from the training set. One image is used as the anchor image of the triplet, and the other is used as the positive sample image of the triplet. Then, one image is randomly extracted from the training set in turn as the negative sample image of the triplet to form a medical image triplet. The negative sample images are extracted repeatedly to form several medical image triplets.
[0010] The basic loss function for triplet is defined as follows:
[0011]
[0012] By introducing an angle loss based on the gradient direction into the basic triplet loss function, we obtain the following improved triplet loss function:
[0013]
[0014] In the formula:
[0015] This indicates the computation of feature vectors between two images in feature space. , Distance metric function between them; Let be any two image feature vectors in the feature space;
[0016] Indicates the triplet number;
[0017] Indicates the first Anchor point images in a triplet;
[0018] Indicates the first Positive sample images in a triplet;
[0019] Indicates the first Negative sample images in a triplet;
[0020] express ;
[0021] This is a threshold used to control the difference between positive and negative samples;
[0022] Indicates the first Feature vectors of anchor point images in a triplet;
[0023] Indicates the first Feature vectors of positive sample images in a triplet;
[0024] Indicates the first Feature vectors of negative sample images in a triplet;
[0025] Indicates the first The geometric midpoint of the feature vectors of the anchor image and the positive sample image in each triplet;
[0026] Indicates the first Each triplet's basic loss;
[0027] Indicates the first The loss after introducing the gradient direction angle loss into each triplet;
[0028] This means that when the value within [ ] is greater than zero, that value is taken as the loss; when it is less than zero, the loss is zero.
[0029] Furthermore, a distance parameter between negative samples is introduced into the triplet loss function, which reduces the distance between samples of the same class and increases the distance between samples of different classes.
[0030] Furthermore, each medical image triplet includes an anchor image, a positive sample image, and a pair of negative sample images;
[0031] First, two images are extracted from the training set. One image is used as the anchor image of the triplet, and the other image is used as the positive sample image of the triplet. Then, two images are randomly extracted from the training set in turn as negative sample images of the triplet to form a medical image triplet. The negative sample images are extracted repeatedly to form a number of medical image triplets.
[0032] The pair of negative sample images are referred to as negative sample image n1 and negative sample image n2, respectively.
[0033] The loss function that incorporates the distance parameter between negative samples is defined as follows:
[0034]
[0035] In the formula:
[0036] This indicates the computation of feature vectors between two images in feature space. , Distance metric function between them; Let be any two image feature vectors in the feature space;
[0037] Indicates the triplet number with a pair of negative samples;
[0038] Indicates the first Anchor point images in a triplet;
[0039] Indicates the first Positive sample images in a triplet;
[0040] Indicates the first The negative sample image n1 in the triplet;
[0041] Indicates the first n2 negative sample images in a triplet;
[0042] This is a threshold used to control the difference between positive and negative samples;
[0043] Indicates the first Feature vectors of anchor point images in a triplet;
[0044] Indicates the first Feature vectors of positive sample images in a triplet;
[0045] Indicates the first The feature vector of the negative sample image n1 in the triplet;
[0046] Indicates the first The feature vector of the negative sample image n2 in the triplet;
[0047] The first parameter representing the distance between negative samples is introduced. The loss of a triplet;
[0048] This means that when the value within [ ] is greater than zero, that value is taken as the loss; when it is less than zero, the loss is zero.
[0049] Furthermore, the triplet loss function simultaneously introduces the gradient direction angle loss and the distance parameter between negative samples. The triplet loss function is defined as follows:
[0050]
[0051] In the formula:
[0052] express ;
[0053] express ;
[0054] This represents the weight of the first component of the loss function; Value range: 0 ~ 1;
[0055] This represents the weight of the second component of the loss function; Value range: 0 ~ 1;
[0056] Indicates the first The geometric midpoint of the feature vectors of the anchor image and the positive sample image in each triplet;
[0057] This represents the simultaneous introduction of angular loss in the gradient direction and distance parameter between negative samples. The loss of a triplet.
[0058] Furthermore, an adaptive marginal adjustment parameter is added to the triplet loss function, as shown in the following equation:
[0059]
[0060]
[0061] In the formula:
[0062] This represents the adaptive marginal adjustment parameter that is automatically adjusted based on the center distance between the two classes of sample images, p and q.
[0063] p and q represent category numbers; p = 1, 2, 3; q = 1, 2, 3;
[0064] Represents the center of the p-class sample image; p = 1, 2, 3;
[0065] Represents the center of the image for class q; q = 1, 2, 3;
[0066] This represents the distance between the centers of the images of classes p and q.
[0067] This indicates the set coefficient. Value range: 0 ~ 1;
[0068] This represents the adaptive marginal adjustment parameter that is automatically adjusted based on the center distance between the sample images of classes 1 and 2.
[0069] This represents the adaptive marginal adjustment parameter that is automatically adjusted based on the center distance between sample images of classes 1 and 3.
[0070] This represents the adaptive marginal adjustment parameter that is automatically adjusted based on the center distance between sample images of classes 2 and 3.
[0071] Indicates in The loss is adjusted by adaptive marginal adjustment on top of the existing loss.
[0072] Furthermore, the medical image classification model includes a metric learning model and a classification model connected in sequence. The metric learning model includes a residual network, a fully connected layer, and a normalization layer connected in sequence. The classification model includes an SVM classifier. The weights of the backbone network of the residual network are updated based on the triplet loss function, and the metric learning model is optimized by minimizing the triplet loss.
[0073] Furthermore, the method includes the following steps:
[0074] Step 1: Construct a metric learning model based on the ResNet convolutional neural network;
[0075] Step 2: Train the metric learning model using the triplet loss function and update the network weights of the metric learning model.
[0076] Step 3: Input the features output by the metric learning model into the SVM classifier, and train the SVM classifier using the real labels of the image.
[0077] Step 4: Establish a medical image classification model using the medical image classification model trained in Step 2 and the SVM classifier trained in Step 3.
[0078] Step 5: Use the medical image classification model established in Step 4 to perform classification and analysis.
[0079] The present invention also provides an apparatus for a medical image classification method based on improved triplet loss, comprising a memory and a processor, wherein the memory is used to store a computer program; and the processor is used to execute the computer program and, when executing the computer program, implement the steps of the medical image classification method based on improved triplet loss as described above.
[0080] The advantages and positive effects of this invention are:
[0081] This invention can improve training efficiency. By introducing negative group distance, angle loss and adaptive margin calculation strategy, the improved triplet loss function converges faster during the training process, thereby improving the efficiency and stability of model training.
[0082] This invention can better learn the features of medical images, making the extracted features more discriminative, thereby improving classification performance and helping to gain a deeper understanding of the intrinsic features and differences of medical images.
[0083] This invention can improve classification accuracy, enabling more precise identification of different types of medical images and providing a more reliable basis for disease diagnosis.
[0084] This invention has significant clinical application value and is expected to be applied in actual clinical practice to assist doctors in medical image recognition and analysis, improve the accuracy and efficiency of diagnosis, reduce the workload of doctors, and promote the development of medical image diagnostic technology. Attached Figure Description
[0085] Figure 1 This is a schematic diagram of a metric learning model structure according to the present invention.
[0086] Figure 2 This is a schematic diagram of a medical image ternary array.
[0087] Figure 3 This is a schematic diagram of a primitive triplet loss.
[0088] Figure 4 This is a schematic diagram of triplet loss based on negative sample distance.
[0089] Figure 5 This is a schematic diagram of the gradient update direction of a primitive triplet loss.
[0090] Figure 6 This is a schematic diagram of the gradient update direction of an improved triplet loss.
[0091] Figure 7 This is a schematic diagram illustrating the distances between different samples.
[0092] Figure 8 This is a schematic diagram of a medical image classification model.
[0093] In the picture:
[0094] A refers to sample type A;
[0095] B refers to sample type B;
[0096] C refers to C-class samples;
[0097] set up Let be any two image feature vectors in the feature space; This indicates the computation of feature vectors between two images in feature space. , Distance metric function between them;
[0098] This is a threshold used to control the difference between positive and negative samples;
[0099] Indicates the triplet number;
[0100] Indicates the first Anchor point images in a triplet;
[0101] Indicates the first Positive sample images in a triplet;
[0102] Indicates the first Negative sample images in a triplet;
[0103] Indicates the first Update position of each anchor point;
[0104] Indicates the first Update positions for each positive sample;
[0105] Indicates the first Update position of each negative sample;
[0106] Indicates the first The negative sample image n1 in the triplet;
[0107] Indicates the first n2 negative sample images in a triplet;
[0108] Indicates the first Feature vectors of anchor point images in a triplet;
[0109] Indicates the first Feature vectors of positive sample images in a triplet;
[0110] Indicates the first Feature vectors of negative sample images in a triplet;
[0111] Indicates the first The feature vector of the negative sample image n1 in the triplet;
[0112] Indicates the first The feature vector of the negative sample image n2 in the triplet;
[0113] , , Corresponding representation , and Regarding the loss function The derivative;
[0114] a12 represents the distance from a positive sample to one of the negative samples in the triplet;
[0115] a13 represents the distance from the positive sample to the other negative sample in the triplet;
[0116] a23 represents the distance between two negative samples. Detailed Implementation
[0117] The present invention will now be described in detail with reference to the accompanying drawings and embodiments. It should be understood that the preferred embodiments described herein are for illustration and explanation only and are not intended to limit the present invention.
[0118] In the description of this invention, the terms "upper," "lower," "front," "rear," "left," "right," "vertical," "horizontal," "top," and "bottom," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing the invention and do not require the invention to be constructed and operated in a specific orientation; therefore, they should not be construed as limitations on the invention. The terms "connected" and "linked" used in this invention should be interpreted broadly. For example, they can refer to a fixed connection or a detachable connection; a direct connection or an indirect connection through intermediate components; or an electrical connection or signal transmission. Those skilled in the art can understand the specific meaning of the above terms according to the specific circumstances.
[0119] The Chinese definitions of the following English words, abbreviations, and phrases used in this application are as follows:
[0120] SVM: Support Vector Machine, is a type of generalized linear classifier that performs binary classification of data using supervised learning. Its decision boundary is the hyperplane with the maximum margin calculated from the learning samples.
[0121] ResNet: Residual Network is a deep convolutional neural network architecture proposed by Kaiming He et al. in 2015. Its core innovation is to solve the gradient vanishing problem in deep neural network training through residual blocks and skip connections, which significantly improves the accuracy of image recognition tasks.
[0122] Anchor: Anchor point.
[0123] Positive: Positive sample.
[0124] Negative: negative sample.
[0125] Please see Figures 1 to 8 A medical image classification method based on improved triplet loss is proposed. A medical image classification model based on neural network and triplet loss function is constructed. Medical images with category labels are collected. According to the category labels, the three different categories of medical images in the collected medical images are edited into a training set to train the medical image classification model. An angle loss of gradient direction is introduced into the triplet loss function to reduce the gradient direction deviation when calculating the gradient direction, thereby accelerating the convergence of the training process.
[0126] Triple loss is a loss function used to train neural networks. It is mainly used to measure learning tasks, and is widely used in fields such as face recognition and image retrieval.
[0127] Preferably, each medical image triplet includes an anchor image, a positive sample image, and a negative sample image;
[0128] First, two images can be extracted from the training set. One image is used as the anchor image of the triplet, and the other is used as the positive sample image of the triplet. Then, one image is randomly extracted from the training set in turn as the negative sample image of the triplet to form a medical image triplet. The negative sample images are extracted repeatedly to form several medical image triplets.
[0129] It can be assumed that the first The medical image triplet composed of the images extracted in the second extraction is the first... The basic loss function for a triplet can be defined as follows:
[0130]
[0131] By introducing an angle loss based on the gradient direction into the basic triplet loss function, we can obtain the following improved triplet loss function:
[0132]
[0133] In the formula:
[0134] This indicates the computation of feature vectors between two images in feature space. , Distance metric function between them; Let be any two image feature vectors in the feature space;
[0135] Indicates the triplet number;
[0136] Indicates the first Anchor point images in a triplet;
[0137] Indicates the first Positive sample images in a triplet;
[0138] Indicates the first Negative sample images in a triplet;
[0139] express ;
[0140] This is a threshold used to control the difference between positive and negative samples;
[0141] Indicates the first Feature vectors of anchor point images in a triplet;
[0142] Indicates the first Feature vectors of positive sample images in a triplet;
[0143] Indicates the first Feature vectors of negative sample images in a triplet;
[0144] Indicates the first The geometric midpoint of the feature vectors of the anchor image and the positive sample image in each triplet;
[0145] Indicates the first Each triplet's basic loss;
[0146] Indicates the first The loss after introducing the gradient direction angle loss into each triplet;
[0147] This means that when the value within [ ] is greater than zero, that value is taken as the loss; when it is less than zero, the loss is zero.
[0148] Preferably, a distance parameter between negative samples can be introduced into the triplet loss function to reduce the distance between samples of the same class and increase the distance between samples of different classes.
[0149] Preferably, each medical image triplet may include an anchor image, a positive sample image, and a pair of negative sample images;
[0150] First, two images can be extracted from the training set. One image is used as the anchor image of the triplet, and the other is used as the positive sample image of the triplet. Then, two images are randomly extracted from the training set in turn as negative sample images of the triplet to form a medical image triplet. The negative sample images are extracted repeatedly to form a number of medical image triplets.
[0151] A pair of negative sample images can be referred to as negative sample image n1 and negative sample image n2, respectively.
[0152] It can be assumed that the first The medical image triplet composed of the images extracted in the second extraction is the first... For a set of triples, the loss function that incorporates the distance parameter between negative samples can be defined as follows:
[0153]
[0154] In the formula:
[0155] This indicates the computation of feature vectors between two images in feature space. , Distance metric function between them; Let be any two image feature vectors in the feature space;
[0156] Indicates the triplet number with a pair of negative samples;
[0157] Indicates the first Anchor point images in a triplet;
[0158] Indicates the first Positive sample images in a triplet;
[0159] Indicates the first The negative sample image n1 in the triplet;
[0160] Indicates the first n2 negative sample images in a triplet;
[0161] This is a threshold used to control the difference between positive and negative samples;
[0162] Indicates the first Feature vectors of anchor point images in a triplet;
[0163] Indicates the first Feature vectors of positive sample images in a triplet;
[0164] Indicates the first The feature vector of the negative sample image n1 in the triplet;
[0165] Indicates the first The feature vector of the negative sample image n2 in the triplet;
[0166] The first parameter representing the distance between negative samples is introduced. The loss of a triplet;
[0167] This means that when the value within [ ] is greater than zero, that value is taken as the loss; when it is less than zero, the loss is zero.
[0168] Preferably, the triplet loss function can simultaneously incorporate the gradient direction angle loss and the distance parameter between negative samples. The triplet loss function can be defined as follows:
[0169]
[0170] In the formula:
[0171] express ;
[0172] express ;
[0173] This represents the weight of the first component of the loss function; Value range: 0 ~ 1;
[0174] This represents the weight of the second component of the loss function; Value range: 0 ~ 1;
[0175] Indicates the first The geometric midpoint of the feature vectors of the anchor image and the positive sample image in each triplet;
[0176] This represents the simultaneous introduction of angular loss in the gradient direction and distance parameter between negative samples. The loss of a triplet.
[0177] Preferably, an adaptive marginal adjustment parameter can be added to the triplet loss function, as shown in the following equation:
[0178]
[0179]
[0180] In the formula:
[0181] This represents the adaptive marginal adjustment parameter that is automatically adjusted based on the center distance between the two classes of sample images, p and q.
[0182] p and q represent category numbers; p = 1, 2, 3; q = 1, 2, 3;
[0183] Represents the center of the p-class sample image; p = 1, 2, 3;
[0184] Represents the center of the image for class q; q = 1, 2, 3;
[0185] This represents the distance between the centers of the images of classes p and q.
[0186] This indicates the set coefficient. Value range: 0 ~ 1;
[0187] This represents the adaptive marginal adjustment parameter that is automatically adjusted based on the center distance between the sample images of classes 1 and 2.
[0188] This represents the adaptive marginal adjustment parameter that is automatically adjusted based on the center distance between sample images of classes 1 and 3.
[0189] This represents the adaptive marginal adjustment parameter that is automatically adjusted based on the center distance between sample images of classes 2 and 3.
[0190] Indicates in The loss is adjusted by adaptive marginal adjustment on top of the existing loss.
[0191] Preferably, the medical image classification model may include a metric learning model and a classification model connected in sequence. The metric learning model includes a residual network, a fully connected layer, and a normalization layer connected in sequence. The classification model includes an SVM classifier, updates the backbone network weights of the residual network based on the triplet loss function, and optimizes the metric learning model by minimizing the triplet loss.
[0192] Preferably, the method may include the following steps:
[0193] Step 1: Construct a metric learning model based on the ResNet convolutional neural network;
[0194] Step 2: Train the metric learning model using the triplet loss function and update the network weights of the metric learning model.
[0195] Step 3: Input the features output by the metric learning model into the SVM classifier, and train the SVM classifier using the real labels of the image.
[0196] Step 4: Establish a medical image classification model using the medical image classification model trained in Step 2 and the SVM classifier trained in Step 3.
[0197] Step 5: Use the medical image classification model established in Step 4 to perform classification and analysis.
[0198] The present invention also provides an apparatus for a medical image classification method based on improved triplet loss, comprising a memory and a processor, wherein the memory is used to store a computer program; and the processor is used to execute the computer program and, when executing the computer program, implement the steps of the medical image classification method based on improved triplet loss as described above.
[0199] The workflow and working principle of the present invention are further described below according to a preferred embodiment of the present invention:
[0200] like Figure 2 As shown, a triple is defined by the anchor image. Positive sample images and negative sample images Composition. The original triplet loss function is:
[0201]
[0202]
[0203] In the formula:
[0204] This indicates the computation of feature vectors between two images in feature space. , Distance metric function between them; Let be any two image feature vectors in the feature space;
[0205] Indicates the triplet number;
[0206] Indicates the number of triples;
[0207] Indicates the first Three-tuple anchor point images;
[0208] Indicates the first Three positive sample images;
[0209] Indicates the first Three negative sample images;
[0210] Indicates the first Feature vectors of three-tuple anchor point images;
[0211] Indicates the first Feature vectors of positive sample images of triplet;
[0212] Indicates the first Feature vectors of negative sample images of triplet;
[0213] Indicates the first The basic loss of each triplet;
[0214] This means that when the value within [ ] is greater than zero, that value is taken as the loss; when it is less than zero, the loss is zero.
[0215] This represents the basic loss of the triplet.
[0216] The basic principle of the triplet basic loss function is to ensure that the distance between the anchor point and the positive sample is added to the sum of the distance between the anchor point and the positive sample. The distance between the anchor point and the negative sample is less than the distance between the image and the negative sample. The corresponding feature vector is ,but Should be greater than .
[0217] Take respectively , and Regarding the loss function The derivative is:
[0218]
[0219]
[0220]
[0221] Gradient update diagram as shown Figure 5 As shown, but the actual gradient direction and Inconsistent. and s is striving to gather and However, their gradient directions also deviate.
[0222] This project proposes a triplet loss with angular loss, defined as follows:
[0223]
[0224] in, and The center is , express Then we have:
[0225]
[0226] In the formula:
[0227] This indicates the computation of feature vectors between two images in feature space. , Distance metric function between them; Let be any two image feature vectors in the feature space;
[0228] Indicates the triplet number;
[0229] Indicates the first Anchor point images in a triplet;
[0230] Indicates the first Positive sample images in a triplet;
[0231] Indicates the first Negative sample images in a triplet;
[0232] express ;
[0233] This is a threshold used to control the difference between positive and negative samples;
[0234] Indicates the first Feature vectors of anchor point images in a triplet;
[0235] Indicates the first Feature vectors of positive sample images in a triplet;
[0236] Indicates the first Feature vectors of negative sample images in a triplet;
[0237] Indicates the first The geometric midpoint of the feature vectors of the anchor image and the positive sample image in each triplet;
[0238] Indicates the first Each triplet's basic loss;
[0239] Indicates the first The loss after introducing the gradient direction angle loss into each triplet;
[0240] This means that when the value within [ ] is greater than zero, that value is taken as the loss; when it is less than zero, the loss is zero.
[0241] Take respectively , and Regarding the loss function The derivative of is then:
[0242]
[0243] An improved gradient update diagram is shown below. Figure 6 As shown, Indicates the first Update position of each anchor point; Indicates the first Update positions for each positive sample; Indicates the first Update position of each negative sample; and Both are the same. And and Committed to gathering and ,and and They are converging at a single point.
[0244] A schematic diagram of the triplet basic loss is shown below. Figure 3 As shown, where:
[0245] The distance between Class A samples is When the loss function When pushing B and C class samples apart during training while satisfying constraints, the loss function does not take into account the distance between B and C class samples. The pushing process will make B and C class samples closer together.
[0246] To mitigate the weak generalization ability of triplet loss, it is necessary not only to reduce the distance between similar samples but also to increase the distance between different classes. The distance between negative samples is introduced into triplet loss to bring samples of the same class closer together and increase the distance between samples of different classes. The triplet loss function based on negative sample distance is as follows: Figure 4 As shown.
[0247] Each medical image triplet includes an anchor image, a positive sample image, and a pair of negative sample images;
[0248] First, two images are extracted from the training set. One image is used as the anchor image of the triplet, and the other image is used as the positive sample image of the triplet. Then, two images are randomly extracted from the training set in turn as negative sample images of the triplet to form a medical image triplet. The negative sample images are extracted repeatedly to form a number of medical image triplets.
[0249] The pair of negative sample images are referred to as negative sample image n1 and negative sample image n2, respectively.
[0250] Let the first The medical image triplet composed of the images extracted in the second extraction is the first... The loss function for a set of triples, incorporating the distance parameter between negative samples, is defined as follows:
[0251]
[0252] In the formula:
[0253] This indicates the computation of feature vectors between two images in feature space. , Distance metric function between them; Let be any two image feature vectors in the feature space;
[0254] Indicates the triplet number with a pair of negative samples;
[0255] Indicates the first Anchor point images in a triplet;
[0256] Indicates the first Positive sample images in a triplet;
[0257] Indicates the first The negative sample image n1 in the triplet;
[0258] Indicates the first n2 negative sample images in a triplet;
[0259] This is a threshold used to control the difference between positive and negative samples;
[0260] Indicates the first Feature vectors of anchor point images in a triplet;
[0261] Indicates the first Feature vectors of positive sample images in a triplet;
[0262] Indicates the first The feature vector of the negative sample image n1 in the triplet;
[0263] Indicates the first The feature vector of the negative sample image n2 in the triplet;
[0264] The first parameter representing the distance between negative samples is introduced. The loss of a triplet;
[0265] This means that when the value within [ ] is greater than zero, that value is taken as the loss; when it is less than zero, the loss is zero.
[0266] The improved triplet loss based on negative sample distance tightens the sample distance of class A while pushing classes B and C away from class A, which is consistent with the effect of the original triplet loss. Furthermore, in the process of pushing classes B and C away, the distance between B and C increases, which further improves the model's convergence speed.
[0267] The improved triplet loss function is obtained by introducing the distance parameter between negative samples according to the following formula:
[0268]
[0269] In the formula:
[0270] express ;
[0271] express ;
[0272] This represents the weight of the first component of the loss function; Value range: 0 ~ 1;
[0273] This represents the weight of the second component of the loss function; Value range: 0 ~ 1;
[0274] Indicates the first The geometric midpoint of the feature vectors of the anchor image and the positive sample image in each triplet;
[0275] This represents the simultaneous introduction of angular loss in the gradient direction and distance parameter between negative samples. The loss of a triplet.
[0276] like Figure 7 As shown, a12 represents the distance from a positive sample to one of the negative samples in the triplet; a13 represents the distance from a positive sample to the other negative sample in the triplet; and a23 represents the distance between the two negative samples.
[0277] Common sense dictates that the values of a12 and a13 should be greater than the value of a23 to represent the similarity between different categories. Therefore, a more detailed calculation strategy is needed for the threshold.
[0278] This invention proposes an online threshold calculation strategy that adaptively calculates the threshold based on existing expressions. and through the updated threshold Continue model training, as shown in the following formula.
[0279] An adaptive marginal adjustment strategy is incorporated into the triplet loss, referencing the similarity of the original samples and preserving the original spatial form when the loss function derives different categories. The threshold is updated according to the following formula. Continue model training:
[0280]
[0281]
[0282] In the formula:
[0283] This represents the adaptive marginal adjustment parameter that is automatically adjusted based on the center distance between the two classes of sample images, p and q.
[0284] p and q represent category numbers; p = 1, 2, 3; q = 1, 2, 3;
[0285] Represents the center of the p-class sample image; p = 1, 2, 3;
[0286] Represents the center of the image for class q; q = 1, 2, 3;
[0287] This represents the distance between the centers of the images of classes p and q.
[0288] This indicates the set coefficient. Value range: 0 ~ 1;
[0289] This represents the adaptive marginal adjustment parameter that is automatically adjusted based on the center distance between the sample images of classes 1 and 2.
[0290] This represents the adaptive marginal adjustment parameter that is automatically adjusted based on the center distance between sample images of classes 1 and 3.
[0291] This represents the adaptive marginal adjustment parameter that is automatically adjusted based on the center distance between sample images of classes 2 and 3.
[0292] Indicates in The loss is adjusted by adaptive marginal adjustment on top of the existing loss.
[0293] The medical image classification model consists of a metric learning model and a classification model connected in sequence. The metric learning model includes a residual network, a fully connected layer, and a normalization layer connected in sequence. The classification model includes an SVM classifier. An improved triplet loss function is used to update the weights of the ResNet backbone network, and the metric learning model is optimized by minimizing the triplet loss.
[0294] like Figure 1 As shown, in the metric learning model, the improved triplet loss function described above is used to update the network weights. The model is optimized by minimizing the triplet loss, which helps the network learn the features of medical images. ResNet is introduced as the backbone of the metric learning. A normalization layer following the fully connected layers helps stabilize the training process and accelerate convergence. This model leverages the powerful feature representation capabilities of metric learning and ResNet to achieve accurate and reliable medical image classification.
[0295] The trained model converts medical images into feature vectors. A metric learning model is used as a feature extractor. The feature vectors are then fed into an SVM, which is used to classify the images, such as... Figure 8 As shown.
[0296] Based on the above analysis, the medical image classification method based on improved triplet loss in this invention can be carried out according to the following steps:
[0297] Step 1: Construct a metric learning model based on the ResNet convolutional neural network; such as Figure 1 As shown.
[0298] Step 2: Train the metric learning model using the triplet loss function and update the network weights of the metric learning model.
[0299] Step 3: Input the features output by the metric learning model into the SVM classifier, and train the SVM classifier using the real labels of the images.
[0300] Step 4: Using the medical image classification model trained in Step 2 and the SVM classifier trained in Step 3, establish a medical image classification model, such as... Figure 8 As shown.
[0301] Step 5: Use the medical image classification model established in Step 4 to perform classification and analysis.
[0302] The above steps enable medical image classification, which not only improves the classification accuracy of medical images but also standardizes the features extracted by convolutional networks, thus having significant clinical application value.
[0303] The aforementioned neural networks, metric learning models, classification models, residual networks, fully connected layers, normalization layers, SVM classifiers, ResNet convolutional neural networks, and other neural networks and functional modules can all be constructed using existing applicable neural networks and functional modules, or they can be constructed using existing applicable neural networks and functional modules and conventional technical means.
[0304] The embodiments described above are only used to illustrate the technical ideas and features of the present invention. Their purpose is to enable those skilled in the art to understand the content of the present invention and implement it accordingly. The patent scope of the present invention should not be limited by these embodiments. That is, any equivalent changes or modifications made in accordance with the spirit disclosed in the present invention still fall within the patent scope of the present invention.
Claims
1. A medical image classification method based on improved triplet loss, characterized in that, A medical image classification model based on neural networks and triplet loss function is constructed. Medical images with category labels are collected. Based on the category labels, the three different categories of medical images in the collected medical images are edited into a training set to train the medical image classification model. An angle loss of gradient direction is introduced into the triplet loss function to reduce the gradient direction deviation when calculating the gradient direction, thereby accelerating the convergence of the training process. Each medical image triplet includes an anchor image, a positive sample image, and a negative sample image; First, two images are extracted from the training set. One image is used as the anchor image of the triplet, and the other is used as the positive sample image of the triplet. Then, one image is randomly extracted from the training set in turn as the negative sample image of the triplet to form a medical image triplet. The negative sample images are extracted repeatedly to form several medical image triplets. The basic loss function for triplet is defined as follows: By introducing an angle loss based on the gradient direction into the basic triplet loss function, we obtain the following improved triplet loss function: In the formula: This indicates the computation of feature vectors between two images in feature space. , Distance metric function between them; Let be any two image feature vectors in the feature space; Indicates the triplet number; Indicates the first Anchor point images in a triplet; Indicates the first Positive sample images in a triplet; Indicates the first Negative sample images in a triplet; express ; This is a threshold used to control the difference between positive and negative samples; Indicates the first Feature vectors of anchor point images in a triplet; Indicates the first Feature vectors of positive sample images in a triplet; Indicates the first Feature vectors of negative sample images in triplet; Indicates the first The geometric midpoint of the feature vectors of the anchor image and the positive sample image in each triplet; Indicates the first Each triplet's basic loss; Indicates the first The loss after introducing the gradient direction angle loss into each triplet; This means that when the value within [] is greater than zero, that value is taken as the loss; when it is less than zero, the loss is zero.
2. The medical image classification method based on improved triplet loss according to claim 1, characterized in that, The triplet loss function also introduces a distance parameter between negative samples, which reduces the distance between samples of the same class and increases the distance between samples of different classes.
3. The medical image classification method based on improved triplet loss according to claim 2, characterized in that, Each medical image triplet includes an anchor image, a positive sample image, and a pair of negative sample images; First, two images are extracted from the training set. One image is used as the anchor image of the triplet, and the other image is used as the positive sample image of the triplet. Then, two images are randomly extracted from the training set in turn as negative sample images of the triplet to form a medical image triplet. The negative sample images are extracted repeatedly to form a number of medical image triplets. The pair of negative sample images are referred to as negative sample image n1 and negative sample image n2, respectively. The loss function that incorporates the distance parameter between negative samples is defined as follows: In the formula: This indicates the computation of feature vectors between two images in feature space. , Distance metric function between them; Let be any two image feature vectors in the feature space; Indicates the triplet number with a pair of negative samples; Indicates the first Anchor point images in a triplet; Indicates the first Positive sample images in a triplet; Indicates the first The negative sample image n1 in the triplet; Indicates the first n2 negative sample images in a triplet; This is a threshold used to control the difference between positive and negative samples; Indicates the first Feature vectors of anchor point images in a triplet; Indicates the first Feature vectors of positive sample images in a triplet; Indicates the first The feature vector of the negative sample image n1 in the triplet; Indicates the first The feature vector of the negative sample image n2 in the triplet; The first parameter representing the distance between negative samples is introduced. The loss of a triplet; This means that when the value within [] is greater than zero, that value is taken as the loss; when it is less than zero, the loss is zero.
4. The medical image classification method based on improved triplet loss according to claim 3, characterized in that, The triplet loss function incorporates both the gradient direction angle loss and the distance parameter between negative samples. The triplet loss function is defined as follows: In the formula: express ; express ; This represents the weight of the first component of the loss function; Value range: 0 ~ 1; This represents the weight of the second component of the loss function; Value range: 0 ~ 1; Indicates the first The geometric midpoint of the feature vectors of the anchor image and the positive sample image in each triplet; This represents the simultaneous introduction of angular loss in the gradient direction and distance parameter between negative samples. The loss of a triplet.
5. The medical image classification method based on improved triplet loss according to claim 4, characterized in that, An adaptive marginal adjustment parameter is added to the triplet loss function, as shown in the following equation: In the formula: Indicates by Adaptive marginal adjustment parameters for automatic adjustment of the center distance between two types of sample images; , Indicates the category number; =1, 2, 3; =1, 2, 3; express Center of the sample image; =1, 2, 3; express Center of the sample image; =1, 2, 3; express Distance between the centers of the two types of sample images; This indicates the set coefficient. Value range: 0 ~ 1; Indicates by Adaptive marginal adjustment parameters for automatic adjustment of the center distance between two types of sample images; Indicates by Adaptive marginal adjustment parameters for automatic adjustment of the center distance between two types of sample images; Indicates by Adaptive marginal adjustment parameters for automatic adjustment of the center distance between two types of sample images; Indicates in The loss is adjusted by adaptive marginal adjustment on top of the existing loss.
6. The medical image classification method based on improved triplet loss according to claim 1, characterized in that, The medical image classification model consists of a metric learning model and a classification model connected in sequence. The metric learning model includes a residual network, a fully connected layer, and a normalization layer connected in sequence. The classification model includes an SVM classifier. The weights of the backbone network of the residual network are updated based on the triplet loss function, and the metric learning model is optimized by minimizing the triplet loss.
7. The medical image classification method based on improved triplet loss according to claim 6, characterized in that, The method includes the following steps: Step 1: Construct a metric learning model based on the ResNet convolutional neural network; Step 2: Train the metric learning model using the triplet loss function and update the network weights of the metric learning model. Step 3: Input the features output by the metric learning model into the SVM classifier, and train the SVM classifier using the real labels of the image. Step 4: Establish a medical image classification model using the medical image classification model trained in Step 2 and the SVM classifier trained in Step 3. Step 5: Use the medical image classification model established in Step 4 to perform classification and analysis.
8. A device for medical image classification based on an improved triplet loss method, comprising a memory and a processor, characterized in that, The memory is used to store a computer program; the processor is used to execute the computer program and, when executing the computer program, implement the steps of the medical image classification method based on improved triplet loss as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Image classification model training method, image classification method, equipment and medium
CN115496955A
Discriminative Cosine Embedding in Machine Learning
US20190279091A1