Classification model training method, device, equipment and storage medium
Through multiple training and loss calculation methods, the problems of low efficiency of classification methods and low model accuracy in the existing technology are solved, high-accuracy classification model training is achieved, and classification accuracy and model generalization capabilities are improved.
Patent Information
- Application Number
- CN202210226165.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-09
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2042-03-09
AI Technical Summary
Existing classification methods are inefficient and model training methods cannot obtain a classification model with high accuracy, resulting in low accuracy in determining the type of objects to be classified.
By obtaining the first training sample set and the second training sample set, using the initial model to perform multiple trainings on the image to be predicted, and calculating the total training loss based on the actual probability and predicted probability of the image to be predicted until the total training loss meets the training end conditions, we get Classification model with high accuracy.
It improves the type prediction accuracy of the classification model and the calculation efficiency of the training loss, enhances the feature learning ability of the initial model for samples with different rotation angles, and obtains a model with higher classification accuracy.
Smart Images

Figure CN114581734B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence, and in particular to a classification model training method, apparatus, device and storage medium. Background Art
[0002] With the continuous improvement of science and technology and production level, object classification is often involved in real life. For example, in the field of logistics, it is necessary to effectively classify items to improve logistics efficiency, and in the field of autonomous driving, it is necessary to classify different types of road elements on the road.
[0003] Existing classification methods often classify objects to be classified manually, or pre-train a classification model based on artificial intelligence technology, so that the type of the object to be classified can be determined based on the relevant information of the object to be classified (such as the image information of the object to be classified) through the trained classification model. However, the classification efficiency of the manual classification method is low, and the existing model training method cannot obtain a classification model with a high accuracy, so that the accuracy of determining the type of the object to be classified is low. Summary of the invention
[0004] The embodiments of the present application provide a classification model training method, apparatus, device and storage medium, which can obtain a classification model with high accuracy based on a small amount of training sample images.
[0005] On the one hand, an embodiment of the present application provides a classification model training method, the method comprising:
[0006] Acquire a first training sample set and a second training sample set, wherein the first training sample set and the second training sample set include a plurality of image sets, and each of the image sets includes at least one sample image of a preset type;
[0007] Inputting the image to be predicted and each sample image in the first training sample set into the initial model to obtain a first prediction probability that the image to be predicted belongs to each of the preset types, wherein the image to be predicted is any image in the second training sample set;
[0008] Based on the target preset type corresponding to the image to be predicted, determining a first actual probability that the image to be predicted belongs to each of the preset types, and determining a total training loss based on each of the first predicted probabilities and each of the first actual probabilities;
[0009] The initial model is iteratively trained based on the first training sample set and the second training sample set until the total training loss meets the training end condition, and the training is stopped, and the model at the time of stopping the training is determined as the classification model.
[0010] On the other hand, an embodiment of the present application provides a classification model training device, the device comprising:
[0011] A sample acquisition module, used to acquire a first training sample set and a second training sample set, wherein the first training sample set and the second training sample set include a plurality of image sets, and each of the image sets includes at least one sample image of a preset type;
[0012] A sample processing module, used for inputting the image to be predicted and each sample image in the first training sample set into the initial model to obtain a first prediction probability that the image to be predicted belongs to each of the preset types, wherein the image to be predicted is any image in the second training sample set;
[0013] A data processing module, used to determine, based on the target preset type corresponding to the image to be predicted, a first actual probability that the image to be predicted belongs to each of the preset types, and determine a total training loss based on each of the first predicted probabilities and each of the first actual probabilities;
[0014] The model training module is used to iteratively train the initial model based on the first training sample set and the second training sample set until the total training loss meets the training end condition and the training is stopped, and the model at the time of stopping the training is determined as the classification model.
[0015] On the other hand, an embodiment of the present application provides an electronic device, including a processor and a memory, wherein the processor and the memory are connected to each other;
[0016] The memory is used to store computer programs;
[0017] The above-mentioned processor is configured to execute the classification model training method provided in the embodiment of the present application when calling the above-mentioned computer program.
[0018] On the other hand, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the classification model training method provided by the embodiment of the present application.
[0019] On the other hand, an embodiment of the present application provides a computer program product, which includes a computer program. When the above computer program is executed by a processor, it implements the classification model training method provided by the embodiment of the present application.
[0020] In the embodiment of the present application, in each training process for the initial model, the input of the initial model is all sample images in the first training sample set and one sample image in the second training sample set. When the sample image input to the initial model from the second training sample set is used as the image to be predicted, the initial model can be trained multiple times based on the first training sample set and the second training sample set, and the sample images in the first training sample set and the second training sample set can be effectively used. At the same time, the total training loss is determined based on the actual probability and predicted probability that the image to be predicted belongs to each preset type, which can not only improve the calculation efficiency of the total training loss, but also train the initial model with full reference to the predicted probability that the image to be predicted belongs to each preset type, so that when the total training loss meets the training end condition, the type prediction accuracy of the initial model can be maximized, and finally a classification model with high classification accuracy can be obtained. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in 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 creative work.
[0022] Figure 1 It is a scenario diagram of the classification model training method provided in an embodiment of the present application;
[0023] Figure 2 It is a flow chart of the classification model training method provided in the embodiment of the present application;
[0024] Figure 3 is a schematic diagram of a scenario for determining initial type features provided in an embodiment of the present application;
[0025] Figure 4 is a structural schematic diagram of an initial model provided in an embodiment of the present application;
[0026] Figure 5 is a schematic diagram of a scenario for determining feature pairs provided in an embodiment of the present application;
[0027] Figure 6 is another structural schematic diagram of the initial model provided in the embodiment of the present application;
[0028] Figure 7 It is another structural schematic diagram of the initial model provided in the embodiment of the present application;
[0029] Figure 8 It is another structural schematic diagram of the initial model provided in the embodiment of the present application;
[0030] Fig. 9It is a schematic diagram of an application scenario of the classification model provided in an embodiment of the present application;
[0031] Fig.10 It is a structural diagram of a classification model training device provided in an embodiment of the present application;
[0032] Fig.11 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0033] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0034] The classification model training method provided in the embodiment of the present application can be implemented through relevant technologies in the fields of artificial intelligence, cloud computing, image processing, etc. For example, the machine learning technology in the field of artificial intelligence and the computer vision technology in the field of image processing can be used as the technical basis for model training to obtain a classification model.
[0035] Among them, machine learning is a multi-disciplinary interdisciplinary subject, involving probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory and other disciplines. It specializes in studying how computers simulate or implement human learning behavior to acquire new knowledge or skills, such as training classification models based on machine learning technology. Machine learning is the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications are spread across all areas of artificial intelligence. Machine learning and deep learning usually include artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning and other technologies.
[0036] Among them, computer vision technology generally includes image processing, image recognition, image semantic understanding, image retrieval, OCR, video processing, video semantic understanding, video content / behavior recognition, three-dimensional object reconstruction, 3D technology, virtual reality, augmented reality, simultaneous positioning and map construction, autonomous driving, smart transportation and other technologies, as well as common biometric recognition technologies such as face recognition and fingerprint recognition.
[0037] The classification model training method provided in the embodiment of the present application can perform model training based on sample images of different scenes to determine the types of objects in different scenes based on the trained classification model. For example, if a classification model is trained based on sample images in the traffic field (such as images of cars, pedestrians, traffic signs, traffic lights, etc.), the classification model can be applied to intelligent transportation systems (Intelligent Traffic System, ITS), intelligent vehicle infrastructure cooperative systems (Intelligent Vehicle Infrastructure Cooperative Systems, IVICS) or automatic driving systems, etc., to identify the categories of various road objects on the road.
[0038] For example, model training can also be performed based on sample images of different types of logistics products to determine the category of the logistics products based on the trained classification model, thereby achieving rapid sorting of the logistics products.
[0039] Among them, the intelligent transportation system, also known as the intelligent transportation system (Intelligent Transportation System), effectively and comprehensively applies advanced science and technology (information technology, computer technology, data communication technology, sensor technology, electronic control technology, automatic control theory, operations research, artificial intelligence, etc.) to transportation, service control and vehicle manufacturing, and strengthens the connection between vehicles, roads and users, thus forming a comprehensive transportation system that ensures safety, improves efficiency, improves the environment and saves energy.
[0040] Intelligent vehicle-road cooperative system, referred to as vehicle-road cooperative system, is a development direction of intelligent transportation system (ITS). The vehicle-road cooperative system adopts advanced wireless communication and new generation Internet technologies to implement all-round dynamic real-time information interaction between vehicles and roads, and carries out active vehicle safety control and road cooperative management based on the collection and integration of dynamic traffic information in all time and space, fully realizing the effective coordination of people, vehicles and roads, ensuring traffic safety, and improving traffic efficiency, thus forming a safe, efficient and environmentally friendly road traffic system.
[0041] The classification model training method provided in the embodiment of the present application can be implemented based on a server or a terminal.
[0042] The server may be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides cloud computing services.
[0043] Among them, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, an intelligent voice interaction device (such as a smart speaker), a wearable electronic device (such as a smart watch), a vehicle terminal, a smart home appliance (such as a smart TV), an AR / VR device, etc., but is not limited to these.
[0044] See also Figure 1 , Figure 1 Schematic diagram of the classification model training method provided in the embodiment of the present application. Figure 1 As shown, before training the initial model, it is necessary to determine the first training sample set and the second training sample set.
[0045] The first training sample set and the second training sample set each include a plurality of image sets, and each image set includes at least one sample image of a preset type.
[0046] The sample images included in the image sets corresponding to the same preset type in the first training sample set and the second training sample set may be the same or different, which is not limited here.
[0047] Furthermore, in a training process, the input of the initial model is each sample image in the first training sample set and any sample image in the second training sample set (the sample image is the image to be predicted), and then the initial model can be used to determine the first prediction probability of each preset type corresponding to the first training sample set and the second training sample set.
[0048] In one training process, the highest probability among the first prediction probabilities that the image to be predicted in the training process belongs to each preset type is the prediction type of the image to be predicted in this training process.
[0049] In a training process, the first actual probability that the image to be predicted belongs to each preset type can be determined based on the target preset type corresponding to the image to be predicted, that is, the preset type actually corresponding to the image to be predicted. For example, each preset type includes type 1, type 2, and type 3, and the preset type actually corresponding to the image to be predicted is type 1, then the first actual probability that the image to be predicted belongs to type 1 is 1, and the first actual probability that the image to be predicted belongs to type 2 and type 3 is 0.
[0050] Furthermore, the total training loss can be determined based on the first predicted probability and the first actual probability that the image to be predicted belongs to each preset type. That is, in the process of iteratively training the initial model based on the first training sample set and the second training sample set, a total training loss is determined in each training process, so that the training is stopped when the total training loss corresponding to a certain training meets the training end condition, and the model at the time of stopping the training is determined as the final classification model.
[0051] See also Figure 2 , Figure 2 It is a flow chart of the classification model training method provided in the embodiment of the present application.
[0052] like Figure 2 As shown, the classification model training method provided in the embodiment of the present application may include the following steps:
[0053] Step S21: Obtain a first training sample set and a second training sample set.
[0054] The first training sample set and the second training sample set each include a plurality of image sets, each image set includes at least one sample image of a preset type, and the first training sample set and the second training sample set correspond to the same preset type.
[0055] For example, the first training sample set includes image set 1, image set 2, and image set 3, and image set 1 includes at least one sample image belonging to type 1, image set 2 includes at least one sample image belonging to type 2, and image set 3 includes at least one sample image belonging to type 3. For the second training sample set, the second training sample set also includes 3 image sets, and each image set includes at least one sample image belonging to type 1, type 2, and type 3, respectively.
[0056] The sample images included in the image sets corresponding to the same preset type in the first training sample set and the second training sample set may be the same or different, and there is no limitation here. Also, for any image set in the first training sample set and the second training sample set, there is no limitation on the number of sample images in the image set.
[0057] Among them, each sample image in the first training sample set and the second training sample set can be obtained from a public dataset, or can be collected based on big data, or can be pre-photographed before model training, etc., and there is no limitation here.
[0058] As an example, for a certain public data set, a certain number of preset types can be determined from the public data set, and a certain number of images of each preset type in the public data set are obtained as sample images to construct a first training sample set. Further, a certain number of images of each preset type in the public data set are also obtained as sample images to construct a second training sample set.
[0059] Among them, if after the initial model is trained based on the first training sample set and the second training sample set constructed in the above manner, the corresponding total training loss still does not meet the training end condition, then a new first training sample set and a second training sample set are reconstructed based on the above manner, and the initial model is continued to be iteratively trained based on the new first training sample set and the second training sample set until the final classification model is obtained.
[0060] The above-mentioned public data sets include but are not limited to the miniImageNet data set, the tieredImageNet data set and the ImageNet data set, which are not limited here.
[0061] Step S22: input the image to be predicted and each sample image in the first training sample set into the initial model to obtain a first prediction probability that the image to be predicted belongs to each preset type, and the image to be predicted is any image in the second training sample set.
[0062] In each training process, the input of the initial model is each sample image in the first training sample set and a sample image in the second training sample set, and the sample image in the second training sample input to the initial model is the image to be predicted in this training process.
[0063] Alternatively, in each training process, when a sample image in the second training sample is input into the initial model as the image to be predicted, for the first training sample set, at least one sample image in each image set can be input into the initial model, that is, at least one sample image corresponding to each preset type in the first training sample set is input into the initial model.
[0064] Among them, the initial model includes a feature extraction network. After the image to be predicted and the sample images in the first training sample set are input into the initial model, the first initial image features of the image to be predicted and the second initial image features of each sample image in the first training sample set can be determined based on the feature extraction network of the initial model.
[0065] Among them, the specific network structure of the feature extraction network in the initial model is not limited, such as ResNet-12, WideResNet, SENet, HRNet, etc., which is not limited here.
[0066] Specifically, based on the feature extraction network in the initial model, the second initial image feature of each sample image in the first training sample set can be determined. For the second initial image feature of the sample image corresponding to each preset type, the initial type feature corresponding to the preset type can be determined based on each second initial image feature corresponding to the preset type. The initial type feature corresponding to each preset type is used to characterize the image feature of the sample image of the preset type.
[0067] Among them, for each preset type, when determining the initial type feature corresponding to the preset type, the second initial image features corresponding to the preset type can be averaged, and the final result can be used as the initial type feature corresponding to the preset type. Alternatively, the second initial image features corresponding to the preset type can be feature fused based on a feature fusion network to obtain the initial type feature corresponding to the preset type.
[0068] See also Figure 3 , Figure 3 Schematic diagram of a scenario for determining initial type features provided in an embodiment of the present application. Figure 3 As shown, after each sample image in a certain image set in the first training sample set is input into the initial model, the second initial image feature of each sample image can be determined based on the feature extraction network in the initial model, such as the second initial image features of three sample images in the image set. The corresponding feature values of each second initial image feature can be further averaged to obtain the initial type feature corresponding to the preset type of the image set.
[0069] Furthermore, after determining the initial type features corresponding to each preset type and the first initial image features of the image to be predicted, the feature pairs of the image to be predicted corresponding to each preset type can be determined based on the initial type features corresponding to each preset type and the first initial image features of the image to be predicted.
[0070] Among them, the image to be predicted corresponds to a feature pair of each preset type, including a target image feature after attention enhancement is performed on the first initial image feature based on the first initial image feature and the initial type feature corresponding to the preset type, and a target type feature after attention enhancement is performed on the initial type feature corresponding to the preset type.
[0071] That is, the initial type features corresponding to each preset type and the first initial image features of the image to be predicted can be input into the attention enhancement network in the initial model to respectively perform attention enhancement on the first initial image features and the initial type features corresponding to the preset type to obtain the target image features and target type features after attention enhancement.
[0072] For example, if the initial type feature corresponding to the preset type n is hn, and the first initial image feature of the image to be predicted is q, the initial type feature hn and the first initial image feature q corresponding to the preset type n are input into the attention enhancement network to obtain the target image feature Qn and the target type feature Hn after attention enhancement, and [Hn, Qn] can be determined as the feature pair corresponding to the preset type n.
[0073] Furthermore, based on the feature pairs corresponding to each preset type of the image to be predicted, the first prediction probability that the image to be predicted belongs to each preset type can be determined. That is, for any feature pair, the first prediction probability that the image to be predicted belongs to the preset type corresponding to the feature pair can be determined based on the feature pair.
[0074] Among them, for the feature pair corresponding to each preset type of the image to be predicted, the similarity between the target type feature and the target image feature in the feature pair can be determined, and the higher the similarity between the target type feature and the target image feature in the feature pair, the higher the probability that the image to be predicted belongs to the preset type corresponding to the feature pair. Based on this, the similarity between the target type feature and the target image feature in each feature pair can be determined based on the first prediction network in the initial model, and based on the corresponding similarity of each feature pair, the first prediction probability that the image to be predicted belongs to each preset type is determined.
[0075] Among them, the measurement method of the similarity between the target type feature and the target image feature in each feature pair can be determined based on cosine similarity, a learnable metric method, Euclidean distance, Manhattan distance or Minkowski distance, etc., and is not limited here.
[0076] See also Figure 4 , Figure 4 Schematic diagram of the initial model provided in the embodiment of the present application. Figure 4 As shown, each image set in the first training sample set and the image to be predicted in the second training sample are input into the feature extraction network in the initial model, and the initial type features corresponding to each preset type [h 1 ,h 2 ,…,h n ] and the first initial image feature q corresponding to the image to be predicted. Then the initial type feature [h 1 ,h 2 ,…,h n ] and the first initial image feature q corresponding to the image to be predicted are input into the attention enhancement network to obtain the feature pairs {[H 1 ,Q 1 ],[H 2 ,Q 2 ],…,[H n ,Q n ]}.
[0077] For example, based on the initial type feature h corresponding to the preset type n n and the first initial image feature q, the initial type feature h corresponding to the preset type n is enhanced by the attention network nAnd the first initial image feature q is used for attention enhancement to obtain the target type feature H after attention enhancement n and target image features Q n , and the target type feature H corresponding to the preset type n n and target image features Q n Determine that the image to be predicted corresponds to a feature pair of preset type n ([H n ,Q n ]).
[0078] Furthermore, based on the feature pairs corresponding to the preset types of the image to be predicted, the first prediction probability that the image to be predicted belongs to each preset type can be determined. 1 ,Q 1 ] Determine the first prediction probability P of the image to be predicted belonging to the preset type 1 1 , based on the feature pair [H 2 ,Q 2 ] Determine the first prediction probability P of the image to be predicted belonging to the preset type 2 2 , ..., based on the feature pair [H n ,Q n ] Determine the first prediction probability P of the image to be predicted belonging to the preset type n n .
[0079] In an embodiment of the present application, the attention enhancement network in the initial model can be a dynamic graph convolutional network based cross attention module (Dynamic Graph Convolutional Network based Cross Attention Module, DGCN-CAM), or other attention networks, which is not limited here.
[0080] In an embodiment of the present application, for each preset type, when determining the feature pair of the image to be predicted corresponding to the preset type, the cross-correlation matrix of the initial type features and the first initial image features corresponding to the preset type can be determined, and the cross-correlation matrix can be used for the association relationship between the initial type features and the first initial image.
[0081] Furthermore, based on the initial type feature corresponding to the preset type, the first initial image feature of the image to be predicted and the cross-correlation matrix, the first attention feature corresponding to the preset type and the second attention feature corresponding to the first initial image feature are determined.
[0082] For example, the above-mentioned correlation matrix is used as the dynamic adjacency matrix of graph convolution, and then the initial type features and the first initial image features corresponding to the preset type are processed based on the graph convolution network to obtain the first attention features corresponding to the preset type and the second attention features corresponding to the first initial image features.
[0083] Further, the target type feature corresponding to the preset type can be determined based on the initial type feature and the first attention feature corresponding to the preset type. That is, based on the first attention feature of the preset type pair, the initial type feature corresponding to the preset type is enhanced to obtain the target type feature after the attention enhancement. Similarly, based on the first initial image feature and the second attention feature, the target image feature corresponding to the image to be predicted is determined. That is, based on the second attention feature, the first initial image feature is enhanced to obtain the enhanced target image feature corresponding to the image to be predicted.
[0084] Among them, for each preset type, when determining the correlation matrix corresponding to the initial type feature corresponding to the preset type and the first initial image feature, a first correlation submatrix of the initial type feature of the preset type compared to the first initial image feature, and a second correlation matrix of the first initial image feature compared to the initial type feature corresponding to the preset type can be determined, and then based on the first correlation submatrix, the second correlation submatrix and the unit matrix, the correlation matrix corresponding to the initial type feature corresponding to the preset type and the first initial image feature is determined.
[0085] Taking preset type n as an example, the initial type feature corresponding to preset type n is h n , the first initial image feature of the image to be predicted is q, and the initial type feature h corresponding to the preset type n n Compared with the first cross-correlation matrix of the first initial image feature q It can be determined based on:
[0086]
[0087] The first initial image feature q is compared with the initial type feature h corresponding to the preset type n. n The second cross-correlation matrix It can be determined based on:
[0088]
[0089] Initial type feature h corresponding to preset type n n The cross-correlation matrix corresponding to the first initial image feature q is:
[0090]
[0091] Among them, I is the unit matrix, that is, I = diag (1, 1, ..., 1).
[0092] Before determining any cross-correlation matrix, the initial type feature h n And the first initial image feature q are transformed as follows:
[0093]
[0094] q=[q 1 ,q 2 ,…,q m ]∈R c×m
[0095] Among them, c is the number of channels, and m is the product of height and width. n After the first initial image feature q is converted from a three-dimensional feature to a two-dimensional feature, each cross-correlation submatrix is determined based on the above formula. Based on this, And the identity matrix I∈R m×m .
[0096] In the embodiment of the present application, determining that the feature pair corresponding to the preset type n of the image to be predicted can be determined based on the following method:
[0097] [H n ,Q n ]=([h n ,q]+[1,1])*[A n ,B n ]
[0098] Among them, A n is the first attention feature, B n is the second attention feature, and A n and B n With h n Same height and width as q.
[0099] See also Figure 5 , Figure 5 Schematic diagram of a scenario for determining feature pairs provided in an embodiment of the present application. Figure 5 As shown, for a preset type, the mutual correlation matrix of the initial type feature corresponding to the preset type and the first initial image feature of the image to be predicted is determined, and used as the dynamic adjacency matrix of the graph convolution network in the attention enhancement network. The initial type feature corresponding to the preset type and the first initial image feature are further subjected to graph convolution processing, and finally the first attention feature corresponding to the preset type and the second attention feature corresponding to the first initial image feature are obtained.
[0100] The initial type feature corresponding to the preset type is multiplied by the first attention feature to obtain a first result, and the initial type feature corresponding to the preset type is added to the first result as an offset to finally obtain the target type feature corresponding to the preset type.
[0101] Similarly, the first initial image feature and the second attention are multiplied to obtain the second result, and the first initial image feature is added to the second result as the bias, and finally the target image feature corresponding to the image to be predicted is obtained. Thus, the above target type feature and target image feature can be determined as the feature pair corresponding to the preset type of the image to be predicted.
[0102] By enhancing the attention of the initial type features and the first initial image features of each preset type, the target object features in the sample image can be highlighted and the background feature interference can be reduced, so that the final target type features and target image features have better feature representation capabilities.
[0103] Step S23: determining the first actual probability that the image to be predicted belongs to each preset type based on the target preset type corresponding to the image to be predicted, and determining the total training loss based on each first predicted probability and each first actual probability.
[0104] Specifically, the target preset type corresponding to the image to be predicted is the preset type actually corresponding to the image to be predicted. Based on the target preset type corresponding to the image to be predicted, it can be determined that the first actual probability that the image to be predicted belongs to the target preset type is 1, and the first actual probability that it belongs to other preset types is 0.
[0105] Based on this, a first training loss may be determined based on the first preset probabilities that the image to be predicted belongs to each preset type and each first actual probability, and the first training loss may be used as the total training loss.
[0106] Optionally, the first prediction type of the image to be predicted can be determined based on the first prediction probability that the image to be predicted belongs to each preset type, and the actual type of the image to be predicted (i.e., the target preset type) can be determined based on the first actual probability that the image to be predicted belongs to each preset type. Furthermore, the first training loss can be determined based on the first prediction type and the actual type corresponding to the image to be predicted, and the first training loss can be used as the total training loss.
[0107] In the embodiment of the present application, for each image set in the second training sample set, the image set also includes a rotated image of each sample image in the image set corresponding to at least one preset rotation angle. That is, for a sample image in each image set in the second training sample set, the image set also includes a rotated image of the sample image corresponding to at least one preset rotation angle, so that during the model training process, the same sample image at different preset rotation angles is used as an image to be predicted in different training processes. While increasing the number of training samples, the classification model finally obtained can perform type prediction on images to be predicted at different rotation angles, which helps to improve the generalization ability of the model.
[0108] Among them, the above-mentioned preset angles can be determined based on the actual application scenario requirements and are not limited here.
[0109] In this case, the initial model also includes an angle prediction network. During each training process, the feature pairs of the image to be predicted corresponding to the target preset type (actual preset type) can be determined from the feature pairs of the image to be predicted corresponding to each preset type and input into the angle prediction network to obtain the second prediction probability of the image to be predicted corresponding to each preset rotation angle.
[0110] Furthermore, the second actual probability of the image to be predicted belonging to each preset rotation angle can be determined based on the actual rotation angle of the image to be predicted, and then the second training loss is determined based on each second predicted probability and each second actual probability corresponding to the image to be predicted. And the total training loss is determined based on the first training loss and the second training loss.
[0111] See also Figure 6 , Figure 6 is another structural diagram of the initial model provided in the embodiment of the present application. Figure 6 As shown, each image set in the first training sample set and the image to be predicted in the second training sample are input into the feature extraction network in the initial model, and the initial type features corresponding to each preset type [h 1 ,h 2 ,…,h n ] and the first initial image feature q corresponding to the image to be predicted.
[0112] The initial type features corresponding to each preset type [h 1 ,h 2 ,…,h n ] and the first initial image feature q corresponding to the image to be predicted are input into the attention enhancement network to obtain the feature pairs {[H 1 ,Q 1 ],[H 2 ,Q 2 ],…,[H n ,Q n ]}.
[0113] Based on the feature pairs corresponding to each preset type of the image to be predicted, a first prediction probability [P 1 ,P 2 ,…,P n ] and determine the first training loss L based on the first actual probability and the first predicted probability that the image to be predicted belongs to each preset type 1 .
[0114] When the target preset type (actual preset type) corresponding to the image to be predicted is preset type n, the feature pair [H n ,Q n] Input the angle prediction network to obtain the second prediction probability of the image to be predicted corresponding to each preset rotation angle [V 1 ,V 2 ,…,V s ]. Where s is the index of the preset rotation angle.
[0115] After determining the second actual probability that the image to be predicted corresponds to each preset rotation angle, the second training loss L may be determined based on each second actual probability and each second predicted probability. 2 , and based on the first training loss L 1 and the second training loss determine the total training loss L.
[0116] Optionally, the predicted rotation angle of the image to be predicted may be determined based on the second predicted probability of the image to be predicted corresponding to each preset rotation angle, and then the second training loss may be determined based on the actual rotation angle and the predicted rotation angle of the image to be predicted.
[0117] Among them, the total training loss can be determined based on the following method:
[0118] L=DL 1 +[(w 2 +λ)L 2 +b 2 ]
[0119] Among them, w 2 For L 2 The loss weight, b 2 For L 2 The loss bias of σ 2 is the learnable weight corresponding to the angle prediction network during model training. D is L 1 , λ is the weight bias parameter, and D and λ can be determined based on actual needs, such as D can be 1 / 2 and λ can be 1.5, which are not limited here.
[0120] In an embodiment of the present application, the initial model also includes a second prediction network, which is used to determine the third prediction probability that the image to be predicted belongs to each preset type based on the feature pair of the image to be predicted corresponding to the target preset type.
[0121] That is, in each training process, the feature pair of the image to be predicted corresponding to the target preset type (actual preset type) can be input into the second prediction network to obtain the third prediction probability that the image to be predicted belongs to each preset type.
[0122] Furthermore, a third training loss may be determined based on the first actual probability and the third predicted probability that the image to be predicted belongs to each preset type, and a total training loss may be determined based on the first training loss and the third training loss.
[0123] See also Figure 7 , Figure 7 is another structural diagram of the initial model provided in the embodiment of the present application. Figure 7 As shown, each image set in the first training sample set and the image to be predicted in the second training sample are input into the feature extraction network in the initial model, and the initial type features corresponding to each preset type [h 1 ,h 2 ,…,h n ] and the first initial image feature q corresponding to the image to be predicted.
[0124] The initial type features corresponding to each preset type [h 1 ,h 2 ,…,h n ] and the first initial image feature q corresponding to the image to be predicted are input into the attention enhancement network to obtain the feature pairs {[H 1 ,Q 1 ],[H 2 ,Q 2 ],…,[H n ,Q n ]}.
[0125] Based on the feature pairs corresponding to each preset type of the image to be predicted, a first prediction probability [P 1 ,P 2 ,…,P n ] and determine the first training loss L based on the first actual probability and the first predicted probability that the image to be predicted belongs to each preset type 1 .
[0126] When the target preset type (actual preset type) corresponding to the image to be predicted is preset type n, the feature pair [H n ,Q n ] Input the second prediction network to obtain the third prediction probability [Y 1 ,Y 2 ,…,Y n Based on the first actual probability and the third predicted probability that the image to be predicted belongs to each preset type, the third training loss L is determined. 3 , and based on the first training loss L 1 and the third training loss L 3 Determine the total training loss L.
[0127] Optionally, the second prediction type of the image to be predicted can be determined based on the third prediction probability that the image to be predicted belongs to each preset type, and the actual type of the image to be predicted (i.e., the target preset type) can be determined based on the first actual probability that the image to be predicted belongs to each preset type, and then the third training loss can be determined based on the second prediction type and the actual type corresponding to the image to be predicted.
[0128] Among them, the total training loss can be determined based on the following method:
[0129] L=DL 1 +[(w 3 +λ)L 3 +b 3 ]
[0130] Among them, w 3 For L 3 The loss weight, b 2 For L 3 The loss bias of σ 3 is the learnable weight corresponding to the second prediction network during model training. D is L 1 , λ is the weight bias parameter, and D and λ can be determined based on actual needs, such as D can be 1 / 2 and λ can be 1.5, which are not limited here.
[0131] In an embodiment of the present application, the initial model may include a first prediction network, a second prediction network and an angle prediction network at the same time, and then based on the above implementation method, a first training loss, a second training loss and a third training loss may be determined, thereby determining a total training loss based on the first training loss, the second training loss and the third training loss.
[0132] See also Figure 8 , Figure 8 is another structural diagram of the initial model provided in the embodiment of the present application. Figure 8 As shown, each image set in the first training sample set and the image to be predicted in the second training sample are input into the feature extraction network in the initial model, and the initial type features corresponding to each preset type [h 1 ,h 2 ,…,h n ] and the first initial image feature q corresponding to the image to be predicted.
[0133] The initial type features corresponding to each preset type [h 1 ,h 2 ,…,h n ] and the first initial image feature q corresponding to the image to be predicted are input into the attention enhancement network to obtain the feature pairs {[H 1 ,Q 1],[H 2 ,Q 2 ],…,[H n ,Q n ]}.
[0134] Based on the feature pairs corresponding to each preset type of the image to be predicted, a first prediction probability [P 1 ,P 2 ,…,P n ] and determine the first training loss L based on the first actual probability and the first predicted probability that the image to be predicted belongs to each preset type 1 .
[0135] When the target preset type (actual preset type) corresponding to the image to be predicted is preset type n, the feature pair [H n ,Q n ] Input the angle prediction network to obtain the second prediction probability of the image to be predicted corresponding to each preset rotation angle [V 1 ,V 2 ,…,V s ] Wherein, s is the index of the preset rotation angle. Based on each second actual probability and each second predicted probability, determine the second training loss L 2 , the feature pair [H n ,Q n ] Input the second prediction network to obtain the third prediction probability [Y 1 ,Y 2 ,…,Y n Based on the first actual probability and the third predicted probability that the image to be predicted belongs to each preset type, the third training loss L is determined. 3 .
[0136] Based on the first training loss L 1 , the second training loss L 2 And the third training loss L 3 Determine the total training loss L.
[0137] Among them, the total training loss can be determined based on the following method:
[0138] L=DL 1 +[(w 2 +λ)L 2 +b 2 ]+[(w 3 +λ)L 3 +b 3 ]
[0139] Among them, w 2 For L 2 The loss weight, b2 For L 2 The loss bias of σ 2 w is the learnable weight corresponding to the angle prediction network during model training. 3 For L 3 The loss weight, b 2 For L 3 The loss bias of σ 3 is the learnable weight corresponding to the second prediction network during model training. D is L 1 , λ is the weight bias parameter, and D and λ can be determined based on actual needs, such as D can be 1 / 2 and λ can be 1.5, which are not limited here.
[0140] The learnable weights corresponding to the angle prediction network can be used to balance the training tasks of the first prediction network and the angle prediction network. The learnable weights corresponding to the second prediction network can be used to balance the training tasks of the first prediction network and the second prediction network. In this way, the learnable weights can be used to improve the representation ability of the features output by each network in the initial model during the iterative training process, thereby improving the prediction effect of the final classification model.
[0141] In the embodiment of the present application, when determining any of the first training loss, the second training loss, and the third training loss, it can be determined based on the cross entropy loss function or based on other loss functions, and there is no limitation here.
[0142] Step S24, iteratively train the initial model based on the first training sample set and the second training sample set until the total training loss meets the training end condition, and stop the training, and determine the model when the training is stopped as the classification model.
[0143] After determining the total training loss corresponding to training the initial model, the initial model may be iteratively trained based on the total training loss and the first training sample set and the second training sample set until the training is stopped when a training end condition is met.
[0144] Among them, the above-mentioned training end condition can be that the total training loss reaches convergence, or the total training loss for a consecutive preset number of times is less than a preset threshold, or the difference between two consecutive total training losses for a consecutive preset number of times is less than a preset threshold, etc. The specific conditions can be determined based on the actual application scenario requirements and are not limited here.
[0145] For each training, the training is stopped when the total training loss meets the training end condition, and the initial model at the end of the training is determined as the final classification model. If the total training loss does not meet the training end condition during the training of the initial model, the model parameters of the initial model can be adjusted, and the adjusted model is trained again based on the above method and the total training loss is determined, until the total training loss meets the training end condition, the training is stopped.
[0146] Optionally, after completing the training and obtaining the final model, the third training sample set can be determined based on the same method as the first training sample set, and the model at the end of the training can be inferred and verified based on the third training sample set. The model at the end of the training can be optimized based on the verification results to obtain the final classification model.
[0147] The preset types corresponding to the third training sample set and the first training sample set and / or the second training sample set may be the same or different, and the number of sample images of each preset type is not limited.
[0148] In an embodiment of the present application, when the initial model includes the second prediction network and the angle prediction network, the second prediction network and the angle prediction network in the model at the end of training can be removed, and the obtained model can be determined as a classification model.
[0149] The data processing processes involved in the embodiments of the present application, such as determining the similarity between the target image features and the target type features in the feature pair and determining various probabilities, can be implemented based on cloud computing technology. Cloud computing refers to the delivery and use mode of IT infrastructure, which refers to obtaining the required resources through the network in an on-demand and easily scalable manner. It is the product of the development and integration of traditional computer and network technologies such as grid computing, distributed computing, parallel computing, utility computing, network storage technologies, virtualization, and load balancing.
[0150] In an embodiment of the present application, after obtaining the classification model, a target image of the target object can be obtained, and the target image of the target object can be input into the classification model to obtain a prediction result corresponding to the target object, that is, the fourth prediction probability that the target object belongs to multiple types, and then the type corresponding to the highest fourth prediction probability is determined as the type of the target object.
[0151] Among them, the implementation method of the classification model determining the fourth prediction probability that the target object belongs to multiple types is the same as the implementation method of the aforementioned determining the first prediction probability that the image to be predicted belongs to each preset type, which will not be repeated here.
[0152] See also Fig. 9 , Fig. 9 Schematic diagram of the application scenario of the classification model provided in the embodiment of the present application. Fig. 9 As shown, in an item sorting system, an image acquisition device can be used to acquire images of items to be sorted, and each image can be input into a classification model to obtain the type of each item. For example, the type of the item to be sorted is determined to be vegetables or fruits based on the classification model, and then the items to be sorted are intelligently sorted based on the determined type, thereby improving the efficiency of item sorting.
[0153] In the embodiment of the present application, in each training process for the initial model, the input of the initial model is all sample images in the first training sample set and one sample image in the second training sample set. When the sample image input to the initial model from the second training sample set is used as the image to be predicted, the initial model can be trained multiple times based on the first training sample set and the second training sample set, and the sample images in the first training sample set and the second training sample set can be effectively used. At the same time, the images corresponding to different preset rotation angles of each sample image in the second training sample set are also used as the images to be predicted, so that when the number of sample images is small, not only the number of sample images can be increased, but also the feature learning and type prediction capabilities of the initial model for sample images with different rotation angles can be improved.
[0154] On the other hand, determining the total training loss based on the actual probability and predicted probability that the image to be predicted belongs to each preset type can not only improve the calculation efficiency of the total training loss, but also train the initial model with full reference to the predicted probability that the image to be predicted belongs to each preset type, so that the type prediction accuracy of the initial model can be maximized when the total training loss meets the training end condition. Through the attention enhancement network in the initial model, the influence of the image background information on the target type features corresponding to each preset type and the target image features corresponding to the image to be predicted can be reduced, and through the second prediction network and the angle prediction network jointly participating in the model training, the representation ability of the relevant features input to the first prediction network can be improved, so that the classification model obtained by training has higher accuracy, and finally a classification model with higher classification accuracy is obtained.
[0155] See also Fig.10 , Fig.10 : is a schematic diagram of the structure of the classification model training device provided in the embodiment of the present application. The device provided in the embodiment of the present application includes:
[0156] The sample acquisition module 101 is used to acquire a first training sample set and a second training sample set, wherein the first training sample set and the second training sample set include a plurality of image sets, and each of the image sets includes at least one sample image of a preset type;
[0157] A sample processing module 102, configured to input an image to be predicted and each sample image in the first training sample set into an initial model to obtain a first prediction probability that the image to be predicted belongs to each of the preset types, wherein the image to be predicted is any image in the second training sample set;
[0158] A data processing module 103 is used to determine, based on the target preset type corresponding to the image to be predicted, a first actual probability that the image to be predicted belongs to each preset type, and determine a total training loss based on each of the first predicted probabilities and each of the first actual probabilities;
[0159] The model training module 104 is used to iteratively train the initial model based on the first training sample set and the second training sample set until the total training loss meets the training end condition and stops the training, and determines the model at the time of stopping the training as the classification model.
[0160] In some feasible implementations, the sample processing module 102 is used to:
[0161] Determining a first initial image feature of the image to be predicted and a second initial image feature of each sample image in the first training sample set;
[0162] Determining an initial type feature corresponding to each of the preset types based on the second initial image features of each sample image corresponding to each of the preset types;
[0163] Determine a feature pair corresponding to each of the preset types for the image to be predicted, wherein the feature pair corresponding to each of the preset types for the image to be predicted includes a target image feature after the first initial image feature is enhanced based on the first initial image feature and the initial type feature corresponding to the preset type, and a target type feature after the initial type feature corresponding to the preset type is enhanced;
[0164] Based on the feature pairs of the to-be-predicted image corresponding to each of the preset types, a first prediction probability that the to-be-predicted image belongs to each of the preset types is determined.
[0165] In some feasible implementations, for each of the preset types, the sample processing module 102 is configured to:
[0166] Determine a mutual correlation matrix corresponding to an initial type feature corresponding to the preset type and the first initial image feature;
[0167] Determining a first attention feature and a second attention feature based on an initial type feature corresponding to the preset type, the first initial image feature and the cross-correlation matrix;
[0168] Determining a target type feature corresponding to the preset type based on the initial type feature corresponding to the preset type and the first attention feature;
[0169] Based on the first initial image feature and the second attention feature, a target image feature of the image to be predicted is determined.
[0170] In some feasible implementations, for each of the preset types, the sample processing module 102 is configured to:
[0171] Determine a first mutual correlation submatrix of the initial type feature corresponding to the preset type compared to the first initial image feature;
[0172] Determining a second cross-correlation submatrix of the first initial image feature compared to the initial type feature of the preset type;
[0173] Based on the first mutual correlation submatrix, the second mutual correlation submatrix and the identity matrix, a mutual correlation matrix corresponding to the initial type feature corresponding to the preset type and the first initial image feature is determined.
[0174] In some feasible implementations, for each of the image sets in the second training sample set, the image set further includes a rotated image of each sample image in the image set corresponding to at least one preset rotation angle;
[0175] The sample processing module 102 is further used for:
[0176] Determining, based on the feature pair of the to-be-predicted image corresponding to the target preset type, a second prediction probability of the to-be-predicted image corresponding to each of the preset rotation angles;
[0177] The data processing module 103 is used to:
[0178] determining a first training loss based on each of the first predicted probabilities and each of the first actual probabilities;
[0179] Determining, based on the target rotation angle corresponding to the image to be predicted, a second actual probability that the image to be predicted belongs to each of the preset rotation angles;
[0180] determining a second training loss based on each of the second predicted probabilities and each of the second actual probabilities;
[0181] A total training loss is determined based on the first training loss and the second training loss.
[0182] In some feasible implementations, the sample processing module 102 is further used to:
[0183] Determining, based on the feature pairs of the to-be-predicted image corresponding to the target preset type, a third prediction probability that the to-be-predicted image belongs to each of the preset types;
[0184] The data processing module 103 is used to:
[0185] Determining a third training loss based on each of the third predicted probabilities and each of the first actual probabilities;
[0186] A total training loss is determined based on the first training loss, the second training loss, and the third training loss.
[0187] In some feasible implementations, the data processing module 103 is further used to:
[0188] determining a target image of a target object;
[0189] Inputting the target image into the classification model to obtain a prediction result corresponding to the target object;
[0190] The type of the target object is determined based on the prediction result.
[0191] In a specific implementation, the above device can execute the above-mentioned functions through its built-in functional modules. Figure 2 For the implementation methods provided in each step, please refer to the implementation methods provided in the above steps for details, which will not be repeated here.
[0192] See also Fig.11 , Fig.11 Schematic diagram of the structure of the electronic device provided in the embodiment of the present application. Fig.11As shown, the electronic device 1100 in this embodiment may include: a processor 1101, a network interface 1104 and a memory 1105. In addition, the above-mentioned electronic device 1100 may also include: an object interface 1103, and at least one communication bus 1102. Among them, the communication bus 1102 is used to realize the connection and communication between these components. Among them, the object interface 1103 may include a display screen (Display), a keyboard (Keyboard), and the object interface 1103 may optionally include a standard wired interface and a wireless interface. The network interface 1104 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1104 may be a high-speed RAM memory, or it may be a non-volatile memory (NVM), such as at least one disk storage. The memory 1105 may optionally also be at least one storage device located away from the aforementioned processor 1101. As Fig.11 As shown, the memory 1105 as a computer-readable storage medium may include an operating system, a network communication module, an object interface module, and a device control application program.
[0193] exist Fig.11 In the electronic device 1100 shown, the network interface 1104 can provide a network communication function; the object interface 1103 is mainly used to provide an input interface for the object; and the processor 1101 can be used to call the device control application stored in the memory 1105 to achieve:
[0194] Acquire a first training sample set and a second training sample set, wherein the first training sample set and the second training sample set include a plurality of image sets, and each of the image sets includes at least one sample image of a preset type;
[0195] Inputting the image to be predicted and each sample image in the first training sample set into the initial model to obtain a first prediction probability that the image to be predicted belongs to each of the preset types, wherein the image to be predicted is any image in the second training sample set;
[0196] Based on the target preset type corresponding to the image to be predicted, determining a first actual probability that the image to be predicted belongs to each of the preset types, and determining a total training loss based on each of the first predicted probabilities and each of the first actual probabilities;
[0197] The initial model is iteratively trained based on the first training sample set and the second training sample set until the total training loss meets the training end condition, and the training is stopped, and the model at the time of stopping the training is determined as the classification model.
[0198] In some feasible implementations, the processor 1101 is configured to:
[0199] Determine a first initial image feature of the image to be predicted and a second initial image feature of each sample image in the first training sample set;
[0200] Determining an initial type feature corresponding to each of the preset types based on the second initial image features of each sample image corresponding to each of the preset types;
[0201] Determine the feature pair corresponding to each of the preset types of the image to be predicted, the feature pair corresponding to each of the preset types of the image to be predicted includes a target image feature after the first initial image feature is enhanced based on the first initial image feature and the initial type feature corresponding to the preset type, and a target type feature after the initial type feature corresponding to the preset type is enhanced;
[0202] Based on the feature pairs of the image to be predicted corresponding to each of the preset types, a first prediction probability that the image to be predicted belongs to each of the preset types is determined.
[0203] In some feasible implementation manners, for each of the preset types, the processor 1101 is configured to:
[0204] Determine a mutual correlation matrix corresponding to the initial type feature corresponding to the preset type and the first initial image feature;
[0205] Determining a first attention feature and a second attention feature based on the initial type feature corresponding to the preset type, the first initial image feature and the cross-correlation matrix;
[0206] Determining a target type feature corresponding to the preset type based on the initial type feature corresponding to the preset type and the first attention feature;
[0207] Based on the first initial image feature and the second attention feature, a target image feature of the image to be predicted is determined.
[0208] In some feasible implementation manners, for each of the preset types, the processor 1101 is configured to:
[0209] Determine a first mutual correlation submatrix of the initial type feature corresponding to the preset type compared to the first initial image feature;
[0210] Determine a second cross-correlation submatrix of the first initial image feature compared to the initial type feature of the preset type;
[0211] Based on the first mutual correlation submatrix, the second mutual correlation submatrix and the identity matrix, the initial type feature corresponding to the preset type and the mutual correlation matrix corresponding to the first initial image feature are determined.
[0212] In some feasible implementations, for each of the above-mentioned image sets in the above-mentioned second training sample set, the image set also includes a rotated image of each sample image in the image set corresponding to at least one preset rotation angle;
[0213] The processor 1101 is further configured to:
[0214] Determining, based on the feature pair of the image to be predicted corresponding to the target preset type, a second prediction probability of the image to be predicted corresponding to each of the preset rotation angles;
[0215] Determine a first training loss based on each of the first predicted probabilities and each of the first actual probabilities;
[0216] Based on the target rotation angle corresponding to the image to be predicted, determining a second actual probability that the image to be predicted belongs to each of the preset rotation angles;
[0217] Determining a second training loss based on each of the second predicted probabilities and each of the second actual probabilities;
[0218] Based on the first training loss and the second training loss, a total training loss is determined.
[0219] In some feasible implementations, the processor 1101 is configured to:
[0220] Determining a third prediction probability that the image to be predicted belongs to each of the preset types based on the feature pairs corresponding to the target preset types of the image to be predicted;
[0221] Determining a third training loss based on each of the third predicted probabilities and each of the first actual probabilities;
[0222] Based on the first training loss, the second training loss, and the third training loss, a total training loss is determined.
[0223] In some feasible implementations, the processor 1101 is configured to:
[0224] determining a target image of a target object;
[0225] Input the target image into the classification model to obtain a prediction result corresponding to the target object;
[0226] The type of the target object is determined based on the prediction result.
[0227] It should be understood that in some feasible implementations, the processor 1101 may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The memory may include a read-only memory and a random access memory, and provide instructions and data to the processor. A portion of the memory may also include a non-volatile random access memory. For example, the memory may also store information about the type of device.
[0228] In a specific implementation, the electronic device 1100 can execute the above-mentioned functions through its built-in functional modules. Figure 2 For the implementation methods provided in each step, please refer to the implementation methods provided in the above steps for details, which will not be repeated here.
[0229] The present application also provides a computer-readable storage medium, which stores a computer program and is executed by a processor to implement Figure 2 For the methods provided in each step, please refer to the implementation methods provided in the above steps for details, which will not be repeated here.
[0230] The computer-readable storage medium may be an internal storage unit of the device or electronic device provided in any of the aforementioned embodiments, such as a hard disk or memory of an electronic device. The computer-readable storage medium may also be an external storage device of the electronic device, such as a plug-in hard disk, a smart memory card (smart media card, SMC), a secure digital (secure digital, SD) card, a flash card (flash card), etc. equipped on the electronic device. The computer-readable storage medium may also include a disk, an optical disk, a read-only memory (read-only memory, ROM) or a random access memory (random access memory, RAM), etc. Further, the computer-readable storage medium may also include both an internal storage unit of the electronic device and an external storage device. The computer-readable storage medium is used to store the computer program and other programs and data required by the electronic device. The computer-readable storage medium may also be used to temporarily store data that has been output or is to be output.
[0231] The present invention provides a computer program product, which includes a computer program. The computer program is executed by a processor. Figure 2 The methods provided in each step.
[0232] The terms "first", "second", etc. in the claims, specification and drawings of the present application are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or electronic device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or electronic devices. Mentioning "embodiment" in this article means that the specific features, structures or characteristics described in conjunction with the embodiment may be included in at least one embodiment of the present application. Displaying the phrase at various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments. The term "and / or" used in the present application specification and the attached claims refers to any combination of one or more of the items listed in association and all possible combinations, and includes these combinations.
[0233] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Professional and technical personnel may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0234] The above disclosure is only the preferred embodiment of the present application, which cannot be used to limit the scope of rights of the present application. Therefore, equivalent changes made according to the claims of the present application are still within the scope covered by the present application.
Claims
1. A classification model training method, characterized in that: The method comprises: Acquire a first training sample set and a second training sample set, wherein the first training sample set and the second training sample set include a plurality of image sets, and each of the image sets includes at least one sample image of a preset type; Inputting an image to be predicted and each sample image in the first training sample set into an initial model to obtain a first prediction probability that the image to be predicted belongs to each of the preset types, wherein the image to be predicted is any image in the second training sample set; Based on the target preset type corresponding to the image to be predicted, determining a first actual probability that the image to be predicted belongs to each of the preset types, and determining a total training loss based on each of the first predicted probabilities and each of the first actual probabilities; Iteratively training the initial model based on the first training sample set and the second training sample set until the total training loss meets the training end condition, and the model at the time of stopping the training is determined as the classification model; The first prediction probability that the image to be predicted belongs to each of the preset types is determined based on the following method: Determining a first initial image feature of the image to be predicted and a second initial image feature of each sample image in the first training sample set; Determining an initial type feature corresponding to each of the preset types based on the second initial image features of each sample image corresponding to each of the preset types; Determine a feature pair corresponding to each of the preset types for the image to be predicted, wherein the feature pair corresponding to each of the preset types for the image to be predicted includes a target image feature after the first initial image feature is enhanced based on the first initial image feature and the initial type feature corresponding to the preset type, and a target type feature after the initial type feature corresponding to the preset type is enhanced; Based on the feature pairs of the to-be-predicted image corresponding to each of the preset types, a first prediction probability that the to-be-predicted image belongs to each of the preset types is determined.
2. The method according to claim 1, characterized in that For each of the preset types, determining a feature pair of the image to be predicted corresponding to the preset type includes: Determine a mutual correlation matrix corresponding to the initial type feature corresponding to the preset type and the first initial image feature; Determining a first attention feature and a second attention feature based on an initial type feature corresponding to the preset type, the first initial image feature and the cross-correlation matrix; Determining a target type feature corresponding to the preset type based on the initial type feature corresponding to the preset type and the first attention feature; Based on the first initial image feature and the second attention feature, a target image feature of the image to be predicted is determined.
3. The method according to claim 2, characterized in that For each of the preset types, determining the mutual correlation matrix corresponding to the initial type feature corresponding to the preset type and the first initial image feature includes: Determine a first mutual correlation submatrix of the initial type feature corresponding to the preset type compared to the first initial image feature; Determining a second cross-correlation submatrix of the first initial image feature compared to the initial type feature of the preset type; Based on the first mutual correlation submatrix, the second mutual correlation submatrix and the identity matrix, a mutual correlation matrix corresponding to the initial type feature corresponding to the preset type and the first initial image feature is determined.
4. The method according to claim 1, characterized in that: For each of the image sets in the second training sample set, the image set also includes a rotated image of each sample image in the image set corresponding to at least one preset rotation angle; the method further includes: Determining, based on the feature pair of the to-be-predicted image corresponding to the target preset type, a second prediction probability of the to-be-predicted image corresponding to each of the preset rotation angles; The determining a total training loss based on each of the first predicted probabilities and each of the first actual probabilities comprises: determining a first training loss based on each of the first predicted probabilities and each of the first actual probabilities; Determining, based on the target rotation angle corresponding to the image to be predicted, a second actual probability that the image to be predicted belongs to each of the preset rotation angles; determining a second training loss based on each of the second predicted probabilities and each of the second actual probabilities; A total training loss is determined based on the first training loss and the second training loss.
5. The method according to claim 4, characterized in that The method further comprises: Determining, based on the feature pairs of the to-be-predicted image corresponding to the target preset type, a third prediction probability that the to-be-predicted image belongs to each of the preset types; The determining a total training loss based on the first training loss and the second training loss comprises: Determining a third training loss based on each of the third predicted probabilities and each of the first actual probabilities; A total training loss is determined based on the first training loss, the second training loss, and the third training loss.
6. The method according to claim 1, characterized in that The method further comprises: determining a target image of a target object; Inputting the target image into the classification model to obtain a prediction result corresponding to the target object; The type of the target object is determined based on the prediction result.
7. A classification model training device, characterized in that: The device comprises: A sample acquisition module, used to acquire a first training sample set and a second training sample set, wherein the first training sample set and the second training sample set include a plurality of image sets, each of the image sets includes at least one sample image of a preset type; a sample processing module, configured to input an image to be predicted and each sample image in the first training sample set into an initial model to obtain a first prediction probability that the image to be predicted belongs to each of the preset types, wherein the image to be predicted is any image in the second training sample set; A data processing module, configured to determine, based on the target preset type corresponding to the image to be predicted, a first actual probability that the image to be predicted belongs to each of the preset types, and determine a total training loss based on each of the first predicted probabilities and each of the first actual probabilities; A model training module, configured to iteratively train the initial model based on the first training sample set and the second training sample set until the total training loss meets the training end condition, and to stop the training, and determine the model at the time of stopping the training as a classification model; The first prediction probability that the image to be predicted belongs to each of the preset types is determined by the sample processing module based on the following method: Determining a first initial image feature of the image to be predicted and a second initial image feature of each sample image in the first training sample set; Determining an initial type feature corresponding to each of the preset types based on the second initial image features of each sample image corresponding to each of the preset types; Determine a feature pair corresponding to each of the preset types for the image to be predicted, wherein the feature pair corresponding to each of the preset types for the image to be predicted includes a target image feature after the first initial image feature is enhanced based on the first initial image feature and the initial type feature corresponding to the preset type, and a target type feature after the initial type feature corresponding to the preset type is enhanced; Based on the feature pairs of the to-be-predicted image corresponding to each of the preset types, a first prediction probability that the to-be-predicted image belongs to each of the preset types is determined.
8. An electronic device, characterized in that: comprising a processor and a memory, wherein the processor and the memory are connected to each other; The memory is used to store computer programs; The processor is configured to execute the method according to any one of claims 1 to 6 when calling the computer program.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program is executed by a processor to implement the method according to any one of claims 1 to 6.
10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
