An image classification method fusing triple loss and pearson constraint

CN122929253APending Publication Date: 2026-10-16XIDIAN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610826086.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-06-09
Publication Date
2026-10-16

AI Technical Summary

Technical Problem

[0005]鉴于此,本发明提出了一种融合三元组损失与皮尔逊约束的图像分类方法,旨在解决当前技术中图像分类方法中特征维度间相关性过高、特征冗余严重以及判别力与独立性难以协同优化的问题

Benefits of technology

[0013]Compared with existing technologies, the beneficial effects of this invention are as follows: By constructing triplet sample batches and calculating the triplet loss function, the feature distance between samples of the same class can be narrowed, while the feature distance between samples of different classes can be widened, thereby significantly improving the inter-class discriminative power and intra-class compactness of the features learned by the deep feature extraction network. This results in an effective enhancement of the model's ability to distinguish similar categories, reduced inter-class confusion, and improved image classification accuracy. Secondly, by calculating the Pearson correlation coefficient matrix on the feature vectors output by the deep feature extraction network and constructing a Pearson constraint loss function based on off-diagonal elements, the linear correlation between different dimensions of the feature vectors can be explicitly reduced. This technique encourages the network to learn low-redundancy, highly independent feature representations, avoids information overlap between feature dimensions, thereby improving the utilization efficiency of the feature space, enhancing the model's generalization ability, and reducing the risk of overfitting. Thirdly, the triplet loss function and the Pearson constraint loss function are weighted and fused to obtain a total loss function for joint optimization. Its beneficial effects are manifested in that, while ensuring feature discriminative power, it introduces decorrelation constraints, enabling the network to achieve a balance between inter-class separation and feature independence. This allows the network to learn high-quality feature representations that are both compact and decoupled, further improving classification performance. Finally, by employing a hard example mining strategy to construct triplet sample batches and selecting boundary samples for training, the model convergence is accelerated and its ability to identify difficult samples is enhanced. Backpropagation is then performed using the total loss function to update network parameters until the convergence condition is met, resulting in a well-trained image classification model. The beneficial effect of this mechanism is that it enables the entire image classification model training process to have adaptive feature optimization capabilities, automatically coordinating discriminative and independence objectives under different datasets and class distributions, thereby steadily improving the model's classification accuracy in practical applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122929253A_ABST
    Figure CN122929253A_ABST
Patent Text Reader

Abstract

The application relates to the technical field of image classification, and discloses an image classification method fusing a triple loss and a Pearson constraint, which comprises the following steps: acquiring an image data set and constructing a triple sample batch; inputting the triple sample batch into a deep feature extraction network; calculating a triple loss function based on an extracted feature vector; calculating a Pearson correlation coefficient matrix between feature dimensions of a feature vector output by the network, and constructing a Pearson constraint loss function based on non-diagonal elements; weighting and fusing the triple loss function and the Pearson constraint loss function; performing back propagation by using a total loss function, and updating network parameters until convergence; and inputting an image to be classified into the model, and outputting a classification result. The application reduces feature redundancy and enhances feature independence through the Pearson constraint, improves inter-class distinguishability by combining the triple loss, and effectively improves the accuracy and generalization ability of image classification.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image classification technology, and more specifically, to an image classification method that integrates triplet loss and Pearson constraint. Background Technology

[0002] Existing image classification methods often employ triplet loss functions to enhance the inter-class discriminative power and intra-class compactness of features, achieving some success in tasks such as face recognition and fine-grained classification. However, traditional triplet loss only focuses on the relative distance constraints between sample pairs, neglecting the correlation between the dimensions of the feature vector. When there is strong linear correlation or information redundancy between feature dimensions, the model's expressive power is limited, leading to overfitting and decreased generalization performance. Currently, mainstream improvement schemes focus on sample sampling strategies or boundary threshold adjustments, but lack explicit guidance on feature independence and low redundancy, making it difficult to balance the discriminative power and decorrelation of features.

[0003] Currently, mainstream triplet loss optimization methods mainly focus on improving sample sampling strategies, such as hard example mining and intra-batch sampling, or controlling inter-class spacing by adjusting boundary threshold parameters. While these methods improve training efficiency and classification accuracy to some extent, they do not address the structure of the feature representation itself or explicitly constrain the correlation between feature dimensions. Due to the lack of guidance on feature independence and low redundancy, the feature vectors learned by the network often exhibit inter-dimensional information overlap, leading to reduced utilization of the feature space and making it difficult to obtain the most compact and discriminative representation with limited feature dimensions. Furthermore, existing methods lack dynamic monitoring and adaptive adjustment mechanisms for feature distribution quality during training. When the data scale increases or the number of classes increases, model performance is prone to instability, requiring extensive manual parameter tuning to maintain good classification results.

[0004] In summary, existing technologies are still insufficient to effectively address the problems of severe feature redundancy and the difficulty in co-optimizing discriminative power and independence in image classification. Therefore, there is an urgent need to propose a new image classification method that simultaneously improves the inter-class discriminative power and inter-dimensional independence of features, thereby enhancing classification accuracy and generalization ability. Summary of the Invention

[0005] In view of this, the present invention proposes an image classification method that integrates triplet loss and Pearson constraint, aiming to solve the problems of excessive correlation between feature dimensions, serious feature redundancy, and difficulty in co-optimizing discriminative power and independence in current image classification methods.

[0006] This invention proposes an image classification method that integrates triplet loss and Pearson constraint, comprising the following steps: S1. Obtain the image dataset and divide it into a training set and a test set. Construct a batch of triplet samples from the training set. Each triplet sample includes an anchor image, a positive sample image, and a negative sample image. S2. Input the triplet samples in batches into a preset deep feature extraction network to extract the corresponding anchor point feature vector, positive sample feature vector and negative sample feature vector; S3. Calculate the triplet loss function based on the anchor feature vector, positive sample feature vector, and negative sample feature vector; S4. Calculate the Pearson correlation coefficient matrix between feature dimensions of the feature vectors output by the deep feature extraction network, and construct the Pearson constrained loss function based on the off-diagonal elements of the Pearson correlation coefficient matrix to reduce the correlation between different dimensions of the feature vectors. S5. Weighted fusion of the triplet loss function and the Pearson constraint loss function to obtain the total loss function; S6. Backpropagation is performed using the total loss function to update the network parameters of the deep feature extraction network until the convergence condition is met, and a trained image classification model is obtained. S7. Input the image to be classified into the trained image classification model and output the classification result of the image to be classified.

[0007] Furthermore, the step of constructing the triplet sample batch includes: A hard example mining strategy is used for sampling. For each anchor point image in a batch, its feature distance with the remaining images of the same category is calculated, and the image with the largest distance is selected as the positive sample image. Calculate the feature distance between the anchor point image and images of different categories, and select the image with the smallest distance as the negative sample image.

[0008] Furthermore, the formula for calculating the triplet loss function is as follows: in, Represents the triplet loss function. Indicates the size of the sample batch. , and They represent the first Feature vectors of anchor point images, positive sample images, and negative sample images. Denotes the square of the L2 norm. This represents the preset boundary threshold parameter.

[0009] Furthermore, S4 specifically includes: obtaining a feature matrix F with batch size B and feature dimension D. ; Calculate the Pearson correlation coefficient between the u-th and v-th features in the feature matrix. : in, Indicates the first The first sample 3D eigenvalues This indicates the first of all samples in this batch. The average value of the dimensional features; The off-diagonal elements of the Pearson correlation coefficient matrix are extracted and penalized to construct the Pearson constrained loss function. : in, This represents the Pearson-constrained loss function. The total dimension of the feature vectors. For the first Dimensional features and the first Pearson correlation coefficient between dimensional features, denominator Used to normalize the number of off-diagonal elements.

[0010] Furthermore, the formula for calculating the total loss function obtained in S5 is as follows: in, Represents the total loss function. This represents the hyperparameter used to balance feature discriminative power and feature decorrelation.

[0011] Furthermore, the deep feature extraction network includes a residual network backbone and a global average pooling layer and a fully connected dimensionality reduction layer connected to the end of the residual network backbone. After the triplet samples are input into the residual network backbone to extract spatial feature maps, they are compressed into one-dimensional vectors by the global average pooling layer, and then mapped to a low-dimensional feature space based on the fully connected dimensionality reduction layer.

[0012] Furthermore, the specific steps in S7 of inputting the image to be classified into the trained image classification model and outputting the classification result of the image to be classified include: The image to be classified is input into the trained deep feature extraction network to extract the target feature vector; The target feature vector is input into the classifier, and the probability value of the target feature vector belonging to each image category is calculated by the Softmax function; The category corresponding to the highest probability value is taken as the final classification result of the image to be classified.

[0013] Compared with existing technologies, the beneficial effects of this invention are as follows: By constructing triplet sample batches and calculating the triplet loss function, the feature distance between samples of the same class can be narrowed, while the feature distance between samples of different classes can be widened, thereby significantly improving the inter-class discriminative power and intra-class compactness of the features learned by the deep feature extraction network. This results in an effective enhancement of the model's ability to distinguish similar categories, reduced inter-class confusion, and improved image classification accuracy. Secondly, by calculating the Pearson correlation coefficient matrix on the feature vectors output by the deep feature extraction network and constructing a Pearson constraint loss function based on off-diagonal elements, the linear correlation between different dimensions of the feature vectors can be explicitly reduced. This technique encourages the network to learn low-redundancy, highly independent feature representations, avoids information overlap between feature dimensions, thereby improving the utilization efficiency of the feature space, enhancing the model's generalization ability, and reducing the risk of overfitting. Thirdly, the triplet loss function and the Pearson constraint loss function are weighted and fused to obtain a total loss function for joint optimization. Its beneficial effects are manifested in that, while ensuring feature discriminative power, it introduces decorrelation constraints, enabling the network to achieve a balance between inter-class separation and feature independence. This allows the network to learn high-quality feature representations that are both compact and decoupled, further improving classification performance. Finally, by employing a hard example mining strategy to construct triplet sample batches and selecting boundary samples for training, the model convergence is accelerated and its ability to identify difficult samples is enhanced. Backpropagation is then performed using the total loss function to update network parameters until the convergence condition is met, resulting in a well-trained image classification model. The beneficial effect of this mechanism is that it enables the entire image classification model training process to have adaptive feature optimization capabilities, automatically coordinating discriminative and independence objectives under different datasets and class distributions, thereby steadily improving the model's classification accuracy in practical applications.

[0014] On the other hand, this application also provides an image classification apparatus that integrates triplet loss and Pearson constraint, comprising: The data acquisition module is used to acquire an image dataset and divide it into a training set and a test set, and construct a batch of triplet samples from the training set. Each triplet sample includes an anchor image, a positive sample image and a negative sample image. The feature extraction module is used to input the triplet samples in batches into a preset deep feature extraction network to extract the corresponding anchor point feature vector, positive sample feature vector and negative sample feature vector; The triplet loss calculation module is used to calculate the triplet loss function based on the anchor feature vector, positive sample feature vector, and negative sample feature vector. The Pearson constraint calculation module is used to calculate the Pearson correlation coefficient matrix between feature dimensions of the feature vectors output by the deep feature extraction network, and to construct the Pearson constraint loss function based on the off-diagonal elements of the Pearson correlation coefficient matrix. The loss fusion and training module is used to weightedly fuse the triplet loss function and the Pearson constraint loss function to obtain the total loss function; and to use the total loss function to perform backpropagation to update the network parameters to obtain the trained image classification model. The classification prediction module is used to input the image to be classified into the trained image classification model and output the classification result of the image to be classified. Attached Figure Description

[0015] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit the invention. Furthermore, the same reference numerals denote the same parts throughout the drawings. In the drawings: Figure 1 This is a functional block diagram of an image classification method that integrates triplet loss and Pearson constraint, provided in an embodiment of the present invention. Figure 2 This is a flowchart illustrating an image classification method that integrates triplet loss and Pearson constraint, as provided in an embodiment of the present invention. Detailed Implementation

[0016] Exemplary embodiments of the present disclosure will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the disclosure to those skilled in the art. It should be noted that, unless otherwise specified, embodiments and features in the embodiments of the present invention can be combined with each other. The present invention will now be described in detail with reference to the accompanying drawings and embodiments.

[0017] like Figures 1-2 As shown, in some embodiments of this application, this embodiment provides an image classification method that fuses triplet loss and Pearson constraint, including: Step S1: Obtain the image dataset and divide it into a training set and a test set. Construct a batch of triplet samples from the training set. Each triplet sample includes an anchor image, a positive sample image, and a negative sample image.

[0018] Specifically, the sampling of the triplet sample batches adopts a hard example mining strategy. For each anchor image in the batch, the feature distance between it and other images of the same category is calculated, and the image with the largest distance is selected as the positive sample image; the feature distance between the anchor image and images of different categories is calculated, and the image with the smallest distance is selected as the negative sample image.

[0019] Understandably, constructing triplet sample batches provides the model with training samples that have discriminative constraints. In image classification tasks, images of the same class may have appearance differences (such as pose and lighting variations), while images of different classes may have similarities (such as cats and dogs). By employing a hard example mining strategy, selecting the farthest positive sample (i.e., the least similar image within a class) and the closest negative sample (i.e., the most similar image between classes), the network is forced to learn a more compact intra-class distribution and clearer inter-class boundaries, thereby improving the model's discriminative ability. Compared to random sampling, this sampling method can more effectively utilize the difficult samples in the training data, accelerating model convergence and improving generalization performance.

[0020] In a specific embodiment of this application, the above steps are implemented as follows: Taking the CIFAR-10 image dataset as an example, this dataset contains 60,000 32×32 color images across 10 categories, with 50,000 images used as the training set and 10,000 as the test set. Triple sample batches are constructed from the training set, with a batch size of N=32. For each anchor image within a batch, such as an image of the "cat" category, the Euclidean distance between it and all other "cat" images in the same batch in the initial feature space is first calculated. The "cat" image with the largest distance is selected as the positive sample (i.e., the same category image with the greatest difference from the anchor). Then, the feature distance between it and images of different categories (such as "dog," "bird," etc.) is calculated, and the out-of-category image with the smallest distance is selected as the negative sample (i.e., the out-of-category image most similar to the anchor). Thus, each anchor corresponds to a triple consisting of the anchor, a difficult positive sample, and a difficult negative sample. The batches constructed in this way contain rich boundary samples, laying the foundation for effective optimization of the subsequent loss function.

[0021] The above scenarios are merely preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

[0022] Step S2: Input the triplet samples in batches into a preset deep feature extraction network to extract the corresponding anchor point feature vector, positive sample feature vector and negative sample feature vector.

[0023] Specifically, the deep feature extraction network includes a residual network backbone and a global average pooling layer and a fully connected dimensionality reduction layer connected to the end of the residual network backbone. After the triplet samples are input into the residual network backbone to extract spatial feature maps, they are compressed into one-dimensional vectors by the global average pooling layer and then mapped to a low-dimensional feature space based on the fully connected dimensionality reduction layer.

[0024] Understandably, the role of deep feature extraction networks is to transform the original image into a discriminative feature representation. Residual networks (ResNet) address the vanishing gradient and degradation problems of deep networks through skip connections, enabling the extraction of rich, hierarchical features. Global average pooling layers compress the spatial features of each channel into a scalar, reducing the number of parameters and enhancing translation invariance. Fully connected dimensionality reduction layers map high-dimensional feature vectors to a lower-dimensional embedding space (e.g., 128-dimensional or 256-dimensional), where calculating distances between samples is more efficient and helps remove redundant information. Through this network structure, compact and highly expressive feature vectors can be obtained.

[0025] In a specific embodiment of this application, the above steps are implemented as follows: A ResNet-50 network with 50 convolutional layers is used as the backbone network and pre-trained on the ImageNet dataset. The triplet sample batches constructed in step S1 (each image size normalized to 224×224) are input into the ResNet-50. After a series of convolutions, batch normalization, and ReLU activation operations, a 7×7×2048 spatial feature map is obtained. Then, a global average pooling layer is used to average the 7×7 feature maps of each channel, resulting in a 2048-dimensional one-dimensional vector. Finally, a fully connected dimensionality reduction layer maps the 2048-dimensional vector to a 128-dimensional low-dimensional feature space, yielding the final anchor feature vector f(x^a), positive sample feature vector f(x^p), and negative sample feature vector f(x^n). This 128-dimensional feature vector is L2 normalized and used for subsequent distance calculations. This network design retains ResNet's powerful feature extraction capabilities while also achieving a compact embedding representation suitable for triple loss calculation.

[0026] The above scenarios are merely preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

[0027] Step S3: Calculate the triplet loss function based on the anchor feature vector, positive sample feature vector, and negative sample feature vector.

[0028] Specifically, the formula for calculating the triplet loss function is as follows: in, Represents the triplet loss function. Indicates the size of the sample batch. , and They represent the first Feature vectors of anchor point images, positive sample images, and negative sample images. Denotes the square of the L2 norm. This represents the preset boundary threshold parameter.

[0029] Understandably, the core objective of the triplet loss function is to bring the anchor point closer to the positive samples while simultaneously increasing the distance between the anchor point and the negative samples, and to ensure that the difference in distance between the positive and negative samples is greater than a boundary threshold. When the distance between the anchor point and the positive sample minus the distance between the anchor point and the negative sample plus... If the loss is still greater than 0, it indicates that the current triplet does not meet the requirements, resulting in a positive loss value; otherwise, the loss is 0, indicating that the triplet has met the discrimination criteria. By minimizing this loss function, the network can learn high-quality feature representations that are compact within classes and separable between classes. Boundary Threshold The introduction of this avoids the network focusing on simple samples that already meet the conditions, and instead focuses on difficult samples that are hard to distinguish.

[0030] In a specific embodiment of this application, the above steps are implemented as follows: Taking the 128-dimensional feature vector obtained in step S2, a boundary threshold is set. =0.2, batch size N=32. For the first... For each triplet, the squared Euclidean distance between the anchor point and a positive sample is calculated, for example, 0.15; the squared Euclidean distance between the anchor point and a negative sample is calculated, for example, 0.05. The triplet loss term is then 0.15 - 0.05 + 0.2 = 0.30 > 0, resulting in a positive loss. If another triplet has a positive anchor distance of 0.10 and a negative anchor distance of 0.40, then 0.10 - 0.40 + 0.2 = -0.10 < 0, and the loss is 0. The average triplet loss is obtained by summing the losses of all 32 triplets and dividing by 32. In this way, the network is guided to cluster similar samples in the feature space, while dissimilar samples are kept apart, with an inter-class margin of at least 0.30. .

[0031] The above scenarios are merely preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

[0032] Step S4: Calculate the Pearson correlation coefficient matrix between feature dimensions of the feature vectors output by the deep feature extraction network, and construct the Pearson constrained loss function based on the off-diagonal elements of the Pearson correlation coefficient matrix to reduce the correlation between different dimensions of the feature vectors.

[0033] Specifically, step S4 includes: obtaining a feature matrix F with batch size B and feature dimension D. ; Calculate the Pearson correlation coefficient between the u-th and v-th features in the feature matrix. : in, Indicates the first The first sample 3D eigenvalues This indicates the first of all samples in this batch. The average value of the dimensional features; The off-diagonal elements of the Pearson correlation coefficient matrix are extracted and penalized to construct the Pearson constrained loss function. : in, This represents the Pearson-constrained loss function. The total dimension of the feature vectors. For the first Dimensional features and the first Pearson correlation coefficient between dimensional features, denominator Used to normalize the number of off-diagonal elements.

[0034] Understandably, the Pearson correlation coefficient measures the degree of linear correlation between two variables, ranging from -1 to 1. When there is a strong correlation (absolute value close to 1) between features of different dimensions, it indicates feature redundancy and low utilization of the feature space. By minimizing the sum of squares of off-diagonal elements, the network is encouraged to learn feature representations that are as linearly independent as possible across dimensions, thus reducing feature redundancy. This decorrelation constraint helps improve the independence and expressive power of features, reduces the risk of overfitting, and enhances the model's generalization ability on the test set. Normalization factor This makes the loss value unaffected by the size of the feature dimension, facilitating comparisons and hyperparameter tuning between different network structures.

[0035] In a specific embodiment of this application, the above steps are implemented as follows: Following step S2, 32 128-dimensional feature vectors are obtained in a batch, forming a feature matrix F. First, calculate the mean of each dimension. Then, the Pearson correlation coefficient between any two dimensions is calculated using the formula, resulting in a 128×128 symmetric matrix with diagonal elements of 1. All off-diagonal elements (128×127 in total) are extracted, their squared values ​​are calculated and summed, then divided by 128×127 to obtain the mean squared correlation coefficient, which is the Pearson constraint loss. For example, if the absolute values ​​of all off-diagonal correlation coefficients are close to 0, then The value is close to 0; if there is a strong correlation between certain dimensions (such as 0.9), then the square of 0.81 will significantly increase the loss value. Through backpropagation, the network adjusts the weights to reduce the linear dependence of these strongly correlated dimensions, thereby making each dimension of the feature vector more independent and the feature representation more compact and efficient.

[0036] The above scenarios are merely preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

[0037] Step S5: Weight and fuse the triplet loss function with the Pearson constraint loss function to obtain the total loss function.

[0038] Specifically, the formula for calculating the total loss function is as follows: in Represents the total loss function. This represents the hyperparameter used to balance feature discriminative power and feature decorrelation.

[0039] Understandably, the total loss function simultaneously optimizes two objectives: the triplet loss ensures the discriminative power of features in both between-class and within-class distributions, while the Pearson constraint loss ensures low correlation between feature dimensions. The hyperparameter λ is used to adjust the relative importance of the two losses. When the size is small, the model focuses more on discriminativeness, but may produce redundant features; when When the value is large, the model emphasizes feature independence, but may sacrifice some discriminative ability. This can be addressed by setting appropriate parameters. (For example, by determining it to be 0.01 or 0.1 through cross-validation) this can enable the model to achieve a good balance between discriminative power and feature decoupling, thereby learning a compact and independent feature representation, and further improving classification performance.

[0040] In a specific embodiment of this application, the above steps are implemented in the following scenario: assuming the triplet loss calculated in step S3 is... =0.35, the Pearson constraint loss calculated in step S4 =0.12, set hyperparameter =0.1, then the total loss =0.35 + 0.1 × 0.12 = 0.362. In the initial stages of training, Typically, the features are large and dominate the optimization direction; as training progresses, the features gradually become more distinguishable. Descending, at this time The effect of this joint optimization gradually becomes apparent, prompting feature decorrelation. Through this joint optimization, the network can reduce redundant information between dimensions while maintaining high discriminative power.

[0041] The above scenarios are merely preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

[0042] Step S6: Use the total loss function to perform backpropagation and update the network parameters of the deep feature extraction network until the convergence condition is met, and obtain the trained image classification model.

[0043] Understandably, the gradient of the total loss with respect to the parameters of each layer of the network is calculated using the backpropagation algorithm, and the weights are updated using an optimizer (such as Adam or SGD) to gradually decrease the loss value. The convergence condition can be reaching a preset maximum number of iterations, or the loss value no longer significantly decreasing in several consecutive validation rounds. During training, the classification accuracy can be periodically evaluated on the validation set, and the optimal model parameters can be saved. The final image classification model can extract discriminative and low-redundancy features from the input image, providing high-quality feature representations for classification tasks.

[0044] In a specific embodiment of this application, the above steps are implemented as follows: The Adam optimizer is used, with an initial learning rate of 0.001, which decays to 0.9 times its original value every 20 epochs, for a total of 100 training epochs. The batch size B = 32, and approximately 1562 batches (50000 / 32) are randomly sampled from the training set for each epoch. During each forward propagation, the learning rate is calculated... Then, the backpropagation function is called to calculate the gradient, and the optimizer is used to update all trainable parameters of ResNet-50 and the dimensionality reduction layer. Every 5 epochs, the classification accuracy is calculated on the test set (the extracted 128-dimensional features are input into a softmax classifier). Training is stopped early when the test accuracy no longer improves for 3 consecutive epochs. Finally, the model with the highest validation accuracy is saved as the trained image classification model. In this way, the model achieved a classification accuracy of 95.2% on the CIFAR-10 test set, which is 1.4 percentage points higher than the baseline model using only triplet loss (93.8%), demonstrating the effectiveness of this method.

[0045] The above scenarios are merely preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

[0046] Step S7: Input the image to be classified into the trained image classification model and output the classification result of the image to be classified.

[0047] Specifically, step S7 includes: inputting the image to be classified into the trained deep feature extraction network to extract the target feature vector; inputting the target feature vector into the classifier and calculating the probability value of the target feature vector belonging to each image category through the Softmax function; and taking the category corresponding to the highest probability value as the final classification result of the image to be classified.

[0048] Understandably, a well-trained deep feature extraction network can map any input image to a low-dimensional feature space, which exhibits compact intra-class features and separable inter-class features. The classifier can employ a fully connected layer with a softmax function; the weight matrix of this fully connected layer can be viewed as the class center vectors for each class. By calculating the similarity (usually a dot product or cosine similarity) between the target feature vector and each class center, and then normalizing it to a probability distribution using softmax, the class with the highest probability is selected as the prediction result. This process is simple and efficient, suitable for real-time inference scenarios.

[0049] In a specific embodiment of this application, the above steps are implemented as follows: A cat image (224×224 pixels) to be classified is input into a trained ResNet-50 feature extraction network, and a 128-dimensional target feature vector is obtained through forward propagation. .Will The input is fed into a classifier, which is a 10×128 fully connected layer (because CIFAR-10 has 10 classes), where each row of the weight matrix represents the center vector of a class. The calculation... The dot product of the logit values ​​with the center vectors of the 10 categories yields 10 logit values, which are then converted into probability values ​​using the Softmax function. For example, the probability for cats is 0.92, for dogs 0.05, for birds 0.01, and for other categories it is close to 0. The category "cat" with the highest probability is taken as the final classification result. In practical applications, a confidence threshold can be set; if the highest probability is below the threshold, classification is rejected or manual processing is required. In this way, end-to-end image classification is achieved.

[0050] The above scenarios are merely preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

[0051] In the above embodiments, by constructing triplet sample batches and calculating the triplet loss function, the feature distance between samples of the same class can be narrowed, while the feature distance between samples of different classes can be widened, thereby significantly improving the inter-class discriminative power and intra-class compactness of the features learned by the deep feature extraction network. The beneficial effect of this is that it effectively enhances the model's ability to distinguish similar categories, reduces inter-class confusion, and improves the accuracy of image classification. Secondly, by calculating the Pearson correlation coefficient matrix on the feature vectors output by the deep feature extraction network and constructing a Pearson constraint loss function based on off-diagonal elements, the linear correlation between different dimensions of the feature vectors can be explicitly reduced. The beneficial effect of this technique is that it encourages the network to learn low-redundancy, highly independent feature representations, avoids information overlap between feature dimensions, thereby improving the utilization efficiency of the feature space, enhancing the model's generalization ability, and reducing the risk of overfitting. Thirdly, the triplet loss function and the Pearson constraint loss function are weighted and fused to obtain a total loss function for joint optimization. Its beneficial effects are manifested in that, while ensuring feature discriminative power, it introduces decorrelation constraints, enabling the network to achieve a balance between inter-class separation and feature independence. This allows the network to learn high-quality feature representations that are both compact and decoupled, further improving classification performance. Finally, by employing a hard example mining strategy to construct triplet sample batches and selecting boundary samples for training, the model convergence is accelerated and its ability to identify difficult samples is enhanced. Backpropagation is then performed using the total loss function to update network parameters until the convergence condition is met, resulting in a well-trained image classification model. The beneficial effect of this mechanism is that it enables the entire image classification model training process to have adaptive feature optimization capabilities, automatically coordinating discriminative and independence objectives under different datasets and class distributions, thereby steadily improving the model's classification accuracy in practical applications.

[0052] In another preferred embodiment based on the above embodiments, this implementation provides an image classification device that integrates triplet loss and Pearson constraint, including: a data acquisition module, a feature extraction module, a triplet loss calculation module, a Pearson constraint calculation module, a loss fusion and training module, and a classification prediction module.

[0053] Specifically, the data acquisition module is configured to acquire an image dataset and divide it into a training set and a test set, and construct triplet sample batches from the training set; the feature extraction module is electrically connected to the data acquisition module and is configured to input the triplet sample batches into a preset deep feature extraction network to extract the corresponding anchor feature vectors, positive sample feature vectors, and negative sample feature vectors; the triplet loss calculation module is electrically connected to the feature extraction module and is configured to calculate the triplet loss function based on the anchor feature vectors, positive sample feature vectors, and negative sample feature vectors; the Pearson constraint calculation module is electrically connected to the feature extraction module and is configured to perform deep feature calculations on the triplet loss function. The Pearson correlation coefficient matrix between feature dimensions is calculated by extracting the feature vectors output by the network, and a Pearson constrained loss function is constructed based on the off-diagonal elements. The loss fusion and training module is electrically connected to the triplet loss calculation module and the Pearson constrained loss function, respectively, and is configured to perform weighted fusion of the triplet loss function and the Pearson constrained loss function to obtain the total loss function. The total loss function is then used for backpropagation to update the network parameters, resulting in a trained image classification model. The classification prediction module is electrically connected to the loss fusion and training module and is configured to input the image to be classified into the trained image classification model and output the classification result of the image to be classified.

[0054] It is understood that the image classification method and apparatus that fuse triplet loss and Pearson constraint in the above embodiments have the same beneficial effects, and will not be described in detail here.

[0055] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program goods. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program goods embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0056] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program goods according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0057] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0058] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0059] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the specific implementation of the present invention. Any modifications or equivalent substitutions that do not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.

Claims

1. An image classification method that integrates triplet loss and Pearson constraint, characterized in that, Includes the following steps: S1. Obtain the image dataset and divide it into a training set and a test set. Construct a batch of triplet samples from the training set. Each triplet sample includes an anchor image, a positive sample image, and a negative sample image. S2. Input the triplet samples in batches into a preset deep feature extraction network to extract the corresponding anchor point feature vector, positive sample feature vector and negative sample feature vector; S3. Calculate the triplet loss function based on the anchor feature vector, positive sample feature vector, and negative sample feature vector; S4. Calculate the Pearson correlation coefficient matrix between feature dimensions of the feature vectors output by the deep feature extraction network, and construct the Pearson constrained loss function based on the off-diagonal elements of the Pearson correlation coefficient matrix to reduce the correlation between different dimensions of the feature vectors. S5. Weighted fusion of the triplet loss function and the Pearson constraint loss function to obtain the total loss function; S6. Backpropagation is performed using the total loss function to update the network parameters of the deep feature extraction network until the convergence condition is met, and a trained image classification model is obtained. S7. Input the image to be classified into the trained image classification model and output the classification result of the image to be classified.

2. The image classification method fusing triplet loss and Pearson constraint as described in claim 1, characterized in that, The steps for constructing the triplet sample batch include: A hard example mining strategy is used for sampling. For each anchor point image in a batch, its feature distance with the remaining images of the same category is calculated, and the image with the largest distance is selected as the positive sample image. Calculate the feature distance between the anchor point image and images of different categories, and select the image with the smallest distance as the negative sample image.

3. The image classification method fusing triplet loss and Pearson constraint as described in claim 1, characterized in that, The formula for calculating the triplet loss function is as follows: in, Represents the triplet loss function. Indicates the size of the sample batch. , and They represent the first Feature vectors of anchor point images, positive sample images, and negative sample images. Denotes the square of the L2 norm. This represents the preset boundary threshold parameter.

4. The image classification method fusing triplet loss and Pearson constraint as described in claim 1, characterized in that, S4 specifically includes: obtaining a feature matrix F with batch size B and feature dimension D. ; Calculate the Pearson correlation coefficient between the u-th and v-th features in the feature matrix. : in, Indicates the first The first sample 3D eigenvalues This indicates the first of all samples in this batch. The average value of the dimensional features; The off-diagonal elements of the Pearson correlation coefficient matrix are extracted and penalized to construct the Pearson constrained loss function. : in, This represents the Pearson-constrained loss function. The total dimension of the feature vectors. For the first Dimensional features and the first Pearson correlation coefficient between dimensional features, denominator Used to normalize the number of off-diagonal elements.

5. The image classification method fusing triplet loss and Pearson constraint as described in claim 4, characterized in that, The formula for calculating the total loss function obtained in S5 is as follows: in, Represents the total loss function. This represents the hyperparameter used to balance feature discriminative power and feature decorrelation.

6. The image classification method fusing triplet loss and Pearson constraint as described in claim 1, characterized in that, The deep feature extraction network includes a residual network backbone and a global average pooling layer and a fully connected dimensionality reduction layer connected to the ends of the residual network backbone. After the triplet samples are input into the residual network backbone to extract spatial feature maps, they are compressed into one-dimensional vectors by the global average pooling layer, and then mapped to a low-dimensional feature space based on the fully connected dimensionality reduction layer.

7. The image classification method fusing triplet loss and Pearson constraint as described in claim 1, characterized in that, The specific steps in S7 of inputting the image to be classified into the trained image classification model and outputting the classification result of the image to be classified include: The image to be classified is input into the trained deep feature extraction network to extract the target feature vector; The target feature vector is input into the classifier, and the probability value of the target feature vector belonging to each image category is calculated by the Softmax function; The category corresponding to the highest probability value is taken as the final classification result of the image to be classified.

8. An image classification apparatus that integrates triplet loss and Pearson constraint, applicable to the image classification method integrating triplet loss and Pearson constraint as described in any one of claims 1-7, characterized in that, include: The data acquisition module is used to acquire an image dataset and divide it into a training set and a test set, and construct a batch of triplet samples from the training set. Each triplet sample includes an anchor image, a positive sample image and a negative sample image. The feature extraction module is used to input the triplet samples in batches into a preset deep feature extraction network to extract the corresponding anchor point feature vector, positive sample feature vector and negative sample feature vector; The triplet loss calculation module is used to calculate the triplet loss function based on the anchor feature vector, positive sample feature vector, and negative sample feature vector. The Pearson constraint calculation module is used to calculate the Pearson correlation coefficient matrix between feature dimensions of the feature vectors output by the deep feature extraction network, and to construct the Pearson constraint loss function based on the off-diagonal elements of the Pearson correlation coefficient matrix. The loss fusion and training module is used to weightedly fuse the triplet loss function and the Pearson constraint loss function to obtain the total loss function; and to use the total loss function to perform backpropagation to update the network parameters to obtain the trained image classification model. The classification prediction module is used to input the image to be classified into the trained image classification model and output the classification result of the image to be classified.

9. An electronic device, characterized in that, Including memory and processor; The memory is used to store computer programs; The processor is configured to execute the computer program to implement an image classification method that integrates triplet loss and Pearson constraint as described in any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements an image classification method that integrates triplet loss and Pearson constraint as described in any one of claims 1 to 7.