Classification model training method and device, image classification method and device, equipment and medium
By encoding and decoding the sample image, calculating the loss value to determine its impact on the model structure layer, and adjusting the model parameters, the problem of inconsistent impact of the sample image is solved, and the accuracy and efficiency of model training are improved.
Patent Information
- Application Number
- CN202410624324.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-20
- Publication Date
- 2024-09-17
AI Technical Summary
In the prior art, different sample images have different effects on the internal structural layers of the model, which affects the quality of model training and makes it difficult to determine the degree of influence of the sample images on each structural layer.
By determining the sample image and its label, perform encoding and decoding, calculate the loss value of the encoding layer and decoding layer to reflect the impact of the sample image on each structural layer, and adjust the model parameters based on the loss value to improve the accuracy of model training.
It improves the accuracy and efficiency of model training and ensures high-quality classification model training.
Smart Images

Figure CN118658022A
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a classification model training, image classification method, device, equipment and medium. Background Art
[0002] When training a model, it is usually necessary to use a large number of sample images to train the model, such as using tens of thousands of sample images to train the classification model so that the classification model has the ability to classify images. Different sample images have different effects on different structural layers within the model. For example, a sample image can help improve the processing capacity of layer A within the model, while in the same training process, the sample image will reduce the processing capacity of layer B within the model. If the parameters of layer B are adjusted based on the processing results of the sample image, the training quality of the model will be affected. Therefore, how to determine the degree of influence of the current sample image on each structural layer, and then train the classification model according to the degree of influence on each structural layer to further improve the quality of model training has become an urgent problem to be solved. Summary of the invention
[0003] The embodiments of the present application provide a classification model training, image classification method, device, equipment and medium to solve the problem in the prior art that different sample images have different effects on the internal layer structure of the model, thereby affecting the quality of model training.
[0004] In a first aspect, the present application provides a method for training a classification model, the method comprising:
[0005] Determine a sample image and a label of the sample image;
[0006] Encoding the sample image to obtain predicted semantic features;
[0007] Decoding the predicted semantic features to obtain a predicted classification of the sample image;
[0008] Determine a loss value of an encoding layer of a classification model according to the predicted semantic features and the standard semantic features of the sample image, and determine a loss value of a decoding layer of the classification model according to the predicted classification and the label;
[0009] The classification model is trained according to the loss value of the encoding layer and / or the loss value of the decoding layer.
[0010] According to the embodiment of the present application, during the model training process, a sample image and a label of the sample image are determined, and the sample image is encoded to obtain a predicted semantic feature, and then the predicted semantic feature is decoded to obtain a predicted classification of the sample image, thereby determining the loss value of the encoding layer of the classification model based on the predicted semantic feature obtained by encoding and the standard semantic feature of the sample image, and determining the loss value of the decoding layer of the classification model based on the predicted classification and the label of the sample image obtained by decoding. Since the size of the loss value of different structural layers in the model reflects the degree of influence of the corresponding sample image on the training of the corresponding structural layer, in the embodiment of the present application, the classification model is trained based on the loss value of the encoding layer and / or the loss value of the decoding layer, thereby improving the accuracy of the model training and obtaining a high-quality classification model.
[0011] In a second aspect, the present application also provides an image classification method, the method comprising:
[0012] The image to be classified is input into a classification model to obtain a target classification of the image to be classified, and the classification model is trained according to the training method described above.
[0013] Because in the embodiment of the present application, when image classification is required, the image to be classified is obtained, and the trained classification model is used to classify the image to be classified, thereby improving the efficiency of image classification.
[0014] In a third aspect, the present application also provides a training device for a classification model, the device comprising:
[0015] A determination module, used to determine a sample image and a label of the sample image;
[0016] An encoding module, used for encoding the sample image to obtain predicted semantic features;
[0017] A decoding module, used for decoding the predicted semantic features to obtain the predicted classification of the sample image;
[0018] The determination module is further used to determine the loss value of the encoding layer of the classification model according to the predicted semantic features and the standard semantic features of the sample image, and to determine the loss value of the decoding layer of the classification model according to the predicted classification and the label;
[0019] An adjustment module is used to train the classification model according to the loss value of the encoding layer and / or the loss value of the decoding layer.
[0020] In a fourth aspect, the present application further provides an image classification device, the device comprising:
[0021] The classification module is used to input the image to be classified into the classification model to obtain the target classification of the image to be classified. The classification model is trained according to the training method described above.
[0022] In a fifth aspect, an embodiment of the present application provides an electronic device, which includes at least a processor and a memory, and the processor is used to implement the steps of the training method of the classification model described in any one of the above items, or the steps of the above image classification method when executing a computer program stored in the memory.
[0023] In a sixth aspect, an embodiment of the present application provides a computer storage medium storing a computer program executable by an electronic device. When the program runs on the electronic device, the electronic device executes the steps of the classification model training method described in any one of the above items, or the steps of the image classification method described above.
[0024] In the seventh aspect, an embodiment of the present application provides a computer program product, which includes: a computer program code, when the computer program code runs on the electronic device, enables the electronic device to execute the steps of the training method of the classification model described in any one of the above, or the steps of the above-mentioned image classification method. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solution of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0026] Figure 1 A schematic diagram of a training process of a classification model provided in an embodiment of the present application;
[0027] Figure 2 A schematic diagram of determining a predicted classification result provided in an embodiment of the present application;
[0028] Figure 3 A schematic diagram of a sample image and label determination process provided in an embodiment of the present application;
[0029] Figure 4 A schematic diagram of a training process of a classification model provided in an embodiment of the present application;
[0030] Figure 5 A schematic diagram of a training process of a classification model provided in an embodiment of the present application;
[0031] Figure 6 A schematic diagram of an image classification process provided in an embodiment of the present application;
[0032] Figure 7 A schematic diagram of the structure of a classification model training device provided in an embodiment of the present application;
[0033] Figure 8 A schematic diagram of the structure of an image classification device provided in an embodiment of the present application;
[0034] Fig. 9 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0035] In order to make the purpose and implementation method of the present application clearer, the exemplary implementation method of the present application will be clearly and completely described below in conjunction with the drawings in the exemplary embodiments of the present application. Obviously, the described exemplary embodiments are only part of the embodiments of the present application, rather than all the embodiments.
[0036] It should be noted that the brief description of terms in this application is only for the convenience of understanding the embodiments described below, and is not intended to limit the embodiments of this application. Unless otherwise specified, these terms should be understood according to their common and usual meanings.
[0037] The terms "first", "second", "third", etc. in the specification and claims of this application and the above drawings are used to distinguish similar or similar objects or entities, and do not necessarily mean to limit a specific order or sequence, unless otherwise noted. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances.
[0038] The terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover but not exclude inclusion, for example, a product or device comprising a list of components is not necessarily limited to all the components expressly listed but may include other components not expressly listed or inherent to such product or device.
[0039] The term "module" refers to any known or later developed hardware, software, firmware, artificial intelligence, fuzzy logic, or combination of hardware and / or software code that is capable of performing the functions associated with that element.
[0040] Finally, it should be noted that the embodiments of the present application are only used to illustrate the technical solution of the present application, rather than to limit it. Although the present application has been described in detail with reference to the embodiments, a person of ordinary skill in the art should understand that the technical solutions described in the embodiments can still be modified, or some or all of the technical features can be replaced by equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solution to deviate from the scope of the technical solution of the embodiments of the present application.
[0041] For the convenience of explanation, the above description has been made in conjunction with specific embodiments. However, the exemplary discussion is not intended to be exhaustive or limit the embodiments to the specific forms disclosed. According to the derivation in each embodiment, various modifications and variations can be obtained. The selection and description of each embodiment in this application is to better explain the principle and practical application, so that those skilled in the art can better use the embodiments and various different variations of the embodiments suitable for specific use considerations.
[0042] The sample images used in model training are generally collected over a long period of time. Generally, these sample images are collected by different people through different channels. Since each person has different collection standards, a variety of sample images will be collected. During the model training process, different sample images have different effects on different structural layers within the model. When the model processes the sample images, multiple structural layers within the model will process the sample images in turn to achieve the purpose of model training. There may be a situation where the current sample image has a greater beneficial effect on the training of a certain structural layer in the model, but has little beneficial effect on the training of other structural layers within the model, or even has a negative effect on the training of these other structural layers. Therefore, in order to determine the degree of influence of the current sample image on the model training, and thus train the classification model according to the determined degree of influence of the current sample image on each structural layer, the embodiments of the present application provide a classification model training, image classification method, device, equipment and medium. In the classification model training method, a sample image and a label of the sample image are determined; the sample image is encoded to obtain a predicted semantic feature; the predicted semantic feature is decoded to obtain a predicted classification of the sample image; the loss value of the encoding layer of the classification model is determined based on the predicted semantic feature and the standard semantic feature of the sample image, and the loss value of the decoding layer of the classification model is determined based on the predicted classification and the label of the sample image; the classification model is trained based on the loss value of the encoding layer and / or the loss value of the decoding layer.
[0043] The classification model training method provided in the embodiment of the present application can be applied to any scenario where classification model training is required, and the classification model trained by this method can be applied to products that need to be classified in these scenarios.
[0044] In order to better understand the training method of the classification model provided in the embodiment of the present application, the application environment applicable to the embodiment of the present application is described below. The training method of the classification model provided in the embodiment of the present application can be performed by an electronic device such as a terminal device or a server. The terminal device can be a vehicle-mounted device, a user equipment (UE), a personal digital assistant (PDA), a handheld device, a computing device, etc. The method can be implemented by a processor calling a computer-readable program instruction stored in a memory. The server can be an independent physical server, a server cluster consisting of multiple servers, or a cloud server capable of cloud computing.
[0045] In order to better understand the training method of the classification model provided in the embodiment of the present application, some key terms involved in the embodiment of the present application are explained below.
[0046] Non-standard data: also known as raw data, refers to data that has not been labeled, that is, unlabeled data.
[0047] Labeled data: needs to be labeled by human labelers, who need to have the ability to understand the task and labeling rules and label according to consistent standards. Labeled data can be used to train, verify and test models to improve the performance and generalization ability of the model. Usually the annotation content includes classification labels, bounding boxes, semantic segmentation masks, sequence labels, etc.
[0048] Model training is generally a process of mathematically fitting non-standard data or labeled data to construct a model that can perform autonomous recognition tasks. Model training programs are usually deployed in the cloud and are computationally intensive software programs. Model training is usually divided into "supervised training", "unsupervised training" and "semi-supervised training". Based on these three training modes, "zero-sample learning" and "few-sample learning" can be evolved. High-quality expert models are usually supervised training, such as optical character recognition (OCR) and automatic speech recognition (ASR); high-quality models with strong generalization capabilities are usually unsupervised training, such as BERT (Bidirectional Encoder Representation from Transformers), Chat Generative Pre-trained Transformer (ChatGPT) and other large text models; currently, visual classification models usually use a hybrid training method, that is, first use most of the non-standard data for unsupervised training, which can be understood as a pre-training process, and then use a small part of the data for supervised training, which can be understood as fine-tuning the pre-trained model. It should be noted that the training method of the classification model provided in the embodiment of the present application is also applicable to the fine-tuning training process of the classification model. The training method of the above classification model is described below in conjunction with various embodiments.
[0049] In order to train a classification model with higher accuracy, in an embodiment of the present application, the initial classification model can be trained, and the classification model can be obtained when the training meets the preset convergence conditions. Figure 1 A schematic diagram of a training process of a classification model provided in an embodiment of the present application, the process includes the following steps:
[0050] S101: Determine a sample image and a label of the sample image.
[0051] A classification model training method provided in an embodiment of the present application is applied to an electronic device, which may be a server, a PC, etc.
[0052] When training the classification model, the sample image and the label of the sample image can be determined. In an embodiment of the present application, the sample image and the label of the sample image can be obtained from the training set, or can be received, such as input by the user of the electronic device, or sent to the electronic device by other electronic devices. Among them, the label is used to identify the standard category to which the corresponding sample image belongs. For example, the label corresponding to sample image 1 is "dog", which means that sample image 1 is an image about a dog; the label corresponding to sample image 2 is "cat", which means that sample image 2 is an image about a cat. If the classification model to be trained is a discriminant, for example, the classification model is trained to have the ability to identify whether an image contains a dog, then the label corresponding to each sample image is "yes" or "no", such as, the label corresponding to sample image 3 is "yes", which means that sample image 3 contains a dog; the label corresponding to sample image 4 is "no", which means that sample image 4 does not contain a dog.
[0053] S102: Encode the sample image to obtain predicted semantic features.
[0054] In order to train a classification model, in an embodiment of the present application, a determined sample image and a label of the sample image can be input into the classification model, and the classification model processes the sample image to determine the predicted classification of the sample image. When the classification model processes the sample image, the sample image can be encoded to obtain the predicted semantic features of the sample image. Specifically, the content in the sample image can be extracted by the encoding layer of the classification model, and the extracted content is called the predicted semantic feature, which can be represented in the form of a feature vector or a feature matrix. Optionally, the encoding layer can be a large model's own encoding network. How to encode an image is a prior art and will not be described in detail in the embodiments of the present application.
[0055] S103: Decode the predicted semantic features to obtain the predicted classification of the sample image.
[0056] After the predicted semantic features are obtained through encoding, the preset semantic features can be decoded to obtain the predicted classification of the sample image. Specifically, the predicted semantic features can be input into the decoding layer of the classification model, and the decoding layer will process the predicted semantic features to obtain the predicted classification of the sample image.
[0057] Figure 2 A schematic diagram of determining a predicted classification result provided in an embodiment of the present application is shown in FIG. Figure 2As shown, the sample image is input to the encoding layer, the encoding layer processes the sample image to obtain the predicted semantic feature e, and the predicted semantic feature e is input to the decoding layer, and the decoding layer can output the predicted classification of the sample image. In an embodiment of the present application, the classification model may include multiple encoding layers and multiple decoding layers.
[0058] S104: Determine a loss value of a coding layer of a classification model according to the predicted semantic features and the standard semantic features of the sample image, and determine a loss value of a decoding layer of the classification model according to the predicted classification and the label.
[0059] In an embodiment of the present application, the encoding layer is used to predict the semantic features in the sample image, and the decoding layer is used to further perform classification prediction based on the semantic features. Among them, the encoding layer can be trained to predict the semantic features through any sample image, and has strong versatility. The decoding layer needs to be trained in classification capabilities, such as classifying and determining whether a certain image includes a dog, or determining whether a certain image includes a bird. In other words, the functions of the encoding layer and the decoding layer are different. In a possible implementation, it is also possible to train the encoding layer and the decoding layer separately. Therefore, in an embodiment of the present application, the loss value of the encoding layer and the loss value of the decoding layer can be determined separately.
[0060] When determining the loss value of the coding layer, it can be determined based on the predicted semantic features and the standard semantic features of the sample image. The process of training the coding layer can be understood as an unsupervised training process. After obtaining the sample image, the classification model will encode the sample image to obtain the standard semantic features, and then randomly mask the standard semantic features. The iterator sends the masked standard semantic features to the coding layer with a fixed batch size. The coding layer processes the masked standard semantic features to obtain the predicted semantic features. Therefore, the loss value of the coding layer is determined based on the deviation between the predicted semantic features and the standard semantic features. It should be noted that how to determine the predicted semantic features and standard semantic features of the sample image, and how to determine the first loss value are prior art and will not be repeated here.
[0061] When determining the loss value of the decoding layer, the loss value of the decoding layer can be determined according to the deviation between the category to which the target included in the label of the sample image belongs and the predicted classification value.
[0062] S105: Training the classification model according to the loss value of the encoding layer and / or the loss value of the decoding layer.
[0063] Since the size of the loss value can reflect the effect of the corresponding sample image on improving the model capability, that is, the smaller the loss value, the smaller the effect of the corresponding sample image on improving the model capability. Therefore, in the embodiment of the present application, after determining the loss value of the encoding layer and the loss value of the decoding layer, the classification model can be trained according to the loss value of the encoding layer and / or the loss value of the decoding layer.
[0064] In the embodiment of the present application, a parameter adjustment scheme for training the classification model can be determined according to the size relationship between the loss value of the encoding layer and the loss value of the decoding layer. The parameter adjustment scheme can be to adjust the parameters in the encoding layer, or to adjust the parameters in the decoding layer, or to adjust the parameters in both the encoding layer and the decoding layer.
[0065] Exemplarily, when the loss value of the coding layer is greater than the loss value of the decoding layer, it means that the corresponding sample image has a greater positive impact on the coding layer, that is, the corresponding sample image is more helpful in improving the coding ability of the coding layer. In the embodiment of the present application, this round can only adjust the parameters of the coding layer of the classification model. In the embodiment of the present application, the parameters in the coding layer can be adjusted only based on the loss value of the coding layer, or a final loss value can be determined based on the loss value of the coding layer and the loss value of the decoding layer, and then the parameters in the coding layer can be adjusted based on the final loss value. In the embodiment of the present application, the sum or quotient or average of the first loss value and the second loss value can be determined as the final loss value.
[0066] When the loss value of the encoding layer is smaller than the loss value of the decoding layer, it indicates that the corresponding sample image has a greater positive impact on the decoding layer. That is to say, the corresponding sample image is more helpful in improving the prediction ability of the decoding layer. In the embodiment of the present application, the parameters in the decoding layer can be adjusted only based on the loss value of the decoding layer, or a final loss value can be determined based on the loss value of the encoding layer and the loss value of the decoding layer, and then the parameters in the decoding layer can be adjusted based on the final loss value.
[0067] When the loss value of the coding layer is equal to the loss value of the decoding layer, it means that the corresponding sample image has the same influence on the coding layer and the decoding layer, that is, the corresponding sample image is equally helpful in improving the coding ability of the coding layer and the prediction ability of the decoding layer. In an embodiment of the present application, the parameters in the coding layer can be adjusted based on the loss value of the coding layer, and the parameters in the decoding layer can be adjusted based on the loss value of the decoding layer. A final loss value can also be determined based on the loss value of the coding layer and the loss value of the decoding layer, and then the parameters in the coding layer and the decoding layer can be adjusted based on the final loss value.
[0068] According to the embodiment of the present application, during the model training process, a sample image and a label of the sample image are determined, and the sample image is encoded to obtain a predicted semantic feature, and then the predicted semantic feature is decoded to obtain a predicted classification of the sample image, thereby determining the loss value of the encoding layer of the classification model based on the predicted semantic feature obtained by encoding and the standard semantic feature of the sample image, and determining the loss value of the decoding layer of the classification model based on the predicted classification and the label of the sample image obtained by decoding. Since the size of the loss value of different structural layers in the model reflects the degree of influence of the corresponding sample image on the training of the corresponding structural layer, in the embodiment of the present application, the classification model is trained based on the loss value of the encoding layer and / or the loss value of the decoding layer, thereby improving the accuracy of the model training and obtaining a high-quality classification model.
[0069] In order to further improve the accuracy of model training, based on the above embodiment, in the embodiment of the present application, before training the classification model according to the loss value of the encoding layer and / or the loss value of the decoding layer, the method further includes:
[0070] The training object of the current round is determined according to the number of training rounds, and the training object includes the encoding layer and / or decoding layer of the classification model.
[0071] Since the decoding layer predicts and classifies based on the predicted semantic features of the encoding layer, the accuracy of the predicted semantic features encoded by the encoding layer will directly affect the accuracy of the predicted classification determined by the decoding layer. Therefore, in order to further improve the accuracy of model training, in an embodiment of the present application, before training the classification model based on the loss value of the encoding layer and / or the loss value of the decoding layer, the training object of the current round can also be determined based on the number of training rounds. The training object can be the encoding layer, the decoding layer, or the encoding layer and the decoding layer. When training the classification model later, the parameters in the determined training object can be adjusted. In an embodiment of the present application, after each sample image is determined, the number of training rounds can be updated, for example, the number of training rounds can be increased by 1.
[0072] Specifically, the correspondence between the number of training rounds and the training object is preconfigured, for example, the training object corresponding to the training rounds 1-50 is the encoding layer, the training object corresponding to the training rounds 51-100 is the decoding layer, the training object corresponding to the training rounds 101-150 is the encoding layer and the decoding layer, the training object corresponding to the training rounds 151-200 is the encoding layer, the training object corresponding to the training rounds 201-250 is the decoding layer, the training object corresponding to the training rounds 251-300 is the encoding layer and the decoding layer, and so on. Assuming that the number of training rounds of the current round is 58, it can be determined that the training object is the decoding layer, and the parameters of the decoding layer are subsequently adjusted according to the loss value of the encoding layer and / or the loss value of the decoding layer.
[0073] In order to further improve the accuracy of model training, based on the above embodiments, in the embodiment of the present application, the step of determining the training object of the current round according to the number of training rounds includes:
[0074] If the number of training rounds is within a first numerical range, determining that the training object is the coding layer;
[0075] If the number of training rounds is within the second numerical range, determining that the training object is the decoding layer;
[0076] If the number of training rounds is in a third numerical interval, the training objects are determined to be the encoding layer and the decoding layer; wherein the minimum value of the third numerical interval is greater than the maximum value of the second numerical interval, and the minimum value of the second numerical interval is greater than the maximum value of the first numerical interval.
[0077] Since the decoding layer performs classification prediction based on the predicted semantic features of the coding layer, if the coding layer has a weak ability to determine the predicted semantic features, the accuracy of the predicted semantic features output by the coding layer will be low, and then the accuracy of the classification prediction performed by the decoding layer based on the predicted semantic features with low accuracy will be greatly reduced. Therefore, in an embodiment of the present application, the coding layer can be trained first, and after the coding layer has a strong ability to predict semantic features, the classification prediction ability of the decoding layer can be trained. In an embodiment of the present application, a first numerical interval and a second numerical interval are pre-configured, wherein the minimum value of the two numerical intervals is greater than the maximum value of the first numerical interval. Exemplarily, the first numerical interval is [1, 500], and the second numerical interval is [501, 1000]. It should be noted that a technician in this field can configure the first numerical interval and the second numerical interval as needed, and the embodiment of the present application does not limit this.
[0078] In an embodiment of the present application, if the number of training rounds of the current round is in the first numerical interval, it can be determined that the training object is the coding layer. That is, the current round trains the coding layer but does not train the decoding layer. When the number of training rounds of the current round is in the second numerical interval, it can be determined that the training object is the decoding layer. That is, the current round does not train the coding layer but only trains the decoding layer. That is, as in the above example, during the 1st to 500th rounds of training, the coding layer is trained but the decoding layer is not trained, and during the 501st to 1000th rounds of training, the coding layer is not trained but only the decoding layer is trained.
[0079] When the number of training rounds is in the first numerical interval or the second numerical interval, the coding layer or the decoding layer is trained separately. In the model training process, it is very likely that the coding layer is trained separately to have a better ability to predict semantic features, and the decoding layer is trained separately to have a better ability to predict classification, but in actual use, the effect of the combination of the coding layer and the decoding layer is not good. Therefore, in order to prevent overfitting of the model, in an embodiment of the present application, a third numerical interval is also configured, wherein the minimum value in the third numerical interval is greater than the maximum value in the second numerical interval. For example, the first numerical interval is [1,500], the second numerical interval is [501,1000], and the third numerical interval is [1001,1200]. If the number of training rounds of the current round is in the third numerical interval, it can be determined that the training object is the coding layer and the decoding layer. That is, the current round trains the coding layer and the decoding layer together.
[0080] In order to further improve the accuracy of model training, on the basis of the above embodiments, in an embodiment of the present application, if the training object is the encoding layer, the classification model is trained according to the loss value of the encoding layer and / or the loss value of the decoding layer, including:
[0081] If the loss value of the encoding layer is greater than or equal to the loss value of the decoding layer, adjusting the parameters of the encoding layer;
[0082] If the loss value of the encoding layer is smaller than the loss value of the decoding layer, the parameters of the encoding layer are not adjusted.
[0083] Since the quality of each sample image is uneven, in order to further improve the accuracy of model training, in an embodiment of the present application, an evaluation mechanism is introduced to evaluate whether the current round of sample images is beneficial to improving the capabilities of the training object.
[0084] In an embodiment of the present application, if the training object is determined to be the coding layer, when training the classification model according to the loss value of the coding layer and / or the loss value of the decoding layer, it can be determined whether to train the coding layer according to the size relationship between the loss value of the coding layer and the loss value of the decoding layer. If the loss value of the coding layer is larger, it means that the corresponding sample image has a greater beneficial effect on the coding layer, which is more conducive to improving the coding ability of the coding layer. And the smaller the loss value of the coding layer, it means that the corresponding sample image has a smaller beneficial effect on the coding layer.
[0085] Therefore, if the loss value of the coding layer is greater than or equal to the loss value of the decoding layer, it means that the corresponding sample image is more conducive to improving the coding ability of the coding layer, but is relatively weak in improving the prediction ability of the decoding layer, and may even reduce the prediction ability of the decoding layer. Therefore, when the training object is the coding layer, if the loss value of the coding layer is greater than or equal to the loss value of the decoding layer, the coding layer is trained, that is, the parameters of the coding layer are adjusted.
[0086] Specifically, when adjusting the parameters of the coding layer, the parameters of the coding layer can be adjusted according to the loss value of the coding layer; or the final loss value can be determined based on the loss value of the coding layer and the loss value of the decoding layer, and then the parameters of the coding layer can be adjusted according to the final loss value. In an embodiment of the present application, the difference, sum, or quotient of the loss value of the coding layer and the loss value of the decoding layer can be determined as the final loss value.
[0087] If the loss value of the encoding layer is smaller than the loss value of the decoding layer, it means that the corresponding sample image has a greater beneficial effect on the decoding layer and is more beneficial to improving the prediction ability of the decoding layer, while the beneficial effect on the encoder is relatively weak and may even reduce the encoding ability of the encoding layer. Therefore, the encoding layer may not be trained in the current round, that is, the parameters of the encoding layer are not adjusted in the current round.
[0088] In order to further improve the accuracy of model training, on the basis of the above embodiments, in an embodiment of the present application, if the training object is the decoding layer, the classification model is trained according to the loss value of the encoding layer and / or the loss value of the decoding layer, including:
[0089] If the loss value of the decoding layer is greater than or equal to the loss value of the encoding layer, adjusting the parameters of the decoding layer;
[0090] If the loss value of the decoding layer is smaller than the loss value of the encoding layer, the parameters of the decoding layer are not adjusted.
[0091] In an embodiment of the present application, if the training object is determined to be a decoding layer, when training the classification model according to the loss value of the encoding layer and / or the loss value of the decoding layer, it can be determined whether to train the decoding layer according to the size relationship between the loss value of the encoding layer and the loss value of the decoding layer. If the loss value of the decoding layer is larger, it means that the corresponding sample image has a greater beneficial effect on the decoding layer, which is more conducive to improving the prediction ability of the decoding layer. The smaller the loss value of the decoding layer, the smaller the beneficial effect of the corresponding sample image on the decoding layer.
[0092] Therefore, if the loss value of the decoding layer is greater than or equal to the loss value of the encoding layer, it means that the corresponding sample image is more conducive to improving the prediction ability of the decoding layer, but is relatively weak in improving the encoding ability of the encoding layer, and may even reduce the encoding ability of the encoding layer. Therefore, when the training object is the decoding layer, if the loss value of the decoding layer is greater than or equal to the loss value of the encoding layer, the decoding layer is trained, that is, the parameters of the decoding layer are adjusted.
[0093] Specifically, when adjusting the parameters of the decoding layer, the parameters of the decoding layer can be adjusted according to the loss value of the decoding layer; or the final loss value can be determined based on the loss value of the encoding layer and the loss value of the decoding layer, and then the parameters of the decoding layer can be adjusted according to the final loss value. In an embodiment of the present application, the difference, sum, or quotient of the loss value of the encoding layer and the loss value of the decoding layer can be determined as the final loss value.
[0094] If the loss value of the decoding layer is smaller than the loss value of the encoding layer, it means that the corresponding sample image has a greater beneficial effect on the encoding layer, and is more beneficial to improving the encoding ability of the encoding layer, while the beneficial effect on the decoding layer is relatively weak, and may even reduce the prediction ability of the decoding layer. Therefore, the decoding layer may not be trained in the current round, that is, the parameters of the decoding layer are not adjusted in the current round.
[0095] In order to further improve the accuracy of model training, based on the above embodiments, in the embodiments of the present application,
[0096] If the training object is the encoding layer and the decoding layer, training the classification model according to the loss value of the encoding layer and / or the loss value of the decoding layer includes:
[0097] Determining a target loss value according to the loss value of the encoding layer and the loss value of the decoding layer;
[0098] According to the target loss value, parameters of the encoding layer and the decoding layer are adjusted.
[0099] In the embodiment of the present application, if the training object is determined to be the encoding layer and the decoding layer, when the classification model is trained according to the loss value of the encoding layer and / or the loss value of the decoding layer, the target loss value can be determined according to the loss value of the encoding layer and the loss value of the decoding layer. Thus, the parameters in the encoding layer and the decoding layer are adjusted according to the target loss value.
[0100] It should be noted that when determining the target loss value, technicians in this field can also set other calculation methods as needed. For example, determine the target loss value based on the loss value of the encoding layer, the loss value of the decoding layer and preset weights. The embodiments of the present application do not limit this.
[0101] It should be noted that if the parameters in the encoding layer or decoding layer are not adjusted in multiple rounds, it means that the quality of the collected sample images is not high and has little significance for model training, then the training of the classification model can be terminated.
[0102] Since the loss values of different structural layers have different distribution characteristics, that is, the loss values of the coding layer and the loss values of the decoding layer may be distributed in different numerical ranges, therefore, in the embodiment of the present application, the loss values of the coding layer and the loss values of the decoding layer may also be normalized, that is, the loss values of the coding layer and the loss values of the decoding layer are mapped to the same numerical range, for example, mapped to [0,1]. Then, the target loss value is determined based on the normalized loss value.
[0103] At present, model training is increasingly widely used. There are usually two training paradigms, one of which can be applied to the training of most models. Specifically, it includes the following steps:
[0104] 1. Determine the problems to be solved based on the actual business situation;
[0105] 2. According to the determined problems, set up data collection plan and collect original data;
[0106] 3. According to the determined problem, set the data annotation plan and annotate the collected raw data;
[0107] 4. Select or design a new model structure based on actual business conditions;
[0108] 5. Select the appropriate loss function through model tuning schemes such as hyperparameters, and select the appropriate effect evaluation algorithm;
[0109] 6. Control electronic devices to train the model based on the labeled data.
[0110] In general, this training paradigm is that humans collect raw data and annotate the raw data, so that the electronic device trains the model whose structure is determined by humans based on the annotated data.
[0111] Another training paradigm can be applied to pre-trained models. The training process of pre-trained models usually includes two steps: non-standard data training and labeled data training. Non-standard data training is also called pre-training, and labeled data training is also called fine-tuning training. The pre-training process usually requires ultra-large-scale data to learn the inherent connections of non-standard data through training; the fine-tuning training process usually only requires a small amount of data to learn the target task through training. This training paradigm usually includes the following steps:
[0112] 1. Determine the problems to be solved based on the actual business situation;
[0113] 2. According to the determined problems, set up data collection plan and collect original data;
[0114] 3. According to the determined problem, set the data annotation plan and annotate the collected raw data;
[0115] 4. Select or design a new model structure based on actual business conditions;
[0116] 5. Select the appropriate loss function through model tuning schemes such as hyperparameters, and select the appropriate effect evaluation algorithm;
[0117] 6. The control electronic equipment pre-trains the model based on non-standard data, and then fine-tunes the pre-trained model based on the labeled data.
[0118] In general, this training paradigm also involves humans collecting raw data and labeling the raw data, and electronic devices pre-train and fine-tune the model with a determined model structure based on non-standard data and labeled data respectively.
[0119] Regardless of which of the above training paradigms is used, the training of the model is overly dependent on the collection of sample data. Sample data directly determines the effect of model training. If too little sample data is collected, the model will be affected by incomplete learning knowledge. Therefore, model training generally requires sample data of tens of thousands or hundreds of millions. However, manual labeling is required for such large-scale sample data, which will take a lot of time. According to statistics, the time spent on collecting and organizing sample data generally accounts for more than 80% of the overall model training time, which seriously affects the efficiency of model training. Therefore, in order to improve the efficiency of model training, on the basis of the above embodiments, in the embodiment of the present application, the process of determining the sample image includes:
[0120] Acquire an annotation text, where the annotation text is a text describing an element included in the sample image to be generated;
[0121] Performing data enhancement on the annotated text to obtain enhanced text;
[0122] Inputting the enhanced text into a first model for prediction to obtain a predicted image;
[0123] The predicted image is used as a sample image.
[0124] In order to train the classification model, it is usually necessary to collect a large number of sample images, and then train based on these sample images. In an embodiment of the present application, in order to improve the efficiency of model training, an annotation text can be obtained, and then the corresponding sample image is generated based on the obtained annotation text. Among them, the annotation text can be a text that describes the content of the sample image to be generated, and the annotation text is used to subsequently remind the sample image generated by the first model which elements must be included. The annotation text is written by relevant personnel, and the annotation text can be pre-stored in the electronic device. When the classification model is trained, each annotation text saved can be obtained; the annotation text can also be sent by the user of the electronic device, and the annotation text is received when the classification model is trained, and the sample image is generated based on the annotation text. Exemplarily, the annotation text can be "puppy", then the obtained sample image should include a puppy; the annotation text can also be "a running puppy", then the obtained sample image should include a running puppy. It should be noted that the embodiment of the present application does not limit the content of the annotation text and the method of obtaining the annotation text, and those skilled in the art can configure it as needed.
[0125] If each annotated text is manually written, it will also take a lot of time. Therefore, in order to further improve the efficiency of model training, in the embodiment of the present application, after obtaining the annotated text, the obtained annotated text can be data enhanced to obtain enhanced text. Among them, the enhanced text can be understood as the text obtained after the annotated text is expanded.
[0126] Specifically, assuming that the acquired annotation text is "puppy", the enhanced text may include "a running puppy", "a puppy at the beach", "a puppy running at the beach", etc.
[0127] In a possible implementation, when data enhancement is performed on the annotated text, it can be expanded based on a large language model, for example, LLaMA (Large Language Model Meta AI), a text can be input into LLaMA, and LLaMA can output the enhanced text of the received annotated text based on its own powerful language analysis capabilities. For example, input: expand "puppy", and do not allow duplication with texts such as "beautiful puppy" and "running puppy", then LLaMA can expand "puppy" and output "jumping puppy", and the "jumping puppy" is the enhanced text.
[0128] Through the training method of the embodiment of the present application, the scale of sample images can be effectively expanded. If the acquired annotation text is just a "puppy", based on the data enhancement of the annotation text, a large number of sample images containing puppies in different styles can also be automatically generated.
[0129] After obtaining the enhanced text, the enhanced text can be input into the first model, and the first model performs prediction based on the enhanced text to obtain a predicted image. In other words, the predicted image is generated based on the enhanced text using the first model, thereby avoiding the problem of manual collection and consuming too much time. After obtaining the predicted avatar, the obtained predicted image can be used as a sample image.
[0130] In an embodiment of the present application, the first model can be any model with image generation capabilities, such as ChatGPT, Stable Diffusion (SD). After receiving the input enhanced text, the first model can generate a predicted image based on the enhanced text, and the predicted image is a sample image. The first model can generate only one sample image or multiple sample images at the same time during each image generation process, and the embodiment of the present application does not limit this. In other words, the predicted image obtained each time can be one or more.
[0131] It should be noted that technicians in this field can collect open source models in advance as needed, and the collected open source models can be used as the first model. When collecting open source models, the main information can come from cutting-edge papers in the literature library (arxiv), star projects on GitHub, a hosting platform for open source and private software projects, open source organizations such as huggingface, Chinese Magic Build Community (Modelscope), Paddle Paddle, and well-known websites Papers with Code. It can also be extended to commercial paid closed source model service providers, such as Alibaba Cloud and Tencent Cloud. The direct products collected in the above manner can be used as open source code assets or closed source call documents, and a unified application programming interface (Application Programming Interface, API) is formed through unified engineering packaging.
[0132] In order to further improve the efficiency of model training, based on the above embodiments, in the embodiment of the present application, the process of determining the sample image includes:
[0133] Acquire an annotation text, where the annotation text is a text describing an element included in the sample image to be generated;
[0134] Performing data enhancement on the annotated text to obtain enhanced text;
[0135] Inputting the enhanced text into a first model for prediction to obtain a predicted image;
[0136] Inputting the predicted image into a second model to obtain an enhanced image;
[0137] The enhanced image is used as a sample image.
[0138] In an embodiment of the present application, when determining a sample image, an annotation text may be obtained, which is a text describing the elements included in the sample image to be generated. After obtaining the annotation text, data enhancement is performed on the annotation text to obtain enhanced text, and the enhanced text is input into the first model for prediction to obtain a predicted image. The process of obtaining the predicted image has been described in detail in the above embodiment, and the process of obtaining the predicted image will not be repeated in the embodiment of the present application.
[0139] In order to enhance the robustness of the trained classification model, after obtaining the predicted image, the predicted image can be input into the second model to obtain an enhanced image output by the second model. The enhanced image is generated by the second model based on the deformation of the predicted image. In other words, using the "randomization" capability of the second model, a predicted image generated by the first model is randomized into another similar but different sample image. Among them, the second model can be any model with image enhancement capabilities. After obtaining the enhanced image, the enhanced image can be used as a sample image.
[0140] Specifically, assuming that the first model generates a predicted image 1 including a puppy on the roadside on a sunny day, the predicted image 1 can be input into the second model, and the second model will deform the sample image 1. The deformed sample image 1' can include a puppy on the roadside on a snowy day, or the deformed sample image 1", and the sample image 1" can include a puppy in the garden on a rainy day.
[0141] The efficiency of manual labeling is not only low, but also has a high error rate. If the model is trained based on wrong labels, the accuracy of the trained model cannot be guaranteed. Therefore, in order to improve the training efficiency of the model and ensure the accuracy of the trained model, based on the above embodiments, in the embodiment of the present application, the process of determining the label of the sample image includes:
[0142] Perform image classification processing on the sample image to determine a label of the sample image.
[0143] In order to further improve the efficiency of model training, in an embodiment of the present application, the sample image can be subjected to image classification processing based on image recognition technology to determine the label corresponding to the sample image. When determining the label, a publicly available expert model can be used for determination. Exemplarily, an expert model yolo-dog model can be used for identification, the input of which is an image in a common format such as png and jpg, and the output result is a Boolean value, that is, it contains a dog or does not contain a dog. Through the annotation method of an embodiment of the present application, the knowledge of the expert model can be taught to the classification model in the subsequent model training process, that is, the classification model obtained by training has the ability of an expert model.
[0144] The following describes the process of determining sample images and labels in conjunction with a specific embodiment. Figure 3 A schematic diagram of a sample image and label determination process provided in an embodiment of the present application is shown in FIG. Figure 3 As shown, obtain the pre-saved annotation text, input the annotation text into the open source large model, that is, the first model described in the above embodiment, and obtain N sample images. The currently obtained sample images are non-standard data. In order to determine the label corresponding to each sample image, each sample image can be input into the open source expert model respectively, and the open source expert model performs image classification processing on the received sample image to determine the classification of the target contained in the sample image. The classification is the label corresponding to the sample image. Subsequently, the model training can be performed based on the obtained sample images and the corresponding labels to obtain a classification model.
[0145] The training process of the classification model is described below with reference to a specific embodiment. Figure 4 A schematic diagram of a training process of a classification model provided in an embodiment of the present application, such as Figure 4 As shown, a technician in this field inputs the annotation text (prompt) into an electronic device, and the electronic device inputs the annotation text into an open source large model, which is the first model in the above embodiment, obtains N sample images and outputs them. The N sample images currently obtained are non-standard data.
[0146] After obtaining N sample images, the N sample images are input into the open source expert model to obtain the label corresponding to each sample image, and each sample image and the corresponding label are output.
[0147] Each sample image and the corresponding label are input into the own large model for fine-tuning training. The own large model to be fine-tuned is the classification model described in the above embodiment. According to the standard semantic features corresponding to the sample image and the predicted semantic features output by the encoding layer of the initial classification model, the loss value of the encoding layer of the classification model is determined. According to the predicted classification results and the corresponding labels output by the decoding layer of the initial classification model, the loss value of the decoding layer is determined. Then, the classification model is trained based on the loss value of the encoding layer and the loss value of the decoding layer.
[0148] In one possible implementation, the sample images output by the first model, i.e., non-standard data, can be used to train the encoding layer in the initial classification model. That is, the encoding layer can be trained unsupervised using non-standard data, and fine-tuning training can be performed after the encoding layer has certain semantic feature capabilities.
[0149] The training process of the classification model is described below in conjunction with another specific embodiment. Figure 5 A schematic diagram of a training process of a classification model provided in an embodiment of the present application, such as Figure 5 As shown, N sample images corresponding to the annotated text are generated based on the open source large model, and the sample images are used as non-standard data. Image classification processing is performed on the N sample images based on the open source expert model to determine the label corresponding to each sample image, that is, to determine the annotated data. Subsequently, the own large model network can be trained based on the sample images and the corresponding labels. The own large model network is the classification model in the above embodiment. Of course, the generated sample images can also be used as training sets or test sets.
[0150] In the embodiment of the present application, each batch of sample images can be used as a prefix of the input. Usually, the prefix length is half of the original coding length of the own large model network input. If the original coding length is 128 bits, the prefix length is 64 bits. The prefix length can also be directly fixed to 64 bits, and the minimum is not less than 32 bits. In other words, the original coding length is prefixed and suffixed respectively, where the prefix is used to describe the coding of the current learning content, and the suffix is used to describe the coding of the learned content, for example, the coding of the content learned in the last batch. The coding with the determined prefix is input into the iterator of the own large model network, and the iterator is sent to the coding layer with a fixed-scale Batch Size. For example, the Batch Size is 2GB. If the data scale is large enough, a larger Batch Size, such as 24GB, can be used. The coding layer processes the received code to obtain the predicted semantic feature e. In the embodiment of the present application, the coding layer is an architecture in the prior art, and the embodiment of the present application has not made any improvements. After obtaining the predicted semantic feature e, the loss value of the encoding layer can be determined. The training evaluator can adjust the parameters of the encoding layer according to the loss value of the encoding layer according to the preset training strategy, and stop the iterative training when it is determined that overfitting may exist.
[0151] After obtaining the predicted semantic feature e, the predicted semantic feature e can be input into Figure 5 The evaluator in the example includes a decoding layer, which can determine the predicted classification result of the corresponding sample image. After obtaining the predicted classification result, the label of the corresponding sample image can be found in the training set, so as to determine the loss value of the decoding layer based on the category described in the label and the predicted classification result.
[0152] Although the first model has strong generation capabilities and can generate related but different sample images based on the same annotated text, the sample images it generates often include sample images that cannot be used to train other models. In other words, there will be a problem of data poisoning in the sample images generated by the first model, that is, other models refer to these sample images during the training process, which will cause the performance of the other models to decline. This is because the native training data of the first model is limited, its ability to generate data has an upper limit, and there are certain illusions and generation defects. In an embodiment of the present application, the parameters in the encoding layer can be adjusted based on the loss value of the encoding layer. The evaluator then determines whether to adjust the parameters of the decoding layer based on the relationship between the loss value of the encoding layer and the loss value of the decoding layer. When it is determined that the parameters of the decoding layer are not adjusted this time, it can be determined that the corresponding sample image may be "poisoned" data, and the corresponding sample image can be deleted.
[0153] The embodiments of the present application utilize the generation and cross-modal capabilities of the open source large model algorithm engine, which can create a large amount of non-standard data "out of nothing", and utilize the classification and recognition capabilities of the open source expert model algorithm engine to convert non-standard data into labeled data with high precision, making full use of the learning ability of the own large model algorithm engine, and can expand the processing capabilities of expert tasks through the method of fine-tuning the coding layer. From the perspective of the model trainer, this application only needs to provide the corresponding annotation text after defining the problem, and a large model with corresponding problem-solving capabilities can be obtained, which greatly reduces the dependence on data during the model training process and significantly shortens the data collection and collation time for model training.
[0154] Based on the same technical concept, on the basis of the above embodiments, the present application also provides an image classification method. Figure 6 A schematic diagram of an image classification process provided in an embodiment of the present application, the process includes the following steps:
[0155] An image classification provided in the embodiment of the present application is applied to an electronic device, which may be a server, a PC, a smart terminal, etc. The electronic device in the embodiment of the present application may be the same as or different from the electronic device to which the classification model training method is applied.
[0156] When performing image classification, an image to be classified can be obtained, and the image to be classified can be any image that can be recognized by the trained classification model. The classification image can be input by the user of the electronic device or sent by other electronic devices. The embodiment of the present application does not limit the method of obtaining the image to be classified.
[0157] S601: Inputting an image to be classified into a classification model to obtain a target classification of the image to be classified, wherein the classification model is trained according to the classification model training method described in the above embodiments.
[0158] After the image to be classified is acquired, the image to be classified can be input into the classification model to obtain the target classification. The classification model is obtained according to the classification model training method described in the above embodiments.
[0159] Because in the embodiment of the present application, when image classification is required, the image to be classified is obtained, and the trained classification model is used to classify the image to be classified, thereby improving the efficiency of image classification.
[0160] Based on the same technical concept, on the basis of the above embodiments, the present application provides a training device for a classification model, wherein the initial classification model includes a coding layer and a decoding layer. Figure 7 A schematic diagram of a training device for a classification model provided in an embodiment of the present application, the device comprising:
[0161] A determination module 701 is used to determine a sample image and a label of the sample image;
[0162] An encoding module 702, used for encoding the sample image to obtain predicted semantic features;
[0163] A decoding module 703, used for decoding the predicted semantic features to obtain the predicted classification of the sample image;
[0164] The determination module 701 is further used to determine the loss value of the encoding layer of the classification model according to the predicted semantic features and the standard semantic features of the sample image, and to determine the loss value of the decoding layer of the classification model according to the predicted classification and the label;
[0165] The adjustment module 704 is used to train the classification model according to the loss value of the encoding layer and / or the loss value of the decoding layer.
[0166] In a possible implementation, the determination module 701 is further configured to determine a training object for a current round according to the number of training rounds, wherein the training object includes a coding layer and / or a decoding layer of the classification model.
[0167] In a possible implementation, the determination module 701 is further used to determine that the training object is the encoding layer if the number of training rounds is in a first numerical interval; determine that the training object is the decoding layer if the number of training rounds is in a second numerical interval; and determine that the training object is the encoding layer and the decoding layer if the number of training rounds is in a third numerical interval; wherein the minimum value of the third numerical interval is greater than the maximum value of the second numerical interval, and the minimum value of the second numerical interval is greater than the maximum value of the first numerical interval.
[0168] In a possible implementation, if the training object is the encoding layer, the adjustment module 704 is specifically used to adjust the parameters of the encoding layer if the loss value of the encoding layer is greater than or equal to the loss value of the decoding layer; if the loss value of the encoding layer is less than the loss value of the decoding layer, the parameters of the encoding layer are not adjusted.
[0169] In one possible implementation, if the training object is the decoding layer, the adjustment module 704 is specifically used to adjust the parameters of the decoding layer if the loss value of the decoding layer is greater than or equal to the loss value of the encoding layer; if the loss value of the decoding layer is less than the loss value of the encoding layer, the parameters of the decoding layer are not adjusted.
[0170] In a possible implementation, the training objects are the encoding layer and the decoding layer, and the adjustment module 704 is specifically used to determine the target loss value according to the loss value of the encoding layer and the loss value of the decoding layer; and adjust the parameters of the encoding layer and the decoding layer according to the target loss value.
[0171] In a possible implementation, the determination module 701 is specifically used to obtain annotated text, which is text that describes elements included in the sample image to be generated; perform data enhancement on the annotated text to obtain enhanced text; input the enhanced text into the first model for prediction to obtain a predicted image; and use the predicted image as a sample image.
[0172] In a possible implementation, the determination module 701 is specifically used to obtain annotated text, which is text that describes elements included in the sample image to be generated; perform data enhancement on the annotated text to obtain enhanced text; input the enhanced text into the first model for prediction to obtain a predicted image; input the predicted image into the second model to obtain an enhanced image; and use the enhanced image as a sample image.
[0173] In a possible implementation, the determination module 701 is specifically configured to perform image classification processing on the sample image to determine a label of the sample image.
[0174] Based on the same technical concept, on the basis of the above embodiments, the present application provides a training device for a classification model, wherein the initial classification model includes a coding layer and a decoding layer. Figure 8 A schematic diagram of the structure of an image classification device provided in an embodiment of the present application, the device comprising:
[0175] The classification module 801 is used to input the image to be classified into a classification model to obtain a target classification of the image to be classified. The classification model is trained according to the training method of the classification model described in the above embodiments.
[0176] Based on the same technical concept, the present application also provides an electronic device, Fig. 9 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application is shown in FIG. Fig. 9 As shown, it includes: a processor 901, a communication interface 902, a memory 903 and a communication bus 904, wherein the processor 901, the communication interface 902, and the memory 903 communicate with each other through the communication bus 904;
[0177] The memory 903 stores a computer program. When the program is executed by the processor 901, the processor 901 performs the following steps:
[0178] Determine a sample image and a label of the sample image;
[0179] Encoding the sample image to obtain predicted semantic features;
[0180] Decoding the predicted semantic features to obtain a predicted classification of the sample image;
[0181] Determine a loss value of an encoding layer of a classification model according to the predicted semantic features and the standard semantic features of the sample image, and determine a loss value of a decoding layer of the classification model according to the predicted classification and the label;
[0182] The classification model is trained according to the loss value of the encoding layer and / or the loss value of the decoding layer.
[0183] In a possible implementation, the processor 901 is further configured to determine a training object for a current round according to the number of training rounds, where the training object includes a coding layer and / or a decoding layer of the classification model.
[0184] In a possible implementation, the processor 901 is further configured to, if the number of training rounds is within a first numerical interval, determine that the training object is the coding layer;
[0185] If the number of training rounds is within the second numerical range, determining that the training object is the decoding layer;
[0186] If the number of training rounds is in a third numerical interval, the training objects are determined to be the encoding layer and the decoding layer; wherein the minimum value of the third numerical interval is greater than the maximum value of the second numerical interval, and the minimum value of the second numerical interval is greater than the maximum value of the first numerical interval.
[0187] In a possible implementation, if the training object is the encoding layer, the processor 901 is further configured to adjust a parameter of the encoding layer if a loss value of the encoding layer is greater than or equal to a loss value of the decoding layer;
[0188] If the loss value of the encoding layer is smaller than the loss value of the decoding layer, the parameters of the encoding layer are not adjusted.
[0189] In a possible implementation, if the training object is the decoding layer, the processor 901 is further configured to adjust the parameters of the decoding layer if the loss value of the decoding layer is greater than or equal to the loss value of the encoding layer;
[0190] If the loss value of the decoding layer is smaller than the loss value of the encoding layer, the parameters of the decoding layer are not adjusted.
[0191] In a possible implementation manner, if the training object is the encoding layer and the decoding layer, the processor 901 is further configured to determine a target loss value according to the loss value of the encoding layer and the loss value of the decoding layer;
[0192] According to the target loss value, parameters of the encoding layer and the decoding layer are adjusted.
[0193] In a possible implementation manner, the processor 901 is further configured to obtain an annotation text, where the annotation text is a text describing an element included in the sample image to be generated;
[0194] Performing data enhancement on the annotated text to obtain enhanced text;
[0195] Inputting the enhanced text into a first model for prediction to obtain a predicted image;
[0196] The predicted image is used as a sample image.
[0197] In a possible implementation manner, the processor 901 is further configured to obtain an annotation text, where the annotation text is a text describing an element included in the sample image to be generated;
[0198] Performing data enhancement on the annotated text to obtain enhanced text;
[0199] Inputting the enhanced text into a first model for prediction to obtain a predicted image;
[0200] Inputting the predicted image into a second model to obtain an enhanced image;
[0201] The enhanced image is used as a sample image.
[0202] In a possible implementation, the processor 901 is further configured to perform image classification processing on the sample image to determine a label of the sample image.
[0203] Since the principle of solving the problem by the above electronic device is similar to the training method of the classification model, the implementation of the above electronic device can refer to the embodiment of the method, and the repeated parts will not be repeated.
[0204] The memory 903 stores a computer program. When the program is executed by the processor 901, the processor 901 may further perform the following steps:
[0205] The image to be classified is input into a classification model to obtain a target classification of the image to be classified, and the classification model is trained according to the classification model training method described in the above embodiments.
[0206] Since the principle of solving the problem by the above electronic device is similar to that of the image classification method, the implementation of the above electronic device can refer to the embodiment of the method, and the repeated parts will not be repeated.
[0207] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The communication interface 902 is used for communication between the above electronic device and other devices. The memory may include a random access memory (RAM) and may also include a non-volatile memory (NVM), such as at least one disk storage. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0208] The above-mentioned processor can be a general-purpose processor, including a central processing unit, a network processor (Network Processor, NP), etc.; it can also be a digital signal processing processor (Digital Signal Processing, DSP), an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, etc.
[0209] Based on the same technical concept, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program that can be executed by an electronic device. When the program runs on the electronic device, the electronic device implements the classification model training method or image classification method described in any of the above embodiments when executing.
[0210] The above-mentioned computer-readable storage medium can be any available medium or data storage device that can be accessed by the processor in the electronic device, including but not limited to magnetic storage such as floppy disks, hard disks, magnetic tapes, MO (magneto-optical disks), etc., optical storage such as CD, DVD, BD, HVD, etc., and semiconductor storage such as ROM, EPROM, EEPROM, NAND FLASH (non-volatile memory), SSD (solid state drive), etc.
[0211] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0212] Based on the same technical concept, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program that can be executed by an electronic device. When the program runs on the electronic device, the electronic device implements the data classification method or image classification method described in any of the above embodiments when executing.
[0213] The above-mentioned computer-readable storage medium can be any available medium or data storage device that can be accessed by the processor in the electronic device, including but not limited to magnetic storage such as floppy disks, hard disks, magnetic tapes, MO (magneto-optical disks), etc., optical storage such as CD, DVD, BD, HVD, etc., and semiconductor storage such as ROM, EPROM, EEPROM, NAND FLASH (non-volatile memory), SSD (solid state drive), etc.
[0214] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0215] Based on the same technical concept, an embodiment of the present application provides a computer program product, which includes: computer program code, which, when executed on an electronic device, enables the electronic device to implement the classification model training method or image classification method described in any of the above embodiments.
[0216] The computer program for performing the operation of the present disclosure may be an assembly instruction, an instruction set architecture (ISA) instruction, a machine instruction, a machine-related instruction, a microcode, a firmware instruction, a state setting data, or a source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions may be executed completely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be personalized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the present disclosure.
[0217] The computer program product described herein may be implemented in hardware, software, or a combination thereof. In one optional embodiment, the computer program product is embodied as a computer storage medium, and in another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (SDK), etc.
[0218] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0219] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0220] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0221] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0222] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A classification model training method, characterized in that: include: Determine a sample image and a label of the sample image; Encoding the sample image to obtain predicted semantic features; Decoding the predicted semantic features to obtain a predicted classification of the sample image; Determine a loss value of an encoding layer of a classification model according to the predicted semantic features and the standard semantic features of the sample image, and determine a loss value of a decoding layer of the classification model according to the predicted classification and the label; The classification model is trained according to the loss value of the encoding layer and / or the loss value of the decoding layer.
2. The method according to claim 1, characterized in that Before training the classification model according to the loss value of the encoding layer and / or the loss value of the decoding layer, the method further includes: The training object of the current round is determined according to the number of training rounds, and the training object includes the encoding layer and / or decoding layer of the classification model.
3. The method according to claim 2, characterized in that The step of determining the training object of the current round according to the number of training rounds includes: If the number of training rounds is within a first numerical range, determining that the training object is the coding layer; If the number of training rounds is within the second numerical range, determining that the training object is the decoding layer; If the number of training rounds is in a third numerical interval, the training objects are determined to be the encoding layer and the decoding layer; wherein the minimum value of the third numerical interval is greater than the maximum value of the second numerical interval, and the minimum value of the second numerical interval is greater than the maximum value of the first numerical interval.
4. The method according to claim 3, characterized in that If the training object is the encoding layer, training the classification model according to the loss value of the encoding layer and / or the loss value of the decoding layer includes: If the loss value of the encoding layer is greater than or equal to the loss value of the decoding layer, adjusting the parameters of the encoding layer; If the loss value of the encoding layer is smaller than the loss value of the decoding layer, the parameters of the encoding layer are not adjusted.
5. The method according to claim 3, characterized in that: If the training object is the decoding layer, training the classification model according to the loss value of the encoding layer and / or the loss value of the decoding layer includes: If the loss value of the decoding layer is greater than or equal to the loss value of the encoding layer, adjusting the parameters of the decoding layer; If the loss value of the decoding layer is smaller than the loss value of the encoding layer, the parameters of the decoding layer are not adjusted.
6. The method according to claim 3, characterized in that: If the training object is the encoding layer and the decoding layer, training the classification model according to the loss value of the encoding layer and / or the loss value of the decoding layer includes: Determining a target loss value according to the loss value of the encoding layer and the loss value of the decoding layer; According to the target loss value, parameters of the encoding layer and the decoding layer are adjusted.
7. The method according to claim 1, characterized in that The process of determining the sample image comprises: Acquire an annotation text, where the annotation text is a text describing an element included in the sample image to be generated; Performing data enhancement on the annotated text to obtain enhanced text; Inputting the enhanced text into a first model for prediction to obtain a predicted image; The predicted image is used as a sample image.
8. The method according to claim 1, characterized in that The process of determining the sample image comprises: Acquire an annotation text, where the annotation text is a text describing an element included in the sample image to be generated; Performing data enhancement on the annotated text to obtain enhanced text; Inputting the enhanced text into a first model for prediction to obtain a predicted image; Inputting the predicted image into a second model to obtain an enhanced image; The enhanced image is used as a sample image.
9. The method according to claim 1, characterized in that: The process of determining the label of the sample image includes: Perform image classification processing on the sample image to determine a label of the sample image.
10. An image classification method, characterized in that: include: The image to be classified is input into a classification model to obtain a target classification of the image to be classified, and the classification model is trained according to the training method of the classification model according to any one of claims 1 to 9.
11. A training device for a classification model, characterized in that: The device comprises: A determination module, used to determine a sample image and a label of the sample image; An encoding module, used for encoding the sample image to obtain predicted semantic features; A decoding module, used for decoding the predicted semantic features to obtain the predicted classification of the sample image; The determination module is further used to determine the loss value of the encoding layer of the classification model according to the predicted semantic features and the standard semantic features of the sample image, and to determine the loss value of the decoding layer of the classification model according to the predicted classification and the label; An adjustment module is used to train the classification model according to the loss value of the encoding layer and / or the loss value of the decoding layer.
12. An image classification device, characterized in that: The device comprises: The classification module is used to input the image to be classified into the classification model to obtain the target classification of the image to be classified, and the classification model is trained according to the training method of the classification model according to any one of claims 1 to 9.
13. An electronic device, characterized in that: The electronic device includes at least a processor and a memory, and the processor is used to implement the steps of the training method of the classification model as described in any one of claims 1 to 9, or the steps of the image classification method as described in claim 10 when executing the computer program stored in the memory.
14. A computer storage medium, characterized in that: It stores a computer program that can be executed by an electronic device. When the program is run on the electronic device, the electronic device executes the steps of the training method of the classification model described in any one of claims 1 to 9, or the steps of the image classification method described in claim 10.
15. A computer program product, characterized in that The computer program product includes: a computer program code, which, when executed on the electronic device, enables the electronic device to execute the steps of the classification model training method described in any one of claims 1 to 9, or the steps of the image classification method described in claim 10.
Citation Information
Patent Citations
Data processing model training method and device
CN111639684A
Image classifier training method and device, equipment and storage medium
CN114241236A
Text recognition model training method and device and text recognition method and device
CN114372477A
