Learning method using unsupervised sample in image recognition scene
By constructing datasets with both labeled and unlabeled samples and training image recognition models using supervised and unsupervised loss methods, the problem of unlabeled samples being difficult to utilize is solved, and the model's performance on datasets with few labels is improved.
Patent Information
- Application Number
- CN202511720467.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-21
- Publication Date
- 2026-02-17
AI Technical Summary
In existing technologies, unlabeled samples cannot be effectively used for training neural network models. Semi-supervised learning relies on supervised models and has limited performance, making it difficult to achieve good results on datasets with few labeled samples.
A dataset containing labeled and unlabeled samples is constructed. The feature extraction module and the classification module are combined to calculate supervised and unsupervised losses. The parameters of the image recognition model are updated by the overall loss, and unsupervised samples are used to assist supervised training.
This improved the model's accuracy and dataset utilization when the number of labeled samples was small, resulting in a better-performing image recognition model.
Smart Images

Figure CN121545007A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of image recognition technology, and in particular relates to a learning method using unsupervised samples in image recognition scenarios. Background Technology
[0002] Image recognition is an important subfield of computer vision, closely related to human production and daily life. From facial recognition in high-speed rail stations and airports to campuses and residential communities, and product quality inspection in production, image recognition models have been widely used in various fields, effectively providing convenience to people. With the improvement of model performance and equipment performance, more and more faster and better image recognition models are replacing the original models, bringing even more convenience to production and daily life.
[0003] Model training typically requires datasets. During data acquisition, a large portion of the data is unlabeled, necessitating labeling later. However, labeling is labor-intensive and time-consuming, especially with large datasets. Therefore, datasets with only a few labeled or unlabeled samples are easier to obtain than datasets with all labeled samples. However, since unlabeled samples cannot be used to calculate loss using real labels, they cannot be used for traditional supervised neural network model training; they can only be used for unsupervised training, hence the term "unsupervised samples." In this context, the concept of semi-supervised learning emerged. In this concept, unlabeled samples can also be used to participate in neural network model training. This learning approach is closer to the human learning process and can utilize readily available unlabeled samples. However, current semi-supervised learning relies excessively on supervised learning models, and the performance of the chosen unsupervised learning models themselves is limited, making it difficult to achieve good results on datasets with few labeled samples. Summary of the Invention
[0004] The purpose of this invention is to overcome the shortcomings of the prior art and provide a learning method using unsupervised samples in image recognition scenarios.
[0005] Firstly, a learning method utilizing unsupervised samples in image recognition scenarios is provided, including:
[0006] S1. Construct a dataset, which includes labeled samples and unlabeled samples;
[0007] S2. Construct an image recognition model, which includes a feature extraction module and a classification module;
[0008] S3. Training the image recognition model includes: calculating the supervised loss for labeled samples and the unsupervised loss for unlabeled samples, calculating the overall loss based on the supervised loss and the unsupervised loss, and updating the parameters of the image recognition model using the overall loss;
[0009] S4. Evaluate the classification performance of the trained image recognition model.
[0010] Preferably, S1 includes:
[0011] S101. Select images and their correct labels from existing datasets or manually labeled data as labeled samples;
[0012] S102. Select unlabeled images from the unselected portion of the same dataset or manually labeled data as unlabeled samples;
[0013] S103. Perform image preprocessing on all labeled and unlabeled samples, including at least one of cropping, padding, and pixel value normalization.
[0014] S104. Divide the processed labeled samples into a training set, a validation set, and a test set, wherein the number of samples in the training set is greater than the sum of the number of samples in the validation set and the test set.
[0015] S105. Add the processed unlabeled samples to the training set to form the final training set;
[0016] S106. Divide the final training set into groups, each group including labeled samples and unlabeled samples, and the number of labeled samples, the number of unlabeled samples and the total number of samples in each group are consistent.
[0017] Preferably, S2 includes:
[0018] S201. Construct a feature extraction module to extract features from the input image;
[0019] S202. Construct a supervised learning deep model as a classification module for classification based on extracted features;
[0020] S203. Construct a combined model that integrates the feature extraction module and the classification module, wherein the output features of the feature extraction module are set as learnable parameters and participate in the computation graph of the classification module.
[0021] Preferably, in S201, the feature extraction module uses a pre-trained CLIP model and is initialized using publicly available pre-trained parameters.
[0022] Preferably, in S202, the supervised learning deep model includes APE-Training, TAC, or Transformer, and the loss function is selected to include at least one of L1 loss function, L2 loss function, or structural similarity loss function.
[0023] Preferably, S3 includes:
[0024] S301. For each group in the training set, calculate the overall loss of that group using the image recognition model;
[0025] S302. Optimize the parameters of the image recognition model using the overall loss;
[0026] S303. Use the validation set to calculate classification accuracy to monitor the training process;
[0027] S304. Repeat S301 to S303 until the training termination condition is met.
[0028] Preferably, in S304, the training termination conditions include reaching a preset number of training rounds, reaching a preset performance index, and the performance index on the validation set stabilizing or beginning to decline.
[0029] In a second aspect, a learning system utilizing unsupervised samples in an image recognition scenario is provided, for performing any of the methods described in the first aspect, including:
[0030] The first construction module is used to construct a dataset, which includes labeled samples and unlabeled samples.
[0031] The second construction module is used to construct an image recognition model, which includes a feature extraction module and a classification module.
[0032] The training module is used to train the image recognition model, including: calculating the supervised loss for labeled samples and the unsupervised loss for unlabeled samples, calculating the overall loss based on the supervised loss and the unsupervised loss, and updating the parameters of the image recognition model using the overall loss;
[0033] The evaluation module is used to evaluate the classification performance of the trained image recognition model.
[0034] Thirdly, a computer storage medium is provided, wherein a computer program is stored therein; when the computer program is run on a computer, the computer causes the computer to perform any of the methods described in the first aspect.
[0035] Fourthly, an electronic device is provided, comprising:
[0036] Memory, used to store computer programs;
[0037] A processor for executing the computer program to implement the method as described in any of the first aspects.
[0038] The beneficial effects of this invention are: it enables models to be trained using both supervised and unsupervised samples simultaneously, resulting in models that perform better than those trained only with supervised samples. This invention allows for model training using unsupervised samples, thereby improving model accuracy and dataset sample utilization. Attached Figure Description
[0039] Figure 1 A flowchart illustrating a learning method using unsupervised samples in an image recognition scenario provided by the present invention;
[0040] Figure 2 This is a schematic diagram of the framework provided for the present invention. Detailed Implementation
[0041] The present invention will be further described below with reference to embodiments. The description of the embodiments below is only for the purpose of helping to understand the present invention. It should be noted that those skilled in the art can make several modifications to the present invention without departing from the principle of the present invention, and these improvements and modifications also fall within the protection scope of the claims of the present invention.
[0042] Example 1:
[0043] To address the problems of existing technologies, Embodiment 1 of this application provides a learning method using unsupervised samples in image recognition scenarios, such as... Figure 1 As shown, it includes:
[0044] S1. Construct a dataset, which includes labeled samples and unlabeled samples.
[0045] S1 includes:
[0046] S101. Select images and their correct labels from existing datasets or manually labeled data as labeled samples;
[0047] S102. Select unlabeled images from the unselected portion of the same dataset or manually labeled data as unlabeled samples;
[0048] In S102, considering that not all datasets have unlabeled images, labeled images can be selected and the labels removed before being used as unlabeled samples to increase the number of datasets available for training.
[0049] S103. Perform image preprocessing on all labeled and unlabeled samples, including at least one of cropping, padding, and pixel value normalization.
[0050] S104. Divide the processed labeled samples into a training set, a validation set, and a test set, wherein the number of samples in the training set is greater than the sum of the number of samples in the validation set and the test set.
[0051] S105. Add the processed unlabeled samples to the training set to form the final training set;
[0052] S106. Divide the final training set into groups, each group including labeled samples and unlabeled samples, and ensure that the number of labeled samples, the number of unlabeled samples, and the total number of samples are consistent in each group. If the last group has insufficient samples, it can be discarded or retained without affecting the training.
[0053] S2. Construct an image recognition model, which includes a feature extraction module and a classification module.
[0054] S2 includes:
[0055] S201. Construct a feature extraction module to extract features from the input image.
[0056] In S201, the feature extraction module uses a pre-trained CLIP model and is initialized using publicly available pre-trained parameters.
[0057] S202. Construct a supervised learning deep model as a classification module for classification based on extracted features.
[0058] In S202, the supervised learning deep model includes APE-Training, TAC, or Transformer and its variants, and the loss function is selected to include at least one of L1 loss function, L2 loss function, or structural similarity loss function.
[0059] S203. Construct a combined model that integrates the feature extraction module and the classification module, wherein the output features of the feature extraction module are set as learnable parameters and participate in the computation graph of the classification module.
[0060] Specifically, S203 includes:
[0061] S2031. Obtain features F_S from all labeled samples in the final training set described in S105 using the feature extraction model constructed in S201, and set them as learnable parameters. Add them as an additional structure to the supervised model structure in S202, so that they can participate in the computation graph of the model and perform automatic differentiation and parameter updates during actual training. The new model as a whole is the combined model.
[0062] S2032. Select an appropriate optimizer for training the combined model, including but not limited to SGD, Ada, Adam and their variants, and initialize the optimizer according to empirical parameters.
[0063] S3. Training the image recognition model includes: calculating the supervised loss for labeled samples and the unsupervised loss for unlabeled samples, calculating the overall loss based on the supervised loss and the unsupervised loss, and updating the parameters of the image recognition model using the overall loss.
[0064] S4. Evaluate the classification performance of the trained image recognition model.
[0065] Example 2:
[0066] Based on Example 1, Example 2 of this application provides a more specific learning method using unsupervised samples in image recognition scenarios, including:
[0067] S1. Construct a dataset, which includes labeled samples and unlabeled samples.
[0068] S2. Construct an image recognition model, which includes a feature extraction module and a classification module.
[0069] S3. Training the image recognition model includes: calculating the supervised loss for labeled samples and the unsupervised loss for unlabeled samples, calculating the overall loss based on the supervised loss and the unsupervised loss, and updating the parameters of the image recognition model using the overall loss.
[0070] S3 includes:
[0071] S301. For each group in the training set, calculate the overall loss L of that group using the image recognition model.
[0072] Specifically, S301 includes:
[0073] S3011. Obtain the feature F_L from the labeled samples of each group through the feature extraction model constructed in S201.
[0074] S3012. Obtain the feature F_U from the unlabeled samples of each group through the feature extraction model constructed in S201.
[0075] S3013. Obtain the classification result logits from the feature F_L in S3011 through the supervised model initialized in step S204.
[0076] S3014. Obtain the classification result u_logits from the feature F_U in S3012 through the supervised model initialized in step S204, and transform it into a discrete classification result matrix Z corresponding to the classification label.
[0077] S3015. Calculate the similarity matrix B between F_U and the current F_S of the combined model.
[0078] S3016. Calculate the loss L_1 by combining the classification result logits in S3013 with the true labels of the labeled samples in the group according to the loss function selected in S2022.
[0079] S3017. Combine Z and B in S3024 using the following formula. Calculate the loss L_2, where c is the number of columns in matrix Z. Let be the i-th column of matrix Z. It is a diagonal matrix whose diagonal elements are the sum of all elements in B.
[0080] S3018. Calculate the overall loss index L for this group of L_1 and L_2 using a certain method for calculating the overall loss index. Generally, it is... θ is a positive number.
[0081] S302. Optimize the parameters of the image recognition model using the overall loss.
[0082] Specifically, the parameters of the combined model in S203, including the parameters of the supervised model and F_S, are optimized using the grouped overall loss index L in S301 according to the machine learning optimization method.
[0083] S303. Use the validation set to calculate classification accuracy to monitor the training process.
[0084] Specifically, the validation set samples described in S104 are classified using a feature extraction model and the currently trained supervised model to obtain classification results, and the classification accuracy of the validation set is calculated based on its true labels.
[0085] S304. Repeat S301 to S303 until the training termination condition is met.
[0086] In S304, the training termination conditions include reaching a preset number of training rounds, reaching a preset performance index (generally accuracy), and the performance index on the validation set stabilizing or beginning to decline.
[0087] S4. Evaluate the classification performance of the trained image recognition model.
[0088] Specifically, the classification results are obtained using the test set in S104 through the supervised model trained in S3, and the classification accuracy is calculated based on the true labels. The higher the accuracy, the better the classification model performance.
[0089] For example, the comparative test results of the classification accuracy of the present invention are shown in Table 1.
[0090] Table 1
[0091]
[0092] It should be noted that the parts in this embodiment that are the same as or similar to those in Embodiment 1 can be referred to each other, and will not be repeated in this application.
[0093] Example 3:
[0094] Based on Embodiment 2, Embodiment 3 of this application provides a learning system utilizing unsupervised samples in an image recognition scenario, comprising:
[0095] The first construction module is used to construct a dataset, which includes labeled samples and unlabeled samples.
[0096] The second construction module is used to construct an image recognition model, which includes a feature extraction module and a classification module.
[0097] The training module is used to train the image recognition model, including: calculating the supervised loss for labeled samples and the unsupervised loss for unlabeled samples, calculating the overall loss based on the supervised loss and the unsupervised loss, and updating the parameters of the image recognition model using the overall loss;
[0098] The evaluation module is used to evaluate the classification performance of the trained image recognition model.
[0099] It should be noted that the method provided in this embodiment is the corresponding system of the method provided in embodiment 2. Therefore, the parts that are the same as or similar to those in embodiment 2 in this embodiment can be referred to each other, and will not be repeated in this application.
[0100] In summary, the unsupervised learning model in this invention has stronger performance and can utilize information from unlabeled samples to assist supervised model training more quickly and effectively when the number of labeled samples is small, thereby obtaining a better-performing final model.
Claims
1. A learning method using unsupervised samples in an image recognition scenario, characterized in that, Comprising: S1, constructing a dataset, the dataset comprising labeled samples and unlabeled samples; S2, constructing an image recognition model, the image recognition model comprising a feature extraction module and a classification module; S3, training the image recognition model, comprising: calculating a supervised loss of the labeled samples and an unsupervised loss of the unlabeled samples, and calculating a total loss based on the supervised loss and the unsupervised loss, and updating parameters of the image recognition model using the total loss; S4, evaluating the classification performance of the trained image recognition model. 2.The learning method in an image recognition scenario using unsupervised samples according to claim 1, wherein, S1 comprises: S101, selecting pictures and their correct labels from existing datasets or manually annotated data as labeled samples; S102, selecting unlabeled pictures from the same dataset or the unselected part of the manually annotated data as unlabeled samples; S103, performing image preprocessing on all labeled samples and unlabeled samples, including at least one of cropping, padding, and pixel value standardization normalization processing; S104, dividing the processed labeled samples into a training set, a validation set, and a test set, wherein the number of training set samples is greater than the sum of the number of validation set and test set samples; S105, adding the processed unlabeled samples to the training set to form a final training set; S106, grouping the final training set, each group comprising labeled samples and unlabeled samples, and the number of labeled samples, the number of unlabeled samples, and the total number of samples in each group being consistent. 3.The learning method in image recognition scene using unsupervised samples according to claim 2, wherein S2 Comprising: S201, constructing a feature extraction module for extracting features from input images; S202, constructing a supervised learning deep model as a classification module for classification based on the extracted features; S203, constructing a combined model integrating the feature extraction module and the classification module, wherein the output features of the feature extraction module are set as learnable parameters and participate in the calculation graph of the classification module. 4.The learning method in an image recognition scenario using unsupervised samples according to claim 3, characterized in that, In S201, the feature extraction module uses a pre-trained CLIP model and is initialized using public pre-training parameters. 5.The learning method in image recognition scene using unsupervised samples according to claim 4, characterized in that, In S202, the supervised learning deep model comprises APE-Training, TAC, or Transformer, and at least one of the loss functions including L1 loss function, L2 loss function, or structural similarity loss function is selected. 6.The learning method using unsupervised samples in image recognition scenarios according to claim 5, characterized in that, S3 Comprising: S301, for each group in the training set, calculating the total loss of the group by the image recognition model; S302, optimizing the parameters of the image recognition model using the total loss; S303, calculating the classification accuracy using the validation set to monitor the training process; S304, repeating S301 to S303 until the training end condition is met. 7.The learning method in image recognition scene with unsupervised samples according to claim 6, characterized in that, In S304, the training end condition includes reaching a preset training round, reaching a preset performance indicator, the performance indicator on the validation set tending to be stable or starting to decline. 8.A learning system using unsupervised samples in an image recognition scenario, characterized in that, For executing the method of any one of claims 1 to 7, comprising: a first construction module for constructing a dataset, the dataset comprising labeled samples and unlabeled samples; a second construction module for constructing an image recognition model, the image recognition model comprising a feature extraction module and a classification module; The training module is configured to train the image recognition model, including: calculating a supervised loss of a labeled sample and an unsupervised loss of an unlabeled sample, calculating a total loss based on the supervised loss and the unsupervised loss, and updating parameters of the image recognition model by using the total loss; The evaluation module is configured to evaluate a classification performance of the trained image recognition model.
9. A computer storage medium, characterized in that The computer storage medium stores a computer program; when the computer program runs on a computer, the computer program causes the computer to execute the method in any one of claims 1 to 7.
10. An electronic device, comprising: The computer program product comprises: a memory configured to save the computer program; a processor configured to execute the computer program to implement the method in any one of claims 1 to 7.