Image classification model training method, image classification method and storage medium
By introducing the post-module and composite loss mechanism into the image classification model, the problem of the CLIP model's insufficient text semantic distinction ability is solved, the model performance is improved, and the text features with opposite semantics show negative correlation, which enhances the model's classification accuracy. sex.
Patent Information
- Application Number
- CN202310320735.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-28
- Publication Date
- 2024-10-01
AI Technical Summary
The CLIP model has deficiencies in text semantics and cannot effectively distinguish text encoding features with opposite semantics, resulting in insufficient model performance.
By introducing the post-module in the image classification model, the text encoder and the image encoder are used to determine the text features and image features in the candidate classification set respectively, and the cosine similarity sum of the text features in the candidate classification pair is calculated as the first loss, based on the classification The probability vector determines the second loss, which is combined with the composite loss to adjust the text encoder network parameters so that text features with opposite semantics exhibit opposite attributes.
The performance of the model is improved, so that text features with opposite semantics have negative cosine similarity, reflecting opposite attributes, enhancing the semantic consistency of text corresponding candidate classifications, and improving the classification accuracy of the model.
Smart Images

Figure CN118736260A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure generally relates to neural network-based image processing, and more specifically, to a training method for training an image classification model suitable for classifying images, an image classification method for classifying images, and a storage medium. Background Art
[0002] With the development of computer science and artificial intelligence, it is becoming more and more common and effective to use computers to run artificial intelligence models to process information. For example, an image classification model based on a neural network can be used to classify an input image, where the predicted classification is selected from a candidate classification set configured for the image classification model.
[0003] A pre-trained model that has been trained using a sample set such as a general database (for example, using a sample set in a specific field) can be trained again to obtain the desired classification result, such as a classification result with higher accuracy. The Contrastive Language-Image Pre-Training (CLIP) model is a trained image classification model. During the pre-training process, the model's image encoder and text encoder are used to encode sample images and texts corresponding to candidate categories, respectively. The similarity matrix is obtained by calculating the similarity between image encoding features and text encoding features. Comparative learning is used to increase the similarity between matching images and texts, and reduce the similarity between non-matching images and texts, thereby optimizing the network.
[0004] Typically, the above pre-training is performed on a large scale using “image-text pairs” and no semantic knowledge is learned on the text semantics. Summary of the invention
[0005] A brief overview of the present disclosure will be given below in order to provide a basic understanding of certain aspects of the present disclosure. It should be understood that this overview is not an exhaustive overview of the present disclosure. It is not intended to identify key or important parts of the present disclosure, nor is it intended to limit the scope of the present disclosure. Its purpose is simply to give certain concepts in a simplified form as a prelude to a more detailed description discussed later.
[0006] Considering the deficiencies of the CLIP model in text semantics, the inventors conceived the technical solution of the present disclosure. The technical problems solved by the embodiments of the present disclosure include but are not limited to at least one of the following: making the encoding features of two texts with opposite semantics also reflect opposite attributes, thereby improving the performance of the model.
[0007] According to one aspect of the present disclosure, a method for training an image classification model is provided, wherein the image classification model comprises a front module and a rear module connected to the output end of the front module, wherein the front module comprises a text encoder and an image encoder of a CLIP model, and the rear module is used to determine a classification result relative to a candidate classification set based on the output of the front module, and the candidate classification set is a union of a first classification set having a first semantic attribute value and a second classification set having a second semantic attribute value opposite to the first semantic attribute value. The method comprises: determining the corresponding text features of each candidate classification in the candidate classification set by the text encoder; determining the corresponding image features of the image sample by the image encoder; determining the classification probability vector of the image sample based on the corresponding text features and the corresponding image features by the rear module; determining the sum of the cosine similarities of the two text features in each candidate classification pair in a plurality of candidate classification pairs as a first loss; determining the second loss based on the classification probability vector; and adjusting the network parameters of the text encoder based on a composite loss associated with the first loss and the second loss; wherein one classification in each candidate classification pair in the plurality of candidate classification pairs belongs to the first classification set, and the other classification in each candidate classification pair in the plurality of candidate classification pairs belongs to the second classification set.
[0008] According to one aspect of the present disclosure, an image classification method is provided, which includes: using the image classification model trained by the aforementioned training method to classify a test image.
[0009] According to one aspect of the present disclosure, there is provided a computer-readable non-transitory storage medium storing a program. When the program is executed by a computer, the computer implements a training image classification model. The image classification model includes a front module and a rear module connected to the output end of the front module. The front module includes a text encoder and an image encoder of a CLIP model. The rear module is used to determine a classification result relative to a candidate classification set based on the output of the front module, and the candidate classification set is a union of a first classification set having a first semantic attribute value and a second classification set having a second semantic attribute value opposite to the first semantic attribute value. Training an image classification model includes the following operations: determining, by a text encoder, corresponding text features of each candidate classification in a candidate classification set; determining, by an image encoder, corresponding image features of an image sample; determining, by a post-module, a classification probability vector of the image sample based on corresponding text features and corresponding image features; determining, by a post-module, the sum of cosine similarities of two text features in each candidate classification pair in a plurality of candidate classification pairs as a first loss; determining a second loss based on the classification probability vector; and adjusting network parameters of the text encoder based on a composite loss associated with the first loss and the second loss; wherein, one classification in each of the plurality of candidate classification pairs belongs to the first classification set, and the other classification in each of the plurality of candidate classification pairs belongs to the second classification set.
[0010] According to one aspect of the present disclosure, a device for training an image classification model is provided. The device includes: a memory having instructions stored thereon; and at least one processor connected to the memory and used to execute the instructions on the memory to: train the image classification model. The image classification model includes a front module and a rear module connected to the output end of the front module, the front module includes a text encoder and an image encoder of a CLIP model, and the rear module is used to determine a classification result relative to a candidate classification set based on the output of the front module, and the candidate classification set is a union of a first classification set having a first semantic attribute value and a second classification set having a second semantic attribute value opposite to the first semantic attribute value. Training an image classification model includes the following operations: determining, by a text encoder, corresponding text features of each candidate classification in a candidate classification set; determining, by an image encoder, corresponding image features of an image sample; determining, by a post-module, a classification probability vector of the image sample based on corresponding text features and corresponding image features; determining, by a post-module, the sum of cosine similarities of two text features in each candidate classification pair in a plurality of candidate classification pairs as a first loss; determining a second loss based on the classification probability vector; and adjusting network parameters of the text encoder based on a composite loss associated with the first loss and the second loss; wherein, one classification in each of the plurality of candidate classification pairs belongs to the first classification set, and the other classification in each of the plurality of candidate classification pairs belongs to the second classification set.
[0011] The beneficial effects of the method, device and storage medium of the present disclosure include at least one of the following: making the encoding features of two texts with opposite semantics have a negative cosine similarity to be consistent with the semantic attributes of the two texts, and also reflecting the opposite attributes, thereby improving the performance of the model, wherein the texts correspond to candidate categories. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] The following description of the embodiments of the present disclosure will help to more easily understand the above and other purposes, features and advantages of the present disclosure with reference to the accompanying drawings. The accompanying drawings are only for the purpose of illustrating the principles of the present disclosure. The sizes and relative positions of the elements in the accompanying drawings are not necessarily drawn to scale. The same reference numerals may represent the same features. In the accompanying drawings:
[0013] Figure 1 An exemplary flow chart of a method for training an image classification model according to an embodiment of the present disclosure is shown;
[0014] Figure 2 An exemplary flow chart of a method for training a sentiment classification model according to an embodiment of the present disclosure is shown;
[0015] Figure 3 shows an association matrix of exemplary text features;
[0016] Figure 4 An exemplary flow chart of an image classification method according to an embodiment of the present disclosure is shown;
[0017] Figure 5 An exemplary block diagram showing an apparatus for training an image classification model according to an embodiment of the present disclosure; and
[0018] Figure 6 is an exemplary block diagram of an information processing device according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0019] Exemplary embodiments of the present disclosure are described below in conjunction with the accompanying drawings. For the sake of clarity and conciseness, not all features of the actual embodiments are described in the specification. However, it should be understood that many implementation-specific decisions may be made in the process of developing any such actual embodiments in order to achieve the specific goals of the developer, and these decisions may vary from embodiment to embodiment.
[0020] It is also necessary to explain here that, in order to avoid obscuring the contents of the present disclosure due to unnecessary details, only the device structure closely related to the scheme according to the contents of the present disclosure is shown in the accompanying drawings, while other details that are not closely related to the contents of the present disclosure are omitted.
[0021] It should be understood that the present disclosure is not limited to the described implementation forms due to the following description with reference to the accompanying drawings. In this article, where feasible, the embodiments can be combined with each other, features between different embodiments can be replaced or borrowed, and one or more features can be omitted in one embodiment.
[0022] Computer program code for performing operations of various aspects of the embodiments of the present disclosure may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, Smalltalk, C++, and the like, and conventional procedural programming languages such as the "C" programming language or similar programming languages.
[0023] The method of the present disclosure can be implemented, for example, by a circuit having a corresponding functional configuration, wherein the circuit includes a circuit for a processor.
[0024] One aspect of the present disclosure relates to a method for training a model M suitable for classifying images. The method can be implemented using a computer.
[0025] Reference below Figure 1 A method 100 for training an image classification model M according to an embodiment of the present disclosure is exemplarily described.
[0026] Figure 1 An exemplary flow chart of a method 100 for training an image classification model M according to an embodiment of the present disclosure is shown. The image classification model M includes a front module Mf and a rear module Mr connected to the output end of the front module Mf. The front module Mf includes a text encoder Text_Encoder and an image encoder Image_Encoder of a CLIP model, the text encoder Text_Encoder is used to encode the input text into a text feature txF, and the image encoder Image_Encoder is used to encode the input image into an image feature imF. The rear module Mr is used to determine the classification result relative to the candidate classification set cCs based on the output of the front module Mf. The candidate classification set cCs is a union of a first classification set cCs1 having a first semantic attribute value and a second classification set cCs2 having a second semantic attribute value opposite to the first semantic attribute value. The candidate classification set cCs includes a plurality of candidate classifications cC. For example, when the model M is used to classify images by emotions, the candidate classification set configured for the model M may contain words (i.e., prompts) describing emotions, such as "happy", "sad", "angry", "fear", "surprise", "relaxation". According to the semantic attributes, the candidate classification set can be divided into two candidate classification subsets, and the two candidate classification subsets represent the semantics relative (opposite) to each other. A semantic attribute value is assigned to each candidate classification, so that each candidate classification can be classified into a corresponding candidate classification subset based on the semantic attribute value. For example, for an exemplary candidate classification set for emotion classification: {"happy", "sad", "angry", "fear", "surprise", "relaxation"}, the candidate classification set can be divided into a positive candidate classification subset (first classification set) and a negative candidate classification subset (second classification set) according to positive semantic emotions and negative semantic emotions. The positive candidate classification subset is {"happy", "relaxation"}, and the semantic attribute value of each element can be assigned to "1" to represent the positive semantic attribute; the negative candidate classification subset is {"sad", "angry", "fear", "surprise"}, and the semantic attribute value of each element can be assigned to "-1" to represent the negative semantic attribute. That is, in the present disclosure, the candidate classification pair is composed of two candidate classifications with opposite semantic attribute values. Method 100 is generally an iterative training in the field of artificial intelligence, and each iterative training round includes inputting the current batch of samples, extracting features, determining model output, determining loss, and adjusting network parameters until a predetermined condition is met (i.e., a termination condition; for example, reaching a set number of iterations, the loss is less than a predetermined threshold, the loss meets the convergence criterion, the loss change is less than a predetermined threshold, etc.). Figure 1 The method 100 shown in FIG. 1 includes typical operations.
[0027] like Figure 1As shown in , before model training, a training sample set and a candidate classification set are provided. The candidate classification set can be a collection of texts representing classifications. The training sample set is divided into multiple batches and provided to the model for iterative training. The classification of each sample has been labeled.
[0028] In operation Op101, the text encoder Text_Encoder determines the corresponding text features txF of each candidate category in the candidate category set cCs; and the image encoder Image_Encoder determines the corresponding image features imF of the image sample Im.
[0029] In operation Op103, the classification probability vector pV of the image sample is determined by the post-module Mr based on the text feature txF and the image feature imF.
[0030] In operation Op105, the sum of the cosine similarities of the two text features in each of the multiple candidate classification pairs is determined as the first loss Loss_sem. Any candidate classification pair (cC[ip], cC[jn]) selected for determining the first loss includes two classifications, recorded as the first candidate classification cC[ip] and the second candidate classification cC[jn], the first candidate classification belongs to the first classification set cCs1, and the second candidate classification belongs to the second classification set cCs2. For example, when the first classification set is a positive candidate classification set and the second classification set is a negative candidate classification set, the candidate classification pair can be recorded as "(cC[ip], cC[jn])", cC[ip] indicates a positive candidate classification, and cC[jn] indicates a negative candidate classification. The first loss is related to the opposite semantics (Contrary Semantics) of the text of the candidate classification pair, so it can also be called "opposite semantics loss"
[0031] In operation Op107, a second loss Loss_poss is determined based on the classification probability vector pV. For example, the predicted classification of the sample image can be determined based on the classification probability vector, and the second loss can be determined based on the predicted classification and the classification truth value of the label of the sample image. The second loss is related to the accuracy of the predicted classification, so the second loss is also called "classification loss".
[0032] In operation Op109 , the network parameters of the text encoder are adjusted based on the composite loss Loss_com associated with the first loss Loss_sem and the second loss Loss_poss, that is, the network parameters of the text encoder are optimized so that the composite loss is reduced.
[0033] In one embodiment, the candidate classification set is a sentiment classification set including a plurality of sentiment classifications. In one example, the first classification set is composed of positive sentiment classifications in the sentiment classification set; and the second classification set is composed of negative sentiment classifications in the sentiment classification set.
[0034] In one embodiment, the rear module Mr includes: a feature conversion layer Lc, a linear fully connected layer Ln and a softmax layer Ls. The feature conversion layer is configured to determine the Logits feature F_Logits of the image sample Im[i] based on the text feature txF[i] and the image feature imF[i]. For example, the dot product result of the text feature txF[i] and the image feature imF[i] is used as the Logits feature F_Logits. The linear fully connected layer is configured to determine the conversion feature Fc of the Logits feature. The conversion feature Fc is a 1*N vector, where N is the number of elements in the candidate classification set. The softmax layer is configured to determine the classification probability vector pV of the image sample Im[i] based on the conversion feature.
[0035] In one embodiment, the composite loss Loss_com associated with the first loss Loss_sem and the second loss Loss_poss is a weighted sum of the first loss and the second loss.
[0036] Loss_com=λ*Loss_sem+Loss_poss (1)
[0037] Here, λ is a weighting coefficient of the weighted summation, an exemplary value range includes [1.4, 1.6], and an exemplary value may be 1.5.
[0038] In one example, the composite loss is the sum of the product of the first loss and the first weighting coefficient and the product of the second loss and the second weighting coefficient; the first weighting coefficient is greater than the second weighting coefficient. For example, the ratio of the first weighting coefficient ("λ") to the second weighting coefficient ("1") is in the range of [1.3, 2.0].
[0039] In one embodiment, the second loss Loss_poss is a cross entropy (CE) loss.
[0040] In one embodiment, the number of multiple candidate classification pairs is at least the difference between the number of candidate classifications in the candidate classification set and 1. For example, when there are 6 candidate classifications, including 2 positive candidate classifications and 4 negative candidate classifications, the first positive candidate classification of the 2 positive candidate classifications can be selected to form a candidate classification pair with each negative candidate classification (i.e., 4 candidate classification pairs are obtained), and the remaining positive candidate classification is paired with any negative candidate classification to obtain 1 candidate classification pair, and a total of 5 candidate classification pairs are obtained. Selecting the number of candidate classification pairs in this way can reduce the amount of calculation and save training time. For a candidate classification set containing n1 positive candidate classifications and n2 negative candidate classifications, n1+n2-1 candidate classification pairs can be configured, or n1*n2 candidate classification pairs can be configured.
[0041] After training by method 100, the text encoder of the image classification model M will be improved, and the correlation matrix of the text features of the candidate classification output by it will show obvious characteristics: the cosine similarity of two opposite candidate classifications is a negative value close to -1, that is, when the semantics of the text pair of the candidate classification pair have a negative correlation, the obtained text feature pair will also have a negative correlation. The correlation matrix of the text features of n candidate classifications is an n*n matrix, and the element e ij is the cosine similarity between the i-th text feature and the j-th text feature. When i=j, the element value is "1". After training, if the i-th text feature and the j-th text feature belong to the same candidate classification subset (for example, they belong to the "first classification set" or the "second classification set"), the element e of the association matrix is ij The value of is positive.
[0042] The example of method 100 is used to train an emotion classification model Me. The emotion classification model Me is used to determine the classification of the emotion presented by the face in the input image containing the face. Figure 2 Describe this example method.
[0043] Figure 2 FIG. 2 shows an exemplary flow chart of a method 200 for training a sentiment classification model according to an embodiment of the present disclosure. The method 200 is also an iterative training process. Figure 2 The operations in a typical iterative training round are shown in FIG.
[0044] like Figure 2 As shown in , in a typical iterative training round, three operations are included: a first operation Op1 corresponding to encoding, a second operation Op2 corresponding to loss calculation, and a third operation Op3 corresponding to adjusting the text encoder.
[0045] At the beginning of training, N candidate classifications cC[1] to cC[N] and N sample images Im[1] to Im[N] of the current batch are provided. The candidate classification set cCs composed of exemplary candidate classifications is, for example, {"happy", "sad", "angry", "fear", "surprise", "relaxed"}, in which case N = 6. The sample images can be, for example, images containing human facial expressions in the public sample set ImageNet.
[0046] The first operation Op1 of the corresponding encoding includes: the text encoder Text_Encoder determines the corresponding text features txF of each candidate category in the candidate category set cCs, and obtains N text features txF[1] to txF[N]; and the image encoder Image_Encoder determines the corresponding image features imF of each image sample Im, and obtains N image features imF[1] to imF[N].
[0047] The second operation Op2 corresponding to the loss calculation includes a first sub-operation Op21 for calculating the first loss Loss_sem, and a second sub-operation Op22 for calculating the second loss Loss_poss. In the first sub-operation Op21, the sum of the cosine similarities of the two text features in each of the multiple candidate classification pairs is determined as the first loss Loss_sem. For any candidate classification pair (cC[ip], cC[jn]), it includes two classifications, denoted as the first candidate classification cC[ip] and the second candidate classification cC[jn], the first candidate classification belongs to the first classification set cCs1, and the second candidate classification belongs to the second classification set cCs2. Exemplarily, the first candidate classification set cCs1 is {"happy", "relaxed"}, and the second candidate classification set cCs2 is {"sad", "angry", "fear", "surprise"}. The following 6 candidate classification pairs can be selected to calculate the first loss Loss_sem:
[0048] ("happy", "sad");
[0049] ("happy", "angry");
[0050] ("happiness", "fear");
[0051] (“happy”, “surprised”); and
[0052] (“Relaxed”, “Sad”).
[0053] The first loss Loss_sem is calculated using the following 6 cosine similarities:
[0054] loss_sem1 = cosine(Text_features[“happy”], Text_features[“sad”]);
[0055] Loss_sem2 = cosine(Text_features[“happy”], Text_features[“angry”]);
[0056] loss_sem3 = cosine(Text_features[“happy”], Text_features[“fear”]);
[0057] loss_sem4 = cosine(Text_features[“happy”], Text_features[“surprised”]);
[0058] loss_sem5 = cosine(Text_features[“relax”], Text_features[“sad”]);
[0059] loss_sem6 = cosine(Text_features[“relaxation”], Text_features[“anger”]).
[0060] Among them, Text_features[“XX”] represents the text features obtained by encoding the candidate classification “XX” by the text encoder, and consine(X1,X2) represents the cosine similarity between features X1 and X2. The corresponding first loss Loss_sem is expressed as formula (2).
[0061] Loss_sem=loss_sem1+loss_sem2+loss_sem3+loss_sem4+loss_sem5+loss_sem6(2)
[0062] The second sub-operation Op22 of calculating the second loss Loss_poss includes determining the classification loss as the second loss Loss_poss based on the classification probability vectors pV[1] to pV[N] of the sample image. Exemplarily, the second loss Loss_poss may be a cross entropy loss. The second loss is determined with reference to the true value of the sample image.
[0063] In the third operation Op3 corresponding to adjusting the text encoder, the network parameters of the text encoder are adjusted based on the composite loss Loss_com associated with the first loss Loss_sem and the second loss Loss_poss, that is, the network parameters of the text encoder are optimized so that the composite loss is reduced.
[0064] The text encoder of the sentiment classification model trained by method 200 will change relative to the text encoder before training, and the correlation matrix Mct of the text features of the candidate classifications outputted by the method 200 will show obvious characteristics: the cosine similarity of two opposite candidate classifications is a negative value close to -1, that is, when the semantics of the text pairs of the candidate classification pairs have a negative correlation, the obtained text feature pairs will also have a negative correlation. Furthermore: in the correlation matrix, the elements of two candidate classifications of the same candidate classification subset (for example, the "positive sentiment classification set") are positively correlated (that is, the corresponding elements are positive values), and the elements of two candidate classifications belonging to different candidate classification subsets (for example, the "positive sentiment classification set" and the "negative sentiment classification set") are negatively correlated (that is, the corresponding elements are negative values). Figure 3The correlation matrix Mc0 determined by the text features output by the text encoder of the pre-trained model and the correlation matrix Mct determined by the text features output by the text encoder of the sentiment classification model trained by method 200 are shown. The correlation matrix Mct shows that for text pairs with opposite semantic attributes, the similarity of the two features in the text feature pair is negative and close to -1. The text features given by the text encoder incorporate the semantic information of the corresponding text.
[0065] The experiment was conducted using samples from the public dataset ImageNet. Before using method 200, the accuracy of the emotion classification model was 65.1%. After training with method 200, the accuracy of the emotion classification model was 70.3%, and the accuracy of the model was improved.
[0066] The present disclosure also relates to an image classification method. Figure 4 The method is described.
[0067] Figure 4 An exemplary flow chart of an image classification method 400 according to an embodiment of the present disclosure is shown. In operation Op401, an image classification model M is trained using method 100. In operation Op403, a test image is classified using the trained image classification model. The classification candidate set of the classification model M may be a sentiment classification set. The cosine similarity of two text features in each of a plurality of candidate classification pairs determined by a text encoder of the trained image classification model is a negative value. When an image classification model M trained using method 100 is already available, operation Op401 may be omitted.
[0068] According to one embodiment of the present disclosure, a computer-readable non-transitory storage medium storing a program is provided. When the program is executed by a computer, the computer implements a training image classification model, which includes a front module and a rear module connected to the output end of the front module, the front module includes a text encoder and an image encoder of a CLIP model, and the rear module is used to determine a classification result relative to a candidate classification set based on the output of the front module, and the candidate classification set is a union of a first classification set with a first semantic attribute value and a second classification set with a second semantic attribute value opposite to the first semantic attribute value. It is characterized in that the training image classification model includes the following operations: determining the corresponding text features of each candidate classification in the candidate classification set by the text encoder; determining the corresponding image features of the image sample by the image encoder; determining the classification probability vector of the image sample based on the corresponding text features and the corresponding image features by the rear module; determining the sum of the cosine similarities of two text features in each candidate classification pair in a plurality of candidate classification pairs as a first loss; determining the second loss based on the classification probability vector; and adjusting the network parameters of the text encoder based on a composite loss associated with the first loss and the second loss; wherein, one classification in each of the plurality of candidate classification pairs belongs to the first classification set, and the other classification in each of the plurality of candidate classification pairs belongs to the second classification set. For further details of the above operations, reference may be made to the description of method 100 and method 200 .
[0069] One aspect of the present disclosure relates to a storage medium for image classification. According to one embodiment, the storage medium is a computer-readable non-transitory storage medium having a program stored thereon. When the program is executed by a computer, the computer performs the following operations: classifying images in a test set using method 400.
[0070] In one embodiment of the present disclosure, a device for training an image classification model is provided. Figure 5 An exemplary description is given. Figure 5An exemplary block diagram of an apparatus 500 for training an image classification model according to an embodiment of the present disclosure is shown. The apparatus 500 includes: a memory 501 on which instructions are stored; and at least one processor 503, connected to the memory 501, and used to execute the instructions on the memory 501 to: train the image classification model. The image classification model includes a front module and a rear module connected to the output end of the front module, the front module includes a text encoder and an image encoder of a CLIP model, and the rear module is used to determine the classification result relative to a candidate classification set based on the output of the front module, and the candidate classification set is a union of a first classification set having a first semantic attribute value and a second classification set having a second semantic attribute value opposite to the first semantic attribute value. Training the image classification model includes the following operations: determining the corresponding text features of each candidate classification in the candidate classification set by the text encoder; determining the corresponding image features of the image sample by the image encoder; determining the classification probability vector of the image sample based on the corresponding text features and the corresponding image features by the post-module; determining the sum of the cosine similarities of the two text features in each candidate classification pair in multiple candidate classification pairs as the first loss; determining the second loss based on the classification probability vector; and adjusting the network parameters of the text encoder based on the composite loss associated with the first loss and the second loss; wherein, one classification in each candidate classification pair in the multiple candidate classification pairs belongs to the first classification set, and the other classification in each candidate classification pair in the multiple candidate classification pairs belongs to the second classification set. For further details of the above operations, reference may be made to the description of methods 100 and 200.
[0071] The present disclosure also relates to an information processing device. Figure 6 is an exemplary block diagram of an information processing device 600 according to an embodiment of the present disclosure. Figure 6 In the embodiment, a central processing unit (CPU) 601 performs various processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage device 608 to a random access memory (RAM) 603. In the RAM 603, data and the like required when the CPU 601 performs various processes are also stored as needed.
[0072] The CPU 601, the ROM 602, and the RAM 603 are connected to one another via a bus 604. An input / output interface 605 is also connected to the bus 604.
[0073] The following components are connected to the input / output interface 605: an input device 606 including a soft keyboard, etc.; an output device 607 including a display such as a liquid crystal display (LCD), etc. and a speaker, etc.; a storage device 608 such as a hard disk; and a communication device 609 including a network interface card such as a LAN card, a modem, etc. The communication device 609 performs communication processing via a network such as the Internet, a local area network, a mobile network, or a combination thereof.
[0074] A drive 610 is also connected to the input / output interface 605 as needed. A removable medium 611 such as a semiconductor memory or the like is mounted on the drive 610 as needed, so that a program read therefrom is installed to the storage device 608 as needed.
[0075] The CPU 601 may execute a program corresponding to a method for training an image classification model or an image classification method.
[0076] The method, device and storage medium of the present disclosure have at least one of the following beneficial effects: making the encoded features (i.e., text features) of two texts with opposite semantic attributes output by the text encoder of the image classification model have a negative cosine similarity close to "-1" (for example, in the range of [-0.80, -0.99]), so as to be consistent with the semantic relationship between the two texts and also reflect the opposite attributes, and the output text features contain more semantic information; improving model performance. For example, "happy" and "sad" are two opposite concepts in daily cognition, but the CLIP model does not know this knowledge. In the test phase, a "happy" image is input, and the cosine similarity of the obtained image features with respect to the "happy" classification feature and the "sad" classification feature will not show the opposite state; after the model is trained based on the training method of the present disclosure, the cosine similarity obtained will show the opposite state.
[0077] As described above, according to the present disclosure, the principle of training an image classification model, i.e., the principle of classifying images, has been disclosed. It should be noted that the effects of the scheme of the present disclosure are not necessarily limited to the above-mentioned effects, and in addition to or instead of the effects described in the previous paragraphs, any effect shown in this specification or other effects that can be understood from this specification can be achieved.
[0078] Although the present invention has been disclosed above through the description of the specific embodiments of the present invention, it should be understood that those skilled in the art can design various modifications (including, in the case of operation, the combination or replacement of features between the various embodiments), improvements or equivalents of the present invention within the spirit and scope of the appended claims. These modifications, improvements or equivalents should also be considered to be included in the protection scope of the present disclosure.
[0079] It should be emphasized that the term “include / comprises” when used herein refers to the presence of features, elements, steps or components, but does not exclude the presence or addition of one or more other features, elements, steps or components.
[0080] In addition, the methods of the embodiments of the present invention are not limited to being executed in the time sequence described in the specification or shown in the drawings, and may also be executed in other time sequences, in parallel or independently. Therefore, the execution order of the methods described in this specification does not limit the technical scope of the present invention.
[0081] Notes
[0082] The present disclosure includes, but is not limited to, the following schemes.
[0083] 1. A method for training an image classification model, the image classification model comprising a front module and a rear module connected to the output end of the front module, the front module comprising a text encoder and an image encoder of a CLIP model, the rear module being used to determine a classification result relative to a candidate classification set based on the output of the front module, and the candidate classification set being a union of a first classification set having a first semantic attribute value and a second classification set having a second semantic attribute value opposite to the first semantic attribute value, characterized in that the method comprises:
[0084] Determining, by the text encoder, corresponding text features of each candidate classification in the candidate classification set;
[0085] determining, by the image encoder, corresponding image features of the image samples;
[0086] The rear module determines a classification probability vector of the image sample based on the corresponding text features and the corresponding image features;
[0087] Determine the sum of cosine similarities of two text features in each of the plurality of candidate classification pairs as a first loss;
[0088] determining a second loss based on the classification probability vector; and
[0089] adjusting a network parameter of the text encoder based on a composite loss associated with the first loss and the second loss;
[0090] One category in each of the plurality of candidate category pairs belongs to the first category set, and the other category in each of the plurality of candidate category pairs belongs to the second category set.
[0091] 2. The method according to Note 1, wherein the candidate classification set is an emotion classification set including multiple emotion classifications.
[0092] 3. The method according to Supplement 2, wherein the first classification set consists of positive emotion classifications in the emotion classification set; and
[0093] The second classification set consists of negative emotion classifications in the emotion classification set.
[0094] 4. The method according to Supplement 1, wherein the rear module comprises:
[0095] A feature conversion layer, configured to determine a Logits feature of the image sample based on the corresponding text feature and the corresponding image feature;
[0096] A linear fully connected layer configured to determine a transformation feature of the Logits feature; and
[0097] The softmax layer is configured to determine a classification probability vector of the image sample based on the transformed features.
[0098] 5. The method according to Note 1, wherein the compound loss associated with the first loss and the second loss is a weighted sum of the first loss and the second loss.
[0099] 6. The method according to Note 1, wherein the composite loss is the sum of the product of the first loss and a first weighting coefficient and the product of the second loss and a second weighting coefficient; and
[0100] The first weighting coefficient is greater than the second weighting coefficient.
[0101] 7. The method according to Note 6, wherein the ratio of the first weighting coefficient to the second weighting coefficient is in the range of [1.3, 2.0].
[0102] 8. The method according to Note 6, wherein the ratio of the first weighting coefficient to the second weighting coefficient is in the range of [1.4, 1.6].
[0103] 9. The method of claim 1, wherein the second loss is a cross entropy loss.
[0104] 10. The method according to Note 1, wherein the number of the multiple candidate classification pairs is at least the difference between the number of candidate classifications in the candidate classification set and 1.
[0105] 11. An image classification method, characterized by comprising:
[0106] The test images are classified using the image classification model trained according to the method described in Note 1.
[0107] 12. The method according to Note 11, wherein the cosine similarity of the two text features in each of the multiple candidate classification pairs determined by the text encoder of the trained image classification model is a negative value.
[0108] 13. A computer-readable non-transitory storage medium storing a program, when the program is executed by a computer, the computer implements a training image classification model, the image classification model includes a front module and a rear module connected to the output end of the front module, the front module includes a text encoder and an image encoder of a CLIP model, the rear module is used to determine a classification result relative to a candidate classification set based on the output of the front module, and the candidate classification set is a union of a first classification set having a first semantic attribute value and a second classification set having a second semantic attribute value opposite to the first semantic attribute value, characterized in that the training image classification model includes the following operations:
[0109] Determining, by the text encoder, corresponding text features of each candidate classification in the candidate classification set;
[0110] determining, by the image encoder, corresponding image features of the image samples;
[0111] The rear module determines a classification probability vector of the image sample based on the corresponding text features and the corresponding image features;
[0112] Determine the sum of cosine similarities of two text features in each of the plurality of candidate classification pairs as a first loss;
[0113] determining a second loss based on the classification probability vector; and
[0114] adjusting a network parameter of the text encoder based on a composite loss associated with the first loss and the second loss;
[0115] One category in each of the plurality of candidate category pairs belongs to the first category set, and the other category in each of the plurality of candidate category pairs belongs to the second category set.
[0116] 14. The computer-readable non-transitory storage medium according to Note 13, wherein the candidate classification set is an emotion classification set including multiple emotion classifications.
[0117] 15. The computer-readable non-transitory storage medium according to Note 14, wherein the first classification set consists of positive emotion classifications in the emotion classification set; and
[0118] The second classification set consists of negative emotion classifications in the emotion classification set.
[0119] 16. The computer-readable non-transitory storage medium according to Note 13, wherein the post-module comprises:
[0120] A feature conversion layer, configured to determine a Logits feature of the image sample based on the corresponding text feature and the corresponding image feature;
[0121] A linear fully connected layer configured to determine a transformation feature of the Logits feature; and
[0122] The softmax layer is configured to determine a classification probability vector of the image sample based on the transformed features.
[0123] 17. The computer-readable non-transitory storage medium according to Note 13, wherein a composite loss associated with the first loss and the second loss is a weighted sum of the first loss and the second loss.
[0124] 18. The computer-readable non-transitory storage medium according to Note 13, wherein the composite loss is the sum of the product of the first loss and a first weighting coefficient and the product of the second loss and a second weighting coefficient; and
[0125] The first weighting coefficient is greater than the second weighting coefficient.
[0126] 19. The computer-readable non-transitory storage medium according to Note 18, wherein a ratio of the first weighting coefficient to the second weighting coefficient is in the range of [1.3, 2.0].
[0127] 20. A computer-readable non-transitory storage medium according to Note 18, wherein a ratio of the first weighting coefficient to the second weighting coefficient is in the range of [1.4, 1.6].
Claims
1. A method for training an image classification model, the image classification model comprising a front module and a rear module connected to the output end of the front module, the front module comprising a text encoder and an image encoder of a CLIP model, the rear module being used to determine a classification result relative to a candidate classification set based on the output of the front module, and the candidate classification set being a union of a first classification set having a first semantic attribute value and a second classification set having a second semantic attribute value opposite to the first semantic attribute value, characterized in that: The method comprises: Determining, by the text encoder, corresponding text features of each candidate classification in the candidate classification set; determining, by the image encoder, corresponding image features of the image samples; The rear module determines a classification probability vector of the image sample based on the corresponding text features and the corresponding image features; Determine the sum of cosine similarities of two text features in each of the plurality of candidate classification pairs as a first loss; determining a second loss based on the classification probability vector; and adjusting a network parameter of the text encoder based on a composite loss associated with the first loss and the second loss; One category in each of the plurality of candidate category pairs belongs to the first category set, and the other category in each of the plurality of candidate category pairs belongs to the second category set.
2. The method according to claim 1, wherein: The candidate classification set is an emotion classification set including a plurality of emotion classifications.
3. The method according to claim 2, wherein: The first classification set consists of positive emotion classifications in the emotion classification set; and The second classification set consists of negative emotion classifications in the emotion classification set.
4. The method according to claim 1, wherein: The rear module comprises: A feature conversion layer, configured to determine a Logits feature of the image sample based on the corresponding text feature and the corresponding image feature; A linear fully connected layer configured to determine a transformation feature of the Logits feature; and The softmax layer is configured to determine a classification probability vector of the image sample based on the transformed features.
5. The method according to claim 1, wherein: The composite loss is the sum of the product of the first loss and the first weighting coefficient and the product of the second loss and the second weighting coefficient; and The first weighting coefficient is greater than the second weighting coefficient.
6. The method according to claim 1, wherein: The second loss is the cross entropy loss.
7. The method according to claim 1, wherein: The number of the plurality of candidate classification pairs is at least the difference between the number of candidate classifications in the candidate classification set and 1.
8. An image classification method, characterized in that: include: The test images are classified using the image classification model trained according to the method of claim 1.
9. The method according to claim 8, wherein: The cosine similarity of the two text features in each of the plurality of candidate classification pairs determined by the text encoder of the trained image classification model is a negative value.
10. A computer-readable non-transitory storage medium storing a program, when the program is executed by a computer, the computer implements a training image classification model, the image classification model includes a front module and a rear module connected to the output end of the front module, the front module includes a text encoder and an image encoder of a CLIP model, the rear module is used to determine the classification result relative to a candidate classification set based on the output of the front module, and the candidate classification set is a union of a first classification set having a first semantic attribute value and a second classification set having a second semantic attribute value opposite to the first semantic attribute value, characterized in that Training an image classification model involves the following operations: Determining, by the text encoder, corresponding text features of each candidate classification in the candidate classification set; determining, by the image encoder, corresponding image features of the image samples; The rear module determines a classification probability vector of the image sample based on the corresponding text features and the corresponding image features; Determine the sum of cosine similarities of two text features in each of the plurality of candidate classification pairs as a first loss; determining a second loss based on the classification probability vector; as well as adjusting a network parameter of the text encoder based on a composite loss associated with the first loss and the second loss; One category in each of the plurality of candidate category pairs belongs to the first category set, and the other category in each of the plurality of candidate category pairs belongs to the second category set.
