Model training methods, systems, equipment and media
Patent Information
- Application Number
- CN202111328644.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-10
- Publication Date
- 2025-01-28
- Estimated Expiration
- 2041-11-10
Smart Images

Figure CN114022713B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to a model training method, system, device and medium. Background Art
[0002] In recent years, the safety regulations of electric motorcycles and bicycles have received more and more attention, and relevant departments require that electric motorcycles must wear helmets. However, in daily traffic, some people have weak safety awareness and do not wear helmets when traveling, which is likely to lead to tragedy, and it takes a lot of manpower to correct this violation.
[0003] With the development of science and technology, artificial intelligence technology has been effectively promoted in the field of intelligent transportation. Deep learning has achieved remarkable results in the fields of image classification and image detection. Although it is currently possible to complete the recognition of helmet wearing through convolutional neural networks, they cannot have flexible decision-making capabilities when using existing data sets to learn and train deep models.
[0004] Since most images are in high dimensions and are non-rigid, there are many changes. Since the lighting, image acquisition angle, distance, etc. will affect the image of the same object, there is uncertainty in the image, which will reduce the accuracy of the machine recognition process and lead to poor robustness of the model. For example, when the scene is blurred and the color of the helmet is similar to the background, it is easy to make recognition errors and poor recognition accuracy. The training of existing related recognition models often focuses on the training of deterministic targets, and the recognition model has poor recognition accuracy for uncertain images. Summary of the invention
[0005] In view of the above-mentioned shortcomings of the prior art, the present invention provides a model training method, system, device and medium to solve the above-mentioned technical problems.
[0006] The present invention provides a model training method, comprising:
[0007] Obtain the image to be identified, perform feature extraction and feature dimensionality reduction, and obtain several dimensionality reduction features;
[0008] Presetting a preset classification and uncertainty discrimination network, the preset classification and uncertainty discrimination network includes a first network and a second network, inputting the dimension reduction features into the first network and the second network respectively for uncertainty discrimination processing, and obtaining respective prediction probability vectors respectively, the prediction probability vectors are generated according to the prediction category probability value;
[0009] Determining an uncertainty-based cross entropy loss function based on the predicted probability vectors of the first network and the second network;
[0010] The basic model is trained by the image to be identified and the uncertainty-based cross entropy loss function to obtain the target model, wherein the basic model includes a linear classification layer, and the linear classification layer is determined according to the weight matrix of each preset classification and uncertainty discrimination network.
[0011] Optionally, inputting the dimension reduction features into the first network and the second network respectively for uncertainty discrimination processing includes at least one of the following:
[0012] Selecting a plurality of first features from the reduced-dimensional features and inputting them into a first network for uncertainty discrimination processing, selecting a plurality of second features from the reduced-dimensional features and inputting them into a second network for uncertainty discrimination processing, at least one of the first features is different from the second feature;
[0013] The first network selects a plurality of first features from the reduced-dimensional features for uncertainty discrimination processing, and the second network selects a plurality of second features from the reduced-dimensional features for uncertainty discrimination processing, and at least one of the first features is different from the second feature;
[0014] Selecting a plurality of first features from the reduced-dimensional features and inputting them into a first network for uncertainty discrimination processing, selecting a plurality of second features from the reduced-dimensional features and inputting them into a second network for uncertainty discrimination processing, wherein each of the first features is the same as the second feature;
[0015] The first network selects a plurality of first features from the reduced-dimensional features for uncertainty discrimination processing, and the second network selects a plurality of second features from the reduced-dimensional features for uncertainty discrimination processing, and each of the first features is the same as the second feature.
[0016] Optionally, the basic model is constructed in the following manner:
[0017] Obtaining the weight matrix of each of the preset classification and uncertainty discrimination networks;
[0018] Determine a target matrix according to each of the weight matrices and generate a linear classification layer;
[0019] The basic model is generated according to the linear classification layer, the preset feature extraction network and the preset feature dimension reduction network.
[0020] Optionally, training a basic model using the image to be recognized and an uncertainty-based cross entropy loss function includes:
[0021] Acquire the real category of the image to be identified, and perform category prediction on the image to be identified based on the basic model to obtain a predicted category;
[0022] The predicted category and the true category are converged according to the uncertainty-based cross entropy loss function to obtain the target model.
[0023] Optionally, the uncertainty-based cross entropy loss function includes:
[0024]
[0025] Among them, L ce is the cross entropy loss function based on uncertainty, y is the label of the category to which the image to be identified belongs, and p0 y is the value of the predicted probability vector p0 at the position indicated by label y, p1 y is the value of the predicted probability vector p1 at the position indicated by the label y, p0 is the predicted category probability value output by a preset classification and uncertainty discrimination network, and p1 is the predicted category probability value output by another preset classification and uncertainty discrimination network.
[0026] Optionally, the method further includes determining uncertainty according to the prediction probability vectors of the first network and the second network, and the uncertainty is determined in a manner including:
[0027]
[0028] Among them, A is the uncertainty, p0 y is the value of the predicted probability vector p0 at the position indicated by label y, p1 y is the value of the predicted probability vector p1 at the position indicated by the label y, p0 is the predicted category probability value output by a preset classification and uncertainty discrimination network, and p1 is the predicted category probability value output by another preset classification and uncertainty discrimination network.
[0029] Optionally, the image to be identified is a head image of a target person, and the predicted category includes wearing a safety helmet or not wearing a safety helmet.
[0030] Optionally, the method further includes:
[0031] Acquire a target image, wherein the target image includes a head image of a person to be identified;
[0032] The target image is input into the target model to obtain a recognition result, wherein the recognition result includes whether a safety helmet is worn or not worn.
[0033] The present invention also provides a model training system, comprising:
[0034] The image acquisition module is used to acquire the image to be identified, and perform feature extraction and feature dimension reduction to obtain a number of dimension reduction features;
[0035] A vector acquisition module, used to pre-set a preset classification and uncertainty discrimination network, wherein the preset classification and uncertainty discrimination network includes a first network and a second network, and the dimension reduction features are respectively input into the first network and the second network for uncertainty discrimination processing, and respective prediction probability vectors are obtained, wherein the prediction probability vectors are generated according to the prediction category probability value;
[0036] A determination module, configured to determine an uncertainty-based cross entropy loss function according to the predicted probability vectors of the first network and the second network;
[0037] A training module is used to train a basic model through the image to be identified and an uncertainty-based cross entropy loss function to obtain a target model, wherein the basic model includes a linear classification layer, and the linear classification layer is determined according to the weight matrix of each of the preset classifications and the uncertainty discrimination network.
[0038] The present invention also provides an electronic device, comprising a processor, a memory and a communication bus;
[0039] The communication bus is used to connect the processor and the memory;
[0040] The processor is used to execute the computer program stored in the memory to implement the method described in any one of the above embodiments.
[0041] The present invention also provides a computer-readable storage medium having a computer program stored thereon.
[0042] The computer program is used to enable the computer to execute the method described in any one of the above embodiments.
[0043] Beneficial effects of the present invention: The present invention proposes a model training method, system, device and medium, which obtains an image to be identified, performs feature extraction and dimensionality reduction, obtains reduced dimensionality features, inputs the reduced dimensionality features into a first network and a second network respectively, obtains two prediction probability vectors, and determines a cross entropy loss function based on uncertainty. A basic model is trained using the image to be identified and the cross entropy loss function based on uncertainty to obtain a target model. By adding the idea of uncertainty judgment to a classification neural network, the learning ability of the network is improved, the classification accuracy of the network is enhanced, and the recognition accuracy of the trained target model for uncertain images is greatly improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 This is a flow chart of the model training method provided in the first embodiment of the present invention;
[0045] Figure 2 It is a specific flow chart of the model training method provided in the first embodiment of the present invention;
[0046] Figure 3 It is a network flow diagram applicable to the model training method provided in the first embodiment of the present invention;
[0047] Figure 4 is a structural diagram of a model training system provided in Embodiment 2 of the present invention;
[0048] Figure 5 It is a structural schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0049] The following describes the embodiments of the present invention by specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict.
[0050] It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present invention, and thus the drawings only show components related to the present invention rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.
[0051] In the following description, numerous details are discussed to provide a more thorough explanation of the embodiments of the present invention. However, it is obvious to those skilled in the art that the embodiments of the present invention can be implemented without these specific details. In other embodiments, well-known structures and devices are shown in the form of block diagrams rather than in detail to avoid making the embodiments of the present invention difficult to understand.
[0052] Embodiment 1
[0053] like Figure 1 As shown, this embodiment provides a model training method, which includes:
[0054] Step S101: Obtain an image to be identified, perform feature extraction and feature dimensionality reduction, and obtain a number of dimensionality reduction features.
[0055] The image to be identified may include one or more images, and the image to be identified is classified into the first category or the second category. In other words, the target model only includes two possible recognition results for the image to be identified.
[0056] The method of performing feature extraction and feature dimension reduction on the image to be identified can be implemented in a manner known to those skilled in the art.
[0057] The images to be identified are pre-labeled with real categories.
[0058] In one embodiment, the image to be identified is a head image of a target person, and the predicted category is wearing a helmet or not wearing a helmet.
[0059] In one embodiment, the image to be identified may be other images, and the categories of the image may be two or more.
[0060] In one embodiment, feature extraction of the image to be identified may be achieved through a preset feature extraction network of the basic model, and the preset feature extraction network may be a network known to those skilled in the art, such as VGG16, ResNet-18, etc.
[0061] In one embodiment, the feature dimension reduction of the features extracted by the preset feature extraction network can be realized by the preset feature dimension reduction network of the basic model, and the preset feature dimension reduction network includes one or more convolution layers followed by a pooling layer and a BN layer. The convolution layer only changes the dimension of the feature, and does not change the length and width of the feature. The pooling layer changes the length and width of the feature to m*m size, and the BN (Batch Normalization) layer performs BatchNormalization processing on the feature, so that the network is easier to optimize and converge. Among them, the pooling layer can be a global average pooling layer, and the value of m can be 1 or other values.
[0062] Step S102: pre-set a preset classification and uncertainty discrimination network, the preset classification and uncertainty discrimination network includes a first network and a second network, input the dimensionality reduction features into the first network and the second network respectively for uncertainty discrimination processing, and obtain respective prediction probability vectors respectively.
[0063] The prediction probability vector is generated according to the prediction category probability value output by the first network or the second network. A person skilled in the art can determine the prediction category based on the prediction category probability value. The prediction probability vector can be generated according to the probability values corresponding to various prediction types output by the preset classification and uncertainty discrimination network.
[0064] The preset classification and uncertainty discrimination network may be a network known to those skilled in the art, and the two preset classification and uncertainty discrimination networks may be the same network.
[0065] The preset classification and uncertainty judgment network consists of two parallel classification modules, each of which contains a dropout layer and a linear classification layer. The two classification modules are mainly used to implement classification based on uncertainty thinking.
[0066] In one embodiment, inputting the dimension reduction features into the first network and the second network respectively for uncertainty discrimination processing includes at least one of the following:
[0067] Selecting a plurality of first features from the reduced-dimensional features and inputting them into the first network for uncertainty discrimination processing, selecting a plurality of second features from the reduced-dimensional features and inputting them into the second network for uncertainty discrimination processing, at least one of the first features is different from the second feature;
[0068] The first network selects a plurality of first features from the reduced-dimensional features for uncertainty discrimination processing, and the second network selects a plurality of second features from the reduced-dimensional features for uncertainty discrimination processing, and at least one first feature is different from the second feature;
[0069] Selecting multiple first features from the reduced-dimensional features and inputting them into the first network for uncertainty discrimination processing, selecting multiple second features from the reduced-dimensional features and inputting them into the second network for uncertainty discrimination processing, wherein each first feature is the same as the second feature;
[0070] The first network selects a plurality of first features from the dimensionality reduction features for uncertainty discrimination processing, and the second network selects a plurality of second features from the dimensionality reduction features for uncertainty discrimination processing, and each first feature is the same as the second feature.
[0071] In a common case, the first network and the second network can obtain the same two sets of dimensionality reduction features, and select a part of the dimensionality reduction features from the dimensionality reduction feature sets for uncertainty discrimination processing. In this way, the dimensionality reduction features input into the linear classification layer of each preset classification and uncertainty discrimination network are not exactly the same. Therefore, inputting each dimensionality reduction feature into a preset classification and uncertainty discrimination network can be regarded as two different judgments on the same sample, and the output results obtained are not necessarily the same.
[0072] Of course, there is also a small probability that the first network and the second network can obtain the same two dimensionality reduction feature sets, and select the same multiple dimensionality reduction features from the dimensionality reduction feature sets for uncertainty discrimination processing. The dimensionality reduction features input into the linear classification layer of each preset classification and uncertainty discrimination network are also exactly the same. Therefore, inputting each dimensionality reduction feature into a preset classification and uncertainty discrimination network can be regarded as two different judgments on the same sample, and the output results may be the same or different.
[0073] Optionally, the dimension reduction features input to the first network and the second network may be the same or different.
[0074] The predicted probability vector output by the first network may be the same as or different from the predicted probability vector output by the second network. Due to the existence of the dropout layer, the dimension reduction features input to the linear classification layer of the two preset classification and uncertainty discrimination networks are not exactly the same, so inputting each dimension reduction feature into the two preset classification and uncertainty discrimination networks can be considered as two different judgments on the same sample. According to the image category label of the image to be identified, the predicted category probability values of the image to be identified under different categories output by each preset classification and uncertainty discrimination network can be obtained, and then the predicted probability vector is generated.
[0075] Step S103: Determine an uncertainty-based cross entropy loss function according to the predicted probability vectors of the first network and the second network.
[0076] In one embodiment, the method further includes determining an uncertainty degree according to the prediction probability vectors of the first network and the second network, and the uncertainty degree A is determined in a manner including:
[0077]
[0078] Among them, A is the uncertainty, p0 y is the value of the predicted probability vector p0 at the position indicated by label y, p1 y is the value of the predicted probability vector p1 at the position indicated by the label y, p0 is the predicted category probability value output by a preset classification and uncertainty discrimination network, and p1 is the predicted category probability value output by another preset classification and uncertainty discrimination network.
[0079] In one embodiment, the image to be identified includes multiple pictures. By combining the uncertainty with the uncertainty-based cross entropy loss function, the picture with higher uncertainty has a larger loss value. In this way, when the picture is used for model training in the future, there will be a greater training intensity. Correspondingly, the picture with lower uncertainty has a smaller corresponding loss value than the former. When the picture is used for model training in the future, there will be a smaller training intensity than the former. Through such an adaptive training method, the effect of model training can be effectively improved.
[0080] When the prediction probabilities for the same target output by two preset classification and uncertainty discrimination networks are very different, it means that the image including the target has a large uncertainty. Therefore, an uncertainty degree can be determined based on the prediction probability vector output by the two preset classification and uncertainty discrimination networks to evaluate the uncertainty of the image, and then the next step of processing can be carried out in a targeted manner. Since the uncertainty-based cross entropy loss function is proportional to the uncertainty degree, the greater the uncertainty degree of the sample (image to be identified), the greater the subsequent training intensity, which can effectively improve the credibility of the target model obtained by training.
[0081] Optionally, the uncertainty can also be determined by the relative error (B) between two predicted probability vectors. For example:
[0082]
[0083] If the relative error of the predicted probability vector of at least one category is greater than the preset relative error threshold, it means that the uncertainty is high.
[0084] Of course, the uncertainty may be determined in other ways known to those skilled in the art.
[0085] Step S104: training the basic model through the image to be recognized and the uncertainty-based cross entropy loss function to obtain the target model.
[0086] The basic model includes a linear classification layer, which is determined according to the weight matrix of each preset classification and uncertainty discrimination network. The preset uncertainty threshold can be set by those skilled in the art as needed.
[0087] When the uncertainty is higher than the preset uncertainty threshold, it means that the image is difficult to recognize and the relevant model needs to be trained to improve the recognition accuracy of the model.
[0088] In one embodiment, the basic model is constructed by:
[0089] Obtain the weight matrix of each preset classification and uncertainty discrimination network;
[0090] Determine the target matrix based on each weight matrix and generate a linear classification layer;
[0091] Generate a basic model based on the linear classification layer, the preset feature extraction network and the preset feature dimension reduction network.
[0092] Optionally, determining a target matrix according to each weight matrix includes:
[0093] The mean of each weight is averaged to obtain the target matrix.
[0094] Among them, since the preset classification and uncertainty discrimination networks are the same in the initial state, the arrangement of the corresponding weight matrices is also consistent. The weight values of the corresponding positions are averaged, and the target matrix is composed of the average values of each position.
[0095] When calculating the category to which each sample feature (feature of the image to be identified) belongs, the sample feature is multiplied by each column vector of the classification layer weight matrix (target matrix). The index number where the maximum value of the result is located is the category of the sample feature. Therefore, each column of the trained classification layer weight matrix (target matrix) can be regarded as a matching template for a category in the data set. In order to effectively utilize the trained weight matrices of the two classifiers (preset classification and uncertainty discrimination network), during testing, the weight matrices of the two classifiers (preset classification and uncertainty discrimination network) can be averaged so that the network can obtain a unique category prediction value. In this way, a strong classifier can be formed through weak classifiers to enhance recognition accuracy.
[0096] In other words, since the loss function of the above basic model is a cross entropy loss function based on uncertainty, the classification uncertain images can be focused on learning by increasing their weight in the loss calculation.
[0097] In one embodiment, training a basic model using an image to be recognized includes:
[0098] Obtain the true category of the image to be identified, and predict the category of the image to be identified based on the basic model to obtain the predicted category;
[0099] The predicted categories and true categories are converged according to the uncertainty-based cross entropy loss function to obtain the target model.
[0100] The actual category may be a pre-labeled category.
[0101] In one embodiment, the uncertainty-based cross entropy loss function L ce include:
[0102]
[0103] Among them, L ce is the cross entropy loss function based on uncertainty, y is the label of the category to which the image to be identified belongs, and p0 y is the value of the predicted probability vector p0 at the position indicated by label y, p1 y is the value of the predicted probability vector p1 at the position indicated by the label y, p0 is the predicted category probability value output by a preset classification and uncertainty discrimination network, and p1 is the predicted category probability value output by another preset classification and uncertainty discrimination network.
[0104] Where y∈[0,n-1], n is the number of categories. In the above formula, taking two categories as an example, when the values of the two predicted probability vectors at the positions indicated by the category labels are close, that is, p0 y ≈p1 y , At this time, the uncertainty-based cross entropy loss function can be determined by the above-mentioned method or by other methods known to those skilled in the art. and When the difference is large, A value greater than 1 will be obtained. At this time, it can be known that the image to be identified is an uncertain image and the basic model needs to be focused on learning.
[0105] In one embodiment, the method further comprises:
[0106] Acquire a target image, where the target image includes a head image of a person to be identified;
[0107] The target image is input into the target model to obtain a recognition result, which includes whether the helmet is worn or not.
[0108] The model training method provided in this embodiment obtains an image to be identified, performs feature extraction and dimensionality reduction, obtains reduced-dimensionality features, inputs the reduced-dimensionality features into the first network and the second network respectively, obtains two prediction probability vectors, and determines a cross-entropy loss function based on uncertainty. The basic model is trained by the image to be identified and the cross-entropy loss function based on uncertainty to obtain a target model. By adding the idea of uncertainty judgment to the classification neural network, the learning ability of the network is improved and the classification accuracy of the network is enhanced.
[0109] The model training method provided above is exemplarily described below through a specific embodiment. Figure 2 , the method comprising:
[0110] Step S201: input the image to be identified into a preset feature extraction network to extract a feature map of the image to be identified.
[0111] Step S202: Input the feature map into a preset feature dimensionality reduction network for feature dimensionality reduction and perform global average pooling and BN processing on the reduced features.
[0112] Step S203: Input the features processed in step S202 into two classifiers of the uncertainty judgment network respectively.
[0113] Due to the existence of the dropout layer, the features input to the two linear classification layers are not exactly the same, which can be considered as two different judgments of the same sample. According to the image category label, the predicted category probability value of the category to which the image output by the two linear classification layers belongs is obtained. When the two predicted category probability values differ greatly, it is considered to be an uncertain sample, and its weight in the loss calculation is increased.
[0114] Step S204: Determine the target matrix according to the weight matrices of the two classifiers, and generate a linear classification layer.
[0115] When calculating the category to which the sample feature in each image to be identified belongs, the sample feature is multiplied by each column vector of the classification layer weight matrix. The index number where the maximum value of the result is located is the category of the sample. Therefore, each column of the trained classification layer weight matrix can be regarded as a matching template for a category in the data set. In order to effectively utilize the trained weights of the two classifiers, the weights of the two classifiers are averaged during testing, so that the network obtains a unique category prediction value. A strong classifier can be formed by multiple weak classifiers, thereby improving the recognition accuracy of the model.
[0116] The method provided in the above embodiment uses two classifiers to introduce uncertainty into the classification network. Through uncertainty judgment, a loss function is designed to enable the network to be trained more targeted. In order to effectively utilize the two trained classifiers, when the model is tested, the weights of the two classifiers are averaged and fused. By adding the uncertainty judgment idea to the classification neural network, the learning ability of the network is improved and the classification accuracy of the network is enhanced.
[0117] The model training method provided above is exemplarily described below through another specific embodiment, and its overall network flow chart is as follows: Figure 3 As shown in the figure, ResNet-18 is used as the feature extraction network; the feature dimension reduction network is simply represented by a convolution layer plus a global average pooling layer and a BN layer. The specific steps are as follows:
[0118] Step 1: Assume that the size of the input image to be recognized is 256*256*3, and the preset feature extraction network is ResNet-18. Remove the last pooling layer and classification layer of the original ResNet-18 to obtain the output high-dimensional features with a dimension of 8*8*2048.
[0119] Step 2: In the convolution layer of the dimensionality reduction network, the convolution kernel size is 3*3, the padding is 1, the step size is 1, the input feature is 2048, and the output feature is 512; the pooling layer uses the global average pooling method. Therefore, after the high-dimensional features pass through the dimensionality reduction network, a low-dimensional feature of 512 dimensions is obtained.
[0120] Step 3: Input the obtained reduced-dimensional features into two identical preset classification and uncertainty judgment networks respectively. Assuming that there are n categories in the data set, the dimension of the weight matrix of the linear classification layer in the network is 512*n. The low-dimensional features obtained in step 2 can be passed through the network to obtain an n-dimensional vector. The vector is softmax normalized to obtain the probability value of the input image belonging to each category. In theory, when the linear classification layers are initialized the same, the two predicted probability vectors should be the same. However, due to the existence of the Dropout layer, during the training process, although the low-dimensional features input into the two classification and uncertainty judgment networks are the same, the features input into the two linear classification layers are different. This allows the network to judge the same thing twice from different angles, just like the human brain.
[0121] Step 4: Calculate the loss function using the two predicted probability vectors p0 and p1 obtained in step 3. The uncertainty-based cross entropy loss function is:
[0122]
[0123] Among them, L ce is the cross entropy loss function based on uncertainty, y is the label of the category to which the image to be identified belongs, and p0 y is the value of the predicted probability vector p0 at the position indicated by label y, p1 y is the value of the predicted probability vector p1 at the position indicated by the label y, p0 is the predicted category probability value output by a preset classification and uncertainty discrimination network, and p1 is the predicted category probability value output by another preset classification and uncertainty discrimination network. y∈[0,n-1], n is the number of categories. In the above formula, taking two categories as an example, when the values of the two predicted probability vectors at the position indicated by the category label are close, that is, p0 y ≈p1 y , At this time, the uncertainty-based cross entropy loss function can be determined by the above-mentioned method or by other methods known to those skilled in the art. and When the difference is large, A value greater than 1 will be obtained. At this time, it can be known that the image to be identified is an uncertain image and the basic model needs to be focused on learning.
[0124] Step 5: Since the network has two classifiers (preset classification and uncertainty discrimination network), two classification results will be obtained during testing, which is not required for actual use and will interfere with the user's judgment. Generally, only the result of one classifier is used. However, it is difficult to judge which one to abandon. Extract the 512*n weight matrix of the two classifiers, and then calculate the average of the two weight matrices and assign them to a new linear layer as the linear classification layer for the final test to obtain the final classification result.
[0125] Through the above method, we can first determine whether the image to be identified is an uncertain sample (whether the uncertainty is higher than the preset uncertainty threshold), and then focus on learning the uncertain sample, so as to avoid recognition errors due to interference (scene blur, target color is close to background color, etc.), and effectively improve the accuracy of model recognition.
[0126] Embodiment 2
[0127] See also Figure 4 , this embodiment provides a model training system 400, including:
[0128] The image acquisition module 401 is used to acquire the image to be identified, and perform feature extraction and feature dimension reduction to obtain a plurality of dimension reduction features;
[0129] A vector acquisition module 402 is used to pre-set a preset classification and uncertainty discrimination network, wherein the preset classification and uncertainty discrimination network includes a first network and a second network, and the dimension reduction features are respectively input into the first network and the second network for uncertainty discrimination processing, and respective prediction probability vectors are obtained, wherein the prediction probability vectors are generated according to the prediction category probability value;
[0130] A determination module 403 is used to determine an uncertainty-based cross entropy loss function according to the prediction probability vectors of the first network and the second network;
[0131] The training module 404 is used to train the basic model through the image to be recognized and determine the uncertainty-based cross entropy loss function to obtain the target model. The basic model includes a linear classification layer, and the linear classification layer is determined according to the weight matrix of each preset classification and uncertainty discrimination network.
[0132] In one embodiment, the system further comprises a model building module, the model building module comprising:
[0133] A weight acquisition module is used to obtain the weight matrix of each preset classification and uncertainty discrimination network;
[0134] A target matrix generation module is used to determine the target matrix according to each weight matrix and generate a linear classification layer;
[0135] The basic model generation module is used to generate a basic model according to a linear classification layer, a preset feature extraction network and a preset feature dimension reduction network.
[0136] Optional training modules include:
[0137] The category acquisition module is used to obtain the real category of the image to be identified, and to predict the category of the image to be identified based on the basic model to obtain the predicted category;
[0138] The result convergence module is used to converge the predicted categories and the true categories according to the uncertainty-based cross entropy loss function to obtain the target model.
[0139] Optionally, the image to be identified is a head image of the target person, and the predicted categories include wearing a safety helmet or not wearing a safety helmet.
[0140] Optionally, the system further includes an identification module, which includes:
[0141] A target image acquisition module is used to acquire a target image, wherein the target image includes a head image of a person to be identified;
[0142] The recognition result output module is used to input the target image into the target model to obtain the recognition result, and the recognition result includes wearing a safety helmet or not wearing a safety helmet.
[0143] In this embodiment, the model training system is essentially configured with multiple modules to execute the methods in the above embodiments. The specific functions and technical effects can be referred to in the above embodiment 1, which will not be repeated here.
[0144] See also Figure 5 , an embodiment of the present invention further provides an electronic device 600, including a processor 601, a memory 602 and a communication bus 603;
[0145] The communication bus 603 is used to connect the processor 601 and the memory 602;
[0146] The processor 601 is used to execute the computer program stored in the memory 602 to implement one or more methods described in the above-mentioned embodiment 1.
[0147] The embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon.
[0148] The computer program is used to enable a computer to execute any of the methods described in the first embodiment.
[0149] The embodiment of the present application also provides a non-volatile readable storage medium, which stores one or more modules (programs). When the one or more modules are applied to a device, the device can execute instructions (instructions) of the steps included in the embodiment 1 of the embodiment of the present application.
[0150] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0151] The computer-readable medium may be included in the electronic device, or may exist independently without being installed in the electronic device.
[0152] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages, or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through 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., through the Internet using an Internet service provider).
[0153] The flow chart and block diagram in the accompanying drawings illustrate the possible implementation architecture, function and operation of the method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0154] The above embodiments are merely illustrative of the principles and effects of the present invention, and are not intended to limit the present invention. Anyone familiar with the art may modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by a person of ordinary skill in the art without departing from the spirit and technical concept disclosed by the present invention shall still be covered by the claims of the present invention.
Claims
1. A model training method, characterized in that: The method comprises: Obtain the image to be identified, perform feature extraction and feature dimensionality reduction, and obtain several dimensionality reduction features; Presetting a preset classification and uncertainty discrimination network, the preset classification and uncertainty discrimination network includes a first network and a second network, inputting the dimensionality reduction features into the first network and the second network respectively for uncertainty discrimination processing, and obtaining respective prediction probability vectors respectively, the prediction probability vectors are generated according to the prediction category probability value, the first network includes a first Dropout layer and a first Linear layer, and the second network includes a second Dropout layer and a second Linear layer; Determining an uncertainty-based cross entropy loss function based on the predicted probability vectors of the first network and the second network; The target model is obtained by training a basic model using the image to be identified and an uncertainty-based cross entropy loss function, wherein the basic model includes a linear classification layer, and the linear classification layer is determined according to a weight matrix of each of the preset classifications and the uncertainty discrimination network; Wherein, the uncertainty-based cross entropy loss function includes: Among them, L ce is the cross entropy loss function based on uncertainty, y is the label of the category to which the image to be identified belongs, and p0 y is the value of the predicted probability vector p0 at the position indicated by label y, p1 y is the value of the predicted probability vector p1 at the position indicated by the label y, p0 is the predicted category probability value output by the first network, and p1 is the predicted category probability value output by the second network.
2. The model training method according to claim 1, characterized in that: Inputting the dimension reduction features into the first network and the second network respectively for uncertainty discrimination processing comprises at least one of the following: Selecting a plurality of first features from the reduced-dimensional features and inputting them into a first network for uncertainty discrimination processing, selecting a plurality of second features from the reduced-dimensional features and inputting them into a second network for uncertainty discrimination processing, at least one of the first features is different from the second feature; The first network selects a plurality of first features from the reduced-dimensional features for uncertainty discrimination processing, and the second network selects a plurality of second features from the reduced-dimensional features for uncertainty discrimination processing, and at least one of the first features is different from the second feature; Selecting a plurality of first features from the reduced-dimensional features and inputting them into a first network for uncertainty discrimination processing, selecting a plurality of second features from the reduced-dimensional features and inputting them into a second network for uncertainty discrimination processing, wherein each of the first features is the same as the second feature; The first network selects a plurality of first features from the reduced-dimensional features for uncertainty discrimination processing, and the second network selects a plurality of second features from the reduced-dimensional features for uncertainty discrimination processing, and each of the first features is the same as the second feature.
3. The model training method according to claim 1, characterized in that: The basic model is constructed in the following ways: Obtaining the weight matrix of each of the preset classification and uncertainty discrimination networks; Determine a target matrix according to each of the weight matrices and generate a linear classification layer; The basic model is generated according to the linear classification layer, the preset feature extraction network and the preset feature dimension reduction network.
4. The model training method according to claim 1, characterized in that: Training the basic model using the image to be recognized and the uncertainty-based cross entropy loss function includes: Acquire the real category of the image to be identified, and perform category prediction on the image to be identified based on the basic model to obtain a predicted category; The predicted category and the true category are converged according to the uncertainty-based cross entropy loss function to obtain the target model.
5. The model training method according to any one of claims 1 to 4, characterized in that: The method further includes determining uncertainty based on the prediction probability vectors of the first network and the second network, wherein the uncertainty is determined in a manner including: Among them, A is the uncertainty, p0 y is the value of the predicted probability vector p0 at the position indicated by label y, p1 y is the value of the predicted probability vector p1 at the position indicated by the label y, p0 is the predicted category probability value output by a preset classification and uncertainty discrimination network, and p1 is the predicted category probability value output by another preset classification and uncertainty discrimination network.
6. The model training method according to any one of claims 1 to 4, characterized in that: The image to be identified is a head image of a target person, and the predicted category includes wearing a safety helmet or not wearing a safety helmet.
7. The model training method according to claim 6, characterized in that: The method further comprises: Acquire a target image, wherein the target image includes a head image of a person to be identified; The target image is input into the target model to obtain a recognition result, wherein the recognition result includes whether a safety helmet is worn or not worn.
8. A model training system, characterized in that: The system comprises: The image acquisition module is used to acquire the image to be identified, and perform feature extraction and feature dimension reduction to obtain a number of dimension reduction features; A vector acquisition module, used to pre-set a preset classification and uncertainty discrimination network, wherein the preset classification and uncertainty discrimination network includes a first network and a second network, and the dimension reduction features are respectively input into the first network and the second network for uncertainty discrimination processing, and respective prediction probability vectors are obtained, wherein the prediction probability vectors are generated according to the prediction category probability values, wherein the first network includes a first Dropout layer and a first Linear layer, and the second network includes a second Dropout layer and a second Linear layer; A determination module, configured to determine an uncertainty-based cross entropy loss function according to the predicted probability vectors of the first network and the second network; A training module, used to train a basic model through the image to be identified and an uncertainty-based cross entropy loss function to obtain a target model, wherein the basic model includes a linear classification layer, and the linear classification layer is determined according to a weight matrix of each of the preset classifications and the uncertainty discrimination network; Wherein, the uncertainty-based cross entropy loss function includes: Among them, L ce is the cross entropy loss function based on uncertainty, y is the label of the category to which the image to be identified belongs, and p0 y is the value of the predicted probability vector p0 at the position indicated by label y, p1 y is the value of the predicted probability vector p1 at the position indicated by the label y, p0 is the predicted category probability value output by the first network, and p1 is the predicted category probability value output by the second network.
9. An electronic device, characterized in that: including a processor, a memory and a communication bus; The communication bus is used to connect the processor and the memory; The processor is configured to execute the computer program stored in the memory to implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: A computer program is stored thereon, The computer program is used to make the computer execute the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Method for eliminating uncertainty of self-supervised three-dimensional reconstruction
CN113592913A
Methods for training auto-labeling device and performing auto-labeling by using hybrid classification and devices using the same
US10885387B1