Classification method based on similarity, equipment and medium

By constructing the similarity training data set and target loss function optimization, it is transformed into a binary classification problem, which solves the problem of high cost of data labeling and category imbalance in face recognition, and achieves more efficient and accurate classification, improving the robustness and generalization ability of the model.

CN120236306APending Publication Date: 2025-07-01XIN-HUANGPU JOINT INNOVATION INST OF CHINESE MEDICINE
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510078188.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-17
Publication Date
2025-07-01

AI Technical Summary

Technical Problem

The existing technology relies on deep learning methods in facial recognition, and there are problems of high cost of data labeling and category imbalance, resulting in limited learning effects of models in multi-category tasks, insufficient generalization ability, and affecting classification accuracy.

Method used

By constructing a similarity training data set, training a similarity classification model, using the target loss function to optimize feature extraction and classifier, transforming the five-classification problem into a two-classification problem, simplifying the data processing process, and improving the robustness and generalization ability of the model.

Benefits of technology

It effectively improves the learning effect and classification accuracy of the model, improves the performance of the model in category imbalance and small sample scenarios, and is suitable for face classification tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120236306A_ABST
    Figure CN120236306A_ABST
Patent Text Reader

Abstract

The invention discloses a similarity-based classification method and device, and a medium. The method comprises the steps of obtaining a to-be-classified image; inputting the to-be-classified image into a similarity classification model to obtain a classification result; wherein the similarity classification model is obtained by training according to a similarity training data set, and the similarity training data set comprises a training sample pair and a label; the training sample pair comprises a first training image and a second training image which are randomly selected; the label represents whether the first training image and the second training image belong to the same category. According to the method, the similarity classification model is trained through the similarity training data set, so that the learning effect of the model is effectively improved, more accurate classification is realized, and the robustness and generalization ability of the model are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of machine learning, and in particular to a classification method, device and medium based on similarity. Background Art

[0002] Face recognition technology has been widely used in security monitoring, identity authentication, financial payment and other fields. Existing technologies mostly rely on deep learning methods, especially convolutional neural networks (CNNs), which are trained through large-scale labeled data to extract facial features. However, the high cost of data annotation and the problem of category imbalance are still key factors restricting the development of these technologies. Especially in multi-category tasks, the small number of available training data sets leads to limited learning effects of the model during training, insufficient generalization ability, and affected classification accuracy. Summary of the invention

[0003] According to one aspect of the present invention, a similarity-based classification method, device, and medium are provided, which train a similarity classification model through a similarity training data set, effectively improve the learning effect of the model, achieve more accurate classification, and improve the robustness and generalization ability of the model.

[0004] In order to solve the above technical problems, the first aspect of the present invention discloses a classification method based on similarity, the method comprising: Get the image to be classified; Inputting the image to be classified into a similarity classification model to obtain a classification result; Among them, the similarity classification model is trained according to a similarity training data set, and the similarity training data set includes training sample pairs and labels; the training sample pairs include a randomly selected first training image and a second training image; the label indicates whether the first training image and the second training image belong to the same category.

[0005] In some implementations, inputting the image to be classified into a similarity classification model to obtain a classification result includes: Inputting the image to be classified into a similarity classification model to determine the similarity between the image to be classified and each category; According to the similarity between the image to be classified and each category, a classification result of the image to be classified is determined.

[0006] In some embodiments, the similarity classification model is trained by the following steps: Extracting a first feature of the first training image, and extracting a second feature of the second training image; Combining the first feature and the second feature to obtain a difference vector; using the difference vector as an input of a classifier to obtain labels of the first training image and the second training image; Train the similarity classification model using the target loss function until the training termination condition is reached.

[0007] In some embodiments, the difference vector is the absolute value difference between the first feature and the second feature.

[0008] In some embodiments, before extracting the first feature of the first training image and the second feature of the second training image, it further includes: Randomly select any two training images from the similarity training dataset to form the first training image and the second training image, and determine the labels of the first training image and the second training image; the training image is a face image with the classified result annotated.

[0009] In some embodiments, the target loss function is the Adam optimization algorithm and the cross-entropy loss function.

[0010] In some embodiments, determining the classification result of the image to be classified according to the similarity between the image to be classified and each category includes: Select the category corresponding to the highest similarity as the classification result of the image to be classified.

[0011] In some embodiments, inputting the image to be classified into the similarity classification model to determine the similarity between the image to be classified and each category includes: Compare the image to be classified with any sample image in each category of the similarity classification model to obtain the labels of the image to be classified and any sample image, where the label indicates whether the image to be classified and any sample image belong to the same category; Calculate the similarity ratio of the image to be classified with all sample images in each category according to the label to obtain the similarity between the image to be classified and each category.

[0012] According to the second aspect of the present invention, a computer device is disclosed, including: a processor and a memory; wherein, the memory stores a computer program, and the computer program is adapted to be loaded and executed by the processor to perform the steps of a similarity-based classification method as described in any one of the above.

[0013] According to the third aspect of the present invention, a computer storage medium is disclosed, on which a computer program is stored, and when the computer program is executed by a processor, it implements the steps of a similarity-based classification method as described above.

[0014] Compared with the prior art, the beneficial effects of the present invention are as follows: The present invention provides a similarity-based classification method, device, and medium. By training a model with a similarity training dataset and performing classification based on similarity, the data processing process in the traditional five-classification problem is simplified, and the generalization ability and classification accuracy of the model are improved. Through the training of the similarity training dataset, the learning effect of the model is effectively enhanced, enabling the similarity classification model to accurately judge the similarity between the image to be classified and the category, achieving efficient and accurate classification, and improving the robustness and generalization ability of the model. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] Figure 1 It is a schematic flowchart of the training stage of a similarity-based classification method provided by the present invention; Figure 2 It is a schematic flowchart of step S102 in the training stage of a similarity-based classification method provided by the present invention; Figure 3 It is a schematic flowchart of the application stage of a similarity-based classification method provided by the present invention; Figure 4 It is a schematic flowchart of step S302 in the application stage of a similarity-based classification method provided by the present invention; Figure 5 It is a schematic flowchart of step S401 in the application stage of a similarity-based classification method provided by the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0016] For better understanding and implementation, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

[0017] The terms "including" and "having" and any variations thereof in the embodiments of the present invention are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or modules does not necessarily have to be limited to those clearly listed steps or modules, but may include other steps or modules that are not clearly listed or are inherent to these processes, methods, products, or devices.

[0018] The embodiments of the present invention disclose a similarity-based classification method, device, and medium. By training a similarity classification model with a similarity training dataset, the learning effect of the model is effectively enhanced, more accurate classification is achieved, and the robustness and generalization ability of the model are improved.

[0019] The similarity classification model belongs to two stages, the training stage and the application stage (also called the inference stage). The similarity classification model is trained by using a similarity training data set and a target loss function.

[0020] As Figure 1 shown, the training process of the similarity classification model is described below: Step S101: Obtain a similarity training data set, which includes training sample pairs and labels; the training sample pairs include randomly selected first training images and second training images; the labels indicate whether the first training image and the second training image belong to the same category.

[0021] Select a certain number of images with the same quantity from the face classification data set to ensure the balance of samples for each category. The training sample pairs include a first training image and a second training image, which are any two classified images and can be randomly selected from the existing five-class face data set.

[0022] By randomly selecting any two training images from the original five-class face data set and combining them with labels to construct a two-class similarity training data set, the number of data sets available for training the model is effectively increased. For example, if there are 200 image data belonging to the gold category in the face classification data set, and two images are randomly selected from the gold category as the first training image and the second training image, then the total number of training sample pairs that can be generated is:

[0023] Based on the preliminary estimation of the above calculation formula, the training sample pairs of the training data can be increased to 100 times the original face data set, greatly increasing the amount of data available for model training and improving the training effect of the model. By increasing the training sample pairs, the similarity classification model can learn more diverse features and improve the generalization ability of the classifier. At the same time, in the case of class imbalance, the similarity classification model can better learn the subtle differences between different classes, thereby improving the classification accuracy.

[0024] Determine the labels of the training sample pairs, where the labels indicate whether the first training image and the second training image belong to the same category. Exemplarily, if the category of the first training image is gold and the category of the second training image is wood, then the first training image and the second training image do not belong to the same category, and the label is 0, serving as a negative sample pair; If the category of the first training image is water and the category of the second training image is water, then the first training image and the second training image belong to the same category, and the label is 1, serving as a positive sample pair.

[0025] Step S102: Train the initial similarity classification model using the target loss function until the training termination condition is reached.

[0026] Specifically, as Figure 2 shown, it includes the following steps: Step S201: Extract the first feature of the first training image and the second feature of the second training image.

[0027] Preprocess the first training image and the second training image, including but not limited to: size adjustment, normalization, etc. Use ResNet18 as the feature extractor Extractor to extract the first feature F1 of the first training image and the second feature F2 of the second training image. The first feature F1 and the second feature F2 are generally feature vectors with a dimension of 512, representing the high-dimensional semantic features of the first training image and the second training image.

[0028] Step S202: Combine the first feature and the second feature to obtain a difference vector; use the difference vector as the input of the classifier to obtain the labels of the first training image and the second training image.

[0029] The difference vector is the absolute value difference between the first feature and the second feature, representing the point-to-point difference of the training sample pair in the high-dimensional feature space. If the training sample pair is similar, the value of the difference vector F3 is close to 0. If the training sample pair is quite different and does not belong to the same category, the value of the difference vector F3 is large. The similarity or difference between the training sample pairs is reflected by the difference vector.

[0030] At the same time, since the first feature F1 and the second feature F2 are high-dimensional vectors, the values in each dimension may have significant differences. If the first feature F1 and the second feature F2 are directly used as inputs, it will be difficult for the classifier to directly learn the relative relationship between them. Through the absolute value difference calculation, the first feature and the second feature are uniformly transformed into the same feature space, clearly representing the feature differences of the training sample pairs. The classifier does not need to learn complex relationships additionally, greatly reducing the difficulty of the learning task. If the training sample pairs come from the same category, their feature differences are small, and the classifier can more easily judge them as the same category through the difference vector F3, effectively enhancing the feature expression ability and similarity judgment ability of the similarity classification model.

[0031] Obtain the labels of the first training image and the second training image through the output of the classifier, that is, determine whether the first training image and the second training image belong to the same category through the output of the classifier. If the first training image and the second training image do not belong to the same category, the label is dissimilar; if the first training image and the second training image belong to the same category, the label is similar.

[0032] Step S203: Train the similarity classification model using the target loss function until the training termination condition is reached.

[0033] Furthermore, train the classification model using the target loss function until the training termination condition is met. The target loss function is the Adam optimization algorithm and the cross-entropy loss function, and update the parameters in the feature extractor Extractor and the classifier Classifier. Through the optimization algorithm, the model learns the features of the input training images, obtains the facial features corresponding to the five classifications, and can accurately classify.

[0034] The training termination condition includes but is not limited to the target loss function reaching a preset threshold, the adjusted target loss function converging, the training reaching a preset number of times, or the training reaching a preset duration. After the training termination condition is met, determine the final similarity classification model.

[0035] The traditional face classification model generally classifies the image to be classified directly, while the output of the similarity classification model of this application is the label "the probability that the first training image and the second training image belong to the same category". That is to say, it is a binary classification model. And for the binary classification problem, only need to judge "the same category" or "different categories". This label simplification makes the training process more intuitive and easy to implement, and at the same time reduces the judgment difficulty of the classifier in the multi-category case. By using the training sample pairs and their labels, the five-classification problem of traditional face classification is transformed into a binary classification problem. The training samples of each category can be combined to generate new sample pairs, which not only increases the training data volume of the minority categories, but also effectively avoids the negative impact of class imbalance on the model performance. Each time of training only needs to learn to judge whether the training sample pair belongs to the same category, and the training efficiency of the model is greatly improved. Compared with the five-classification task, the training of the binary classification problem requires less computing resources, and the model structure is relatively simplified, and it can learn effective classification features in a shorter time.

[0036] In this implementation process, by constructing a similarity training data set, using the labels of each pair of images to clarify whether they belong to the same category, and training the classifier by calculating the image feature differences. In this way, the model can learn the similarity between images and judge whether new image pairs belong to the same category in actual applications, effectively improving the performance of the model in the case of class imbalance and small samples, and is applicable to tasks such as face classification.

[0037] As Figure 3 shown, in the application stage, this method includes the following steps: Step S301: Obtain the image to be classified.

[0038] The image to be classified generally refers to an image containing facial features captured by a user or acquisition device. The image has not been classified or processed yet and needs to be processed by a similarity classification model to determine its category. The image to be classified is generally a digitized two-dimensional image, usually a color or grayscale image, and common formats include JPEG, PNG, BMP, etc. The image resolution and size can be adjusted according to application requirements, usually 32×32 or 224×224 pixels. Generally, the face image to be classified contains one or more facial features, and can usually clearly show key parts such as the facial contour, eyes, nose, and mouth.

[0039] In some embodiments, after obtaining the image to be classified, before inputting into the similarity classification model, the face image to be classified usually needs to be preprocessed to ensure effective extraction of the facial region. Preprocessing includes identifying and locating the face region in the image through a face detection algorithm (such as OpenCV, Dlib), and adjusting the size, contrast, brightness, etc. of the image to meet the requirements of the model input.

[0040] Step S302: Input the image to be classified into a similarity classification model to obtain a classification result. The goal of the image to be classified is to identify and classify it into the category, such as gold, wood, water, fire, earth, etc., through the trained similarity classification model. The similarity classification model is a model trained in the above training stage.

[0041] Specifically, the following steps are included: Step S401: input the image to be classified into a similarity classification model to determine the similarity between the image to be classified and each category.

[0042] The image to be classified is input into the trained similarity classification model. The similarity classification model outputs the labels of the image to be classified and the pre-stored sample images. The similarity ratio of the categories is determined according to the labels. The specific steps are as follows: Step S501: compare the image to be classified with any sample image of each category in the similarity classification model to obtain labels of the image to be classified and any sample image, wherein the label indicates whether the image to be classified and any sample image belong to the same category.

[0043] In the similarity classification model, multiple sample images are pre-stored in each category, and the sample images represent the typical features of the category. The categories include "gold", "wood", "water", "fire" and "earth", so each category needs to pre-store several sample face images of the category.

[0044] The pre-stored sample images are used to calculate the similarity ratio between the image to be classified and each category. The sample image set of each category is a feature representation of the category, which helps the model determine which category the image to be classified belongs to.

[0045] Feature extraction is performed on the image to be classified to obtain the first feature F1. For each set of sample images of each category, the same feature extractor Extractor is used to perform feature extraction on the sample images to obtain the first feature F2 of the sample images. A difference vector F3 is determined based on the first feature F1 and the second feature F2, and the difference vector is used as the input of the classifier to obtain the labels of the image to be classified and the sample images, that is, to output whether the image to be classified and the sample images belong to the same category. If they belong to the same category, the output label is similar; if they belong to different categories, the output label is dissimilar.

[0046] The image to be classified is sequentially compared with all pre-stored sample images of each category to obtain the labels of the image to be classified and all sample images.

[0047] Step S502: Calculate the similarity ratio of the image to be classified and all sample images in each category according to the label to obtain the similarity of the image to be classified and each category.

[0048] For the sample images of each category, the proportion of similar labels is statistically calculated according to the label. The similarity ratio represents the overall similarity between the image to be classified and the sample images of this category.

[0049] The similarity ratio of a certain category = the number of similar labels / the number of sample images compared in this category. Exemplarily, if there are 100 sample images in the "gold" category and the image to be classified is similar to 70 of them, the similarity ratio is 0.7. Calculate the similarity ratio of each category in turn. For example, the similarity of the image to be classified to the "gold" category is 0.7, and the similarity to the "wood" category is 0.4.

[0050] Based on the above similarity ratio, a similarity vector similarity = [ratio_gold, ratio_wood, ratio_water, ratio_fire, ratio_earth] is obtained.

[0051] Step S402: Determine the classification result of the image to be classified according to the similarity ratio of the image to be classified and each category.

[0052] Select the category corresponding to the highest similarity in the similarity vector as the classification result of the image to be classified. The pre-stored sample images of each category are used to calculate the similarity between the image to be classified and each category. By extracting features from the image to be classified and the category sample images, the similarity classification model can judge the similarity between the image to be classified and each sample image in each category, and calculate the similarity proportion of each category accordingly. By selecting the category with the highest similarity in the similarity vector, that is, the category with the highest similarity proportion, as the predicted category of the image to be classified, accurate classification can be achieved. Based on the classification result, judge the physical characteristics of the individual, formulate a personalized health management plan, and conduct traditional Chinese medicine health preservation guidance, etc.

[0053] This method trains the model through a similarity training data set and classifies based on similarity, simplifies the data processing process in the traditional five-classification problem, and improves the generalization ability and classification accuracy of the model. Through the training of the similarity training data set, the similarity classification model can accurately judge the similarity between the image to be classified and the category, achieve efficient and accurate classification, and has strong practical application value.

[0054] The present invention also provides a device, which may include: a memory storing executable program code; a processor coupled to the memory; a transceiver for communicating with other devices or communication networks, receiving or sending network messages; a bus for connecting the memory, the processor, and the transceiver for internal communication.

[0055] The transceiver receives the messages transmitted on the network, transfers them to the processor through the bus. The processor calls the executable program code stored in the memory through the bus for processing, and transfers the processing result to the transceiver through the bus for sending, thereby implementing the method provided by the embodiments of the present application.

[0056] The embodiments of the present application also provide a non-transitory machine-readable storage medium, on which an executable program is stored. When the executable program is run by a processor, the processor is enabled to execute the processing method provided by the above embodiments.

[0057] The embodiments of the present invention disclose a computer-readable storage medium, which stores a computer program for electronic data exchange, wherein the computer program enables a computer to execute the described method.

[0058] The embodiments of the present invention disclose a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to enable a computer to execute the described method.

[0059] The embodiments described above are merely illustrative. The modules described as separate components may or may not be physically separated. The components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed to multiple network modules. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art can understand and implement it without creative work.

[0060] Through the specific description of the above embodiments, those skilled in the art can clearly understand that each implementation manner can be realized by means of software plus a necessary general hardware platform, and of course, it can also be realized by hardware. Based on such an understanding, the essence of the above technical solution, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium. The storage medium includes read-only memory (ROM), random access memory (RAM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), one-time programmable read-only memory (OTPROM), electrically-erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc memories, magnetic disk memories, tape memories, or any other computer-readable medium that can be used to carry or store data.

[0061] Finally, it should be noted that: what is disclosed in the embodiments of the present invention is only the preferred embodiments of the present invention, which are only used to illustrate the technical solutions of the present invention, rather than to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A classification method based on similarity, characterized in that: The method comprises: Get the image to be classified; Inputting the image to be classified into a similarity classification model to obtain a classification result; Among them, the similarity classification model is trained according to a similarity training data set, and the similarity training data set includes training sample pairs and labels; the training sample pairs include a randomly selected first training image and a second training image; the label indicates whether the first training image and the second training image belong to the same category.

2. A classification method based on similarity according to claim 1, characterized in that: Inputting the image to be classified into a similarity classification model to obtain a classification result, including: Inputting the image to be classified into a similarity classification model to determine the similarity between the image to be classified and each category; According to the similarity between the image to be classified and each category, a classification result of the image to be classified is determined.

3. A classification method based on similarity according to claim 1, characterized in that: The similarity classification model is trained by the following steps: Extracting a first feature of the first training image, and extracting a second feature of the second training image; Combining the first feature and the second feature to obtain a difference vector; using the difference vector as an input of a classifier to obtain labels of the first training image and the second training image; The similarity classification model is trained using the target loss function until the training termination condition is reached.

4. A classification method based on similarity according to claim 3, characterized in that: The difference vector is the absolute value difference between the first feature and the second feature.

5. The similarity-based classification method according to claim 3, characterized in that: Before extracting the first feature of the first training image and extracting the second feature of the second training image, the method further includes: Randomly select any two training images from the similarity training data set to form a first training image and a second training image, and determine the labels of the first training image and the second training image; the training images are face images with labeled classification results.

6. A classification method based on similarity according to claim 3, characterized in that: The objective loss function is the Adam optimization algorithm and the cross entropy loss function.

7. A classification method based on similarity according to claim 2, characterized in that: Determining the classification result of the image to be classified according to the similarity between the image to be classified and each category, including: The category corresponding to the highest similarity is selected as the classification result of the image to be classified.

8. A classification method based on similarity according to claim 2, characterized in that: Inputting the image to be classified into a similarity classification model to determine the similarity between the image to be classified and each category, including: Comparing the image to be classified with any sample image of each category in the similarity classification model to obtain labels of the image to be classified and any sample image, wherein the label indicates whether the image to be classified and any sample image belong to the same category; The similarity ratio between the image to be classified and all sample images in each category is calculated according to the label to obtain the similarity between the image to be classified and each category.

9. A computer device, characterized in that: include: A processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the steps of a similarity-based classification method as claimed in any one of claims 1 to 8.

10. A computer storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a processor, the steps of a classification method based on similarity as claimed in any one of claims 1 to 8 are implemented.