Model training method, model training device, terminal equipment and storage medium
By performing data augmentation and multi-loss value optimization on the pedestrian re-identification model, the problem of insufficient recognition accuracy and generalization ability of the pedestrian re-identification model in complex scenes is solved, and the robustness and generalization ability of the model are improved, simplifying the training process.
Patent Information
- Application Number
- CN202210031145.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-12
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2042-01-12
AI Technical Summary
Existing pedestrian re-identification models have low recognition accuracy and poor generalization ability in complex shooting scenes, and traditional methods to improve model robustness and generalization ability are complex and difficult to apply.
By performing two different data augmentation operations on the sample images, images with different styles are generated, and the re-identification model is trained using the backbone network, average pooling layer and fully connected layer, and various loss values are calculated to optimize the model until The target loss function converges and improves the robustness and generalization ability of the model.
This method prompts the model to learn essential discriminative features in images of different styles, improves recognition accuracy and generalization capabilities, simplifies the model training process, and reduces application difficulty.
Smart Images

Figure CN114358205B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a model training method, a model training device, a terminal device, and a computer-readable storage medium. Background Art
[0002] Person re-identification (Re-ID) is an image retrieval technology that searches for specific pedestrians across devices. It aims to use computer vision technology to retrieve specific pedestrian images taken by non-overlapping cameras. In the model training task, due to the complexity of the shooting scene, pedestrian images are greatly affected by factors such as shooting angle, lighting, and posture, resulting in large differences in image styles in different scenes or even in different cameras in the same scene. In addition, in the same dataset, it is inevitable that there are problems such as high similarity between classes and small differences within classes, resulting in low recognition accuracy and poor generalization ability of the trained model.
[0003] At present, in order to improve the robustness and generalization ability of the model, most pedestrian re-identification algorithms are often based on designing complex network structures to improve the representation ability of the model. However, while this method improves the representation ability of the model, it also reduces the efficiency of the algorithm and increases the difficulty of application. Therefore, how to provide a simple and easy-to-apply model training method is an urgent problem to be solved. Summary of the invention
[0004] In view of this, an embodiment of the present application provides a model training method, a model training device, a terminal device and a computer-readable storage medium, which improves the robustness and generalization ability of the re-identification model by changing the model training method.
[0005] A first aspect of an embodiment of the present application provides a model training method, comprising:
[0006] For each sample image in the sample set, two different data augmentation operations are performed on the sample image to obtain a first image and a second image;
[0007] Based on the re-identification model to be trained, pedestrian re-identification is performed on the first image and the second image to obtain a re-identification prediction result, wherein the re-identification model includes a backbone network, an average pooling layer, and a fully connected layer;
[0008] Based on the re-identification prediction result, a first loss value, a second loss value and a third loss value of the re-identification model to be trained are calculated, wherein the first loss value is used to calculate the loss between the true probability and the predicted probability of the label to which the image belongs, the second loss value is used to calculate the loss between the true distinguishing feature and the extracted distinguishing feature of the image, and the third loss value is used to calculate the loss between the true label and the predicted label of the image;
[0009] The total loss value of the re-identification model to be trained is calculated based on the first loss value, the second loss value, the third loss value and the preset target loss function, and the re-identification model to be trained is optimized based on the total loss value until the target loss function converges to obtain a trained re-identification model.
[0010] A second aspect of an embodiment of the present application provides a model training device, comprising:
[0011] A data augmentation module, configured to perform two different data augmentation operations on each sample image in the sample set to obtain a first image and a second image;
[0012] A re-identification module, configured to perform pedestrian re-identification on the first image and the second image based on a re-identification model to be trained to obtain a re-identification prediction result, wherein the re-identification model includes a backbone network, an average pooling layer, and a fully connected layer;
[0013] a calculation module, configured to calculate a first loss value, a second loss value, and a third loss value of the re-identification model to be trained based on the re-identification prediction result, wherein the first loss value is used to describe the loss between the true probability and the predicted probability of the label to which the image belongs, the second loss value is used to describe the loss between the true distinguishing feature and the extracted distinguishing feature of the image, and the third loss value is used to describe the loss between the true label and the predicted label of the image;
[0014] The optimization module is used to calculate the total loss value of the re-identification model to be trained based on the first loss value, the second loss value, the third loss value and the preset target loss function, and optimize the re-identification model to be trained based on the total loss value until the target loss function converges to obtain a trained re-identification model.
[0015] A third aspect of an embodiment of the present application provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the terminal device, wherein the processor implements the steps of the model training method provided in the first aspect when executing the computer program.
[0016] The fourth aspect of an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, each step of the model training method provided in the first aspect is implemented.
[0017] The model training method, model training device, terminal device and computer-readable storage medium provided by the embodiments of the present application have the following beneficial effects:
[0018] By performing two different data augmentation operations on each sample image in the sample set, a first image and a second image can be obtained. Based on the re-identification model to be trained, pedestrian re-identification is performed on the first image and the second image respectively to obtain a re-identification prediction result, and the re-identification model includes a backbone network, an average pooling layer and a fully connected layer; based on the re-identification prediction result, a first loss value, a second loss value and a third loss value of the re-identification model to be trained are calculated, the first loss value is used to describe the loss between the true probability and the predicted probability of the label to which the image belongs, the second loss value is used to describe the loss between the true distinguishing features of the image and the extracted distinguishing features, and the third loss value is used to describe the loss between the true label and the predicted label of the image; based on the first loss value, the second loss value, the third loss value and the preset target loss function, the total loss value of the re-identification model to be trained is calculated, and based on the total loss value, the re-identification model to be trained is optimized until the target loss function converges to obtain the trained re-identification model. This model training method starts from the style deviation problem in the pedestrian re-identification task. Based on the data augmentation operation of sample images, it enables the model to learn the invariant essential discriminative features in images of different styles during the training process, thereby improving the model's representation ability. By optimizing the model with three losses and the preset target loss function, the trained re-identification model can have strong robustness and generalization ability. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art 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 labor.
[0020] Figure 1 It is a flow chart for implementing a model training method provided in an embodiment of the present application;
[0021] Figure 2 It is a structural block diagram of a re-identification model provided in an embodiment of the present application;
[0022] Figure 3 It is a structural block diagram of a model training device provided in an embodiment of the present application;
[0023] Figure 4 It is a structural block diagram of a terminal device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0024] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0025] The model training method involved in the embodiment of the present application can be executed by a terminal device, such as a laptop computer, an ultra-mobile personal computer (UMPC), a netbook or a personal digital assistant (PDA).
[0026] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0027] The basic technologies of artificial intelligence generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems and mechatronics. Artificial intelligence software technology mainly includes computer vision technology, robotics technology, biometrics technology, speech processing technology and natural language processing technology, as well as machine learning / deep learning.
[0028] The model training method involved in the embodiment of the present application can be applied to the scenario of smart transportation and can promote the construction of smart cities.
[0029] See also Figure 1 , Figure 1 A flow chart of an implementation of a model training method provided in an embodiment of the present application is shown. The determination method includes:
[0030] Step 110: For each sample image in the sample set, perform two different data augmentation operations on the sample image to obtain a first image and a second image.
[0031] In order to enable the trained re-identification model to recognize the invariant features in images of different styles, two different data augmentation operations can be performed on each sample image in the sample set to obtain a first image and a second image of different styles. For example, for a sample image, a rotation operation can be performed to obtain a first image; a translation operation can also be performed to obtain a second image. Subsequent training of the re-identification model to be trained based on the first image and the second image can enable the re-identification model to learn the essential discriminative features from the first image and the second image, respectively, thereby improving the representation ability of the model. Among them, the sample set is a learning sample data set for the training model, and the images in the sample set can be obtained by crawling on the Internet, such as crawling from the ImageNet database.
[0032] Step 120: Based on the re-identification model to be trained, pedestrian re-identification is performed on the first image and the second image respectively to obtain a re-identification prediction result.
[0033] After obtaining the first image and the second image, the first image and the second image can be input into the re-identification model to be trained to realize pedestrian re-identification and obtain a re-identification prediction result. The re-identification model includes a backbone network, an average pooling layer, and a fully connected layer.
[0034] Step 130: Calculate a first loss value, a second loss value, and a third loss value of the re-identification model to be trained based on the re-identification prediction result.
[0035] After obtaining the re-identification result, three losses of the re-identification model to be trained can be obtained based on the re-identification result, corresponding to the first loss value, the second loss value and the third loss value, respectively. The first loss value is used to describe the loss between the true probability and the predicted probability of the label to which the image belongs, the second loss value is used to describe the loss between the true distinguishing features of the image and the extracted distinguishing features, and the third loss value is used to describe the loss between the true label and the predicted label of the image.
[0036] Step 140: The total loss value of the re-identification model to be trained is calculated based on the first loss value, the second loss value, the third loss value and the preset target loss function, and the re-identification model to be trained is optimized based on the total loss value until the target loss function converges to obtain a trained re-identification model.
[0037] After obtaining the first loss value, the second loss value, and the third loss value, the total loss value of the re-identification model to be trained can be calculated according to the preset target loss function, and the re-identification model to be trained can be optimized based on the total loss value. It is uncertain whether the optimized re-identification model can achieve the expected performance, so it is possible to return to execute steps 110-140 to check whether the current re-identification model needs to be optimized again. Specifically, in the process of returning to execution, when step 140 is executed again, the total loss value can be compared with the set loss threshold. If the total loss value is less than the loss threshold, it means that the target loss function converges, that is, the re-identification model obtained at this time is the re-identification model that has been trained; but if the total loss value is greater than the loss threshold, it means that the target loss function has not converged, and it is necessary to optimize the re-identification model to be trained again based on the current total loss value until the total loss is less than the loss threshold, and the re-identification model that has been trained is obtained.
[0038] This model training method starts from the style deviation problem in the pedestrian re-identification task, and based on the data augmentation operation of the sample image, enables the model to learn the essential discriminative features of the sample image during the training process, thereby improving the model's representation ability; then the model is optimized through three losses and the preset target loss function, which can make the trained re-identification model have strong robustness and generalization ability.
[0039] In some embodiments, in order to enhance the generalization ability of the trained model and improve its recognition accuracy, data augmentation operations may include horizontal / vertical flipping, rotation, scaling, cropping, shearing, translation, contrast, color jittering, and noise, etc.
[0040] Data augmentation is one of the commonly used techniques in deep learning, which is mainly used to increase the training data set, make the data set as diverse as possible, and make the trained model have stronger generalization ability. In this application, it is not only to make the trained re-identification model have stronger generalization ability, but also to improve the recognition accuracy of the re-identification model through data augmentation operation. This is because in complex shooting scenes, pedestrian images are greatly affected by factors such as shooting angle, lighting and posture, resulting in greater style differences between multiple images of the same pedestrian, which in turn leads to a decrease in the recognition accuracy of the model. In order to solve this problem, the embodiment of the present application performs two different data augmentation operations on the sample image to simulate two images with different styles but pointing to the same pedestrian, namely the first image and the second image, and then uses the first image and the second image to train the re-identification model to be trained, so that the trained re-identification model can learn the essential discriminative features of the pedestrian image. Therefore, even in complex shooting scenes, the trained re-identification model can accurately identify specific pedestrians from pedestrian images with different styles, thereby improving the accuracy of pedestrian re-identification.
[0041] In some embodiments, see Figure 2 , the re-identification model to be trained is the ResNet50 pre-trained on Imagenet, where the remaining part of ResNet50 after removing the average pooling layer and the fully connected layer is the backbone network. Specifically, the above step 120 specifically includes:
[0042] Step 121: extract features from the first image and the second image based on the backbone network to obtain first features and second features.
[0043] Step 122: vectorize the first feature and the second feature based on the average pooling layer to obtain a first feature vector and a second feature vector.
[0044] Step 123: Perform person re-identification based on the fully connected layer, the first eigenvector, and the second eigenvector to obtain a re-identification prediction result.
[0045] Inputting each of the first image and the second image into the backbone network to perform feature extraction operations can provide information and redundant derivative values for the re-identification model to be trained for re-identification, thereby promoting the subsequent learning and generalization steps of the re-identification model to be trained. In some cases, feature extraction can bring interpretability to the recognition process. For images, they are two-dimensional data, so feature extraction can be understood as a dimensionality reduction method. After obtaining the first feature and the second feature, the two features can be input into the average pooling layer to vectorize the first feature and the second feature to obtain the first feature vector and the second feature vector. The reason for performing vectorization operations on the two features is not only to improve the recognition efficiency of the re-identification model to be trained, but also to minimize the size of the feature map, thereby reducing the amount of calculation and the required video memory, thereby improving the efficiency of model training. After obtaining the first feature vector and the second feature vector, the two feature vectors can be input into the fully connected layer to integrate the local information with category distinction in the pooling layer to achieve pedestrian re-identification and obtain the re-identification prediction result. It is understandable that for the classification task of pedestrian re-identification, it can be a single classification task or a multi-classification task: if the re-identification object is a certain person, then the re-identification task is a single classification task; but if the re-identification object is several people, then the re-identification task is a multi-classification task.
[0046] The re-identification model designed in the embodiment of the present application can be regarded as a baseline network, which not only has strong feature representation and generalization capabilities, but can also be applied to data scenarios in different fields. At the same time, the baseline network can also be connected to other excellent pedestrian re-identification algorithm models to effectively improve the recognition accuracy.
[0047] In some embodiments, the re-identification prediction result may include a first prediction probability of the first image and a second prediction probability of the second image. Specifically, the first loss value may be determined by the following steps:
[0048] Based on the KL divergence and the preset first loss function, the first prediction probability and the second prediction probability are constrained to obtain a first loss value. The first loss function is:
[0049]
[0050] Where p1 is the first prediction probability of the first image, p2 is the second prediction probability of the second image, and D KL (p1||p2) is the relative entropy between the first image and the second image, D KL (p2||p1) is the relative entropy of the second image and the first image. Since the relative entropy is asymmetric, two relative entropies are used for calculation in the embodiment of the present application. And in the present application, the first loss value consists of two parts, one part is the first loss value calculated based on the first image, and the other part is the second loss value calculated based on the second image, wherein the first image refers to the first image obtained by performing a certain data augmentation operation on all images in the sample set, not a single image, and the second image is similar. That is to say, the first loss value is calculated after processing each image in the sample set.
[0051] Since the first image and the second image are the results of different data augmentation operations, they belong to different views. When the two images are predicted by the same re-identification model, two different probabilities can be obtained. However, since the first image and the second image are obtained from the same sample image, the two images correspond to the same pedestrian. In other words, if the model can accurately identify the first image and the second image, the predicted probabilities should be similar. The principle that the predicted probabilities of the two images should be similar can be used to improve the accuracy of the re-identification model. Specifically, the symmetric KL divergence can be used to constrain the two predicted probabilities, so that the re-identification model skips the style information in the two images and learns the feature information related to the pedestrian identity to improve the accuracy and generalization of the re-identification model.
[0052] In some embodiments, in order to better characterize the re-identification model, the two feature vectors obtained can be constrained by combining the triplet loss with batch hard mining (TriHard loss). The re-identification prediction result includes the distance between the positive and negative sample pairs. The second loss value is calculated by the distance between the positive and negative sample pairs and the preset second loss function. The distance between the positive and negative sample pairs is obtained by the following steps:
[0053] 210. For each image in the first image and the second image, the images are divided into at least one batch, each batch includes P pedestrian labels, each pedestrian label corresponds to K images, and the K images corresponding to each pedestrian label include a fixed image a.
[0054] 220. For each fixed image a in each batch, images with the same pedestrian label as the fixed image a are determined as the positive sample set A, and images with different pedestrian labels from the fixed image a are determined as the negative sample set B. The distance between the positive and negative sample pairs is calculated based on the fixed image a, the positive sample set A and the negative sample set B.
[0055] The hard sample sampling triplet loss is an improved version of the triplet loss. The traditional triplet loss randomly extracts three images from the sample set to calculate the distance between the positive and negative sample pairs. However, most of the samples extracted by this method are samples that can be easily distinguished. If a large number of trained sample pairs are simple sample pairs, it is not conducive to the model learning better representation. Therefore, the embodiment of the present application adopts the method of hard sample sampling to obtain sample pairs that are not conducive to distinguishing. Based on such samples, the re-recognition model to be trained is trained, which can improve the representation ability of the re-recognition model.
[0056] Specifically, there are two types of images in the embodiment of the present application, that is, all first images can be used as one type of image, and all second images can be used as another type of image. Images can be extracted from each type of image in batches, and for a batch, it contains P*K images, P is the pedestrian label, K is the number of images corresponding to each pedestrian label, and the K images with the same pedestrian label contain a fixed image a, which can be understood as a reference image for accurately predicting the pedestrian label. Since in step 110, an image is subjected to two different data augmentation operations to obtain two images of different styles, namely the first image and the second image, in the process of batch sampling, all first images can be used as a set to be sampled, and all second images can be used as another set to be sampled. In the sampling process, the above-mentioned batch sampling is performed on each set to be sampled.
[0057] After sampling is completed, for each batch, p groups of positive and negative sample sets can be divided based on each fixed image a in the batch, that is, images with the same pedestrian label as the fixed image a are determined as the positive sample set A, and images with different pedestrian labels from the fixed image a are determined as the negative sample set B.
[0058] For ease of understanding, let's take an example. Assume that there are 3 pedestrian labels in the first batch, namely Zhang San, Li Si and Wang Wu. Each pedestrian label corresponds to 5 images. There are 15 images in the first batch, including 5 images with the pedestrian label Zhang San, 5 images with the pedestrian label Li Si and 5 images with the pedestrian label Wang Wu. Among the 5 images with the pedestrian label Zhang San, there is a fixed image a1, among the 5 images with the pedestrian label Li Si, there is a fixed image a2, and among the 5 images with the pedestrian label Wang Wu, there is a fixed image a3. For each of the three fixed images a1, a2 and a3, a set of positive and negative sample sets can be determined. For a1, the other 4 images with the same pedestrian label can form the positive sample set A1, and the two other 10 images with different pedestrian labels can form the negative sample set B1. The two other 10 images with different pedestrian labels are the 10 images with the pedestrian labels Li Si and Wang Wu in the first batch. For a2 and a3, the above a1 is analogous. Through the above operations, three sets of positive and negative sample sets can be obtained. And for each set of positive and negative sample sets, the distance between the positive and negative sample pairs can be calculated in combination with the corresponding fixed image a.
[0059] Optionally, the distance between two images may be represented by Euclidean distance, Mahalanobis distance, cosine similarity, and the like.
[0060] In some embodiments, the positive and negative sample pair distances include positive sample pair distances and negative sample pair distances. Calculating the positive and negative sample pair distances based on the fixed image a, the positive sample set A, and the negative sample set B specifically includes:
[0061] 221. Calculate the positive sample pair distance between each image in the positive sample set A and the fixed image a.
[0062] 222 Calculate the negative sample pair distance between each image in the negative sample set B and the fixed image a.
[0063] Taking the above-mentioned fixed image a1, positive sample set A1 and positive sample set B1 as examples, we can calculate the distance between a1 and each image in the positive sample set A1 to obtain 4 positive sample pair distances, and calculate the distance between a1 and each image in the positive sample set B1 to obtain 10 negative sample pair distances.
[0064] Optionally, after calculating the distances between the positive and negative sample pairs, in order to confuse the feature extractor, the most difficult positive sample and the most difficult negative sample can be selected from them, that is, the image corresponding to the maximum value of the 4 positive sample pair distances is used as the positive sample image, and the image corresponding to the minimum value of the 10 negative sample pair distances is used as the negative sample image, thereby forming a difficult sample sampling triplet to facilitate the calculation of the second loss value.
[0065] The re-identification model to be trained is optimized based on the difficult sample sampling triplet loss, which can shorten the distance between positive sample pairs and push away the distance between negative sample pairs, making the intra-class distance in the dataset closer and the inter-class distance farther, thereby improving the recognition ability of the re-identification model.
[0066] Specifically, the formula of the second loss function is as follows:
[0067]
[0068] Among them, p is a positive sample, n is a negative sample, and d a,p and d a,n Respectively represent the distance between positive and negative sample pairs, (·) + It should be understood that for each image, the above formula is used to calculate the second loss value of each image. After calculating the second loss values of two images, the total second loss value can be further calculated.
[0069] In some embodiments, the third loss value is calculated by a preset third loss function, and the third loss function is:
[0070]
[0071] Among them, N is the total number of categories of pedestrian labels in the sample set, q i is the predicted label, p i is the predicted probability that the pedestrian in the image belongs to the i-th pedestrian label, and y is the true label of the pedestrian in the image. The calculation of the second loss value is the same. For each image, the above formula is used to calculate the third loss value of each image. After calculating the third loss values of the two images, the total third loss value can be further calculated.
[0072] Similarly, in order to maintain consistency in the calculation of the three loss functions, the third loss value includes two parts, namely, the third loss value calculated based on the first image and the third loss value calculated based on the second image.
[0073] Based on the above three loss values, the total loss value can be calculated. The target loss function used to calculate the total loss value is as follows:
[0074]
[0075] Among them, L KL Based on the first loss value, the is the second loss value calculated based on the first image, is the second loss value calculated based on the second image, is the third loss value calculated based on the first image, is the third loss value calculated based on the second image. That is to say, the total loss value calculated above is calculated after all the first images and all the second images are recognized. For example, there are 1000 sample images. After the data augmentation operation, 1000 first images and 1000 second images are obtained. After all 2000 images are recognized, the total loss value is calculated according to the total target loss function to optimize the re-recognition model.
[0076] In some embodiments, after step 140, the model training method further includes:
[0077] The sample set, the re-identification model to be trained and / or the trained re-identification model are uploaded to the blockchain.
[0078] Among them, in order to ensure the security of data and fairness and transparency to users, the current set, the re-identification model to be trained and / or the trained re-identification model can be uploaded to the blockchain for evidence storage. Users can then download and obtain the current set, the re-identification model to be trained and / or the trained re-identification model from the blockchain through their respective devices to verify whether these data have been tampered with. The blockchain referred to in this embodiment is a new application model that uses computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism and encryption algorithm. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods, each of which contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. The blockchain may include the underlying blockchain platform, the platform product service layer, and the application service layer.
[0079] In addition, an embodiment of the present application also provides a model training device.
[0080] See also Figure 3 , Figure 3 is a structural block diagram of a model training device provided in an embodiment of the present application. In this embodiment, the terminal device includes various units for executing Figure 1 For details, please refer to the steps in the corresponding embodiment. Figure 1 as well as Figure 1 For the convenience of explanation, only the parts related to this embodiment are shown. Figure 3 , the model training device 30 comprises:
[0081] A data augmentation module 31 is used for performing two different data augmentation operations on each sample image in the sample set to obtain a first image and a second image;
[0082] A re-identification module 32, configured to perform pedestrian re-identification on the first image and the second image respectively based on the re-identification model to be trained to obtain a re-identification prediction result, wherein the re-identification model includes a backbone network, an average pooling layer, and a fully connected layer;
[0083] A calculation module 33, used to calculate a first loss value, a second loss value and a third loss value of the re-identification model to be trained based on the re-identification prediction result, wherein the first loss value is used to calculate the loss between the true probability and the predicted probability of the label to which the image belongs, the second loss value is used to calculate the loss between the true distinguishing feature and the extracted distinguishing feature of the image, and the third loss value is used to calculate the loss between the true label and the predicted label of the image;
[0084] The optimization module 34 is used to calculate the total loss value of the re-identification model to be trained based on the first loss value, the second loss value, the third loss value and the preset target loss function, and optimize the re-identification model to be trained based on the total loss value until the target loss function converges to obtain a trained re-identification model.
[0085] As an embodiment of the present application, the re-identification prediction result includes a first prediction probability of the first image and a second prediction probability of the second image, and the calculation module 33 is specifically used for:
[0086] Based on the KL divergence and the preset first loss function, the first prediction probability and the second prediction probability are constrained to obtain a first loss value. The first loss function is:
[0087]
[0088] Where p1 is the first prediction probability of the first image, p2 is the second prediction probability of the second image, and D KL (p1||p2) is the relative entropy of the first image, D KL (p2||p1) is the relative entropy of the second image.
[0089] As an embodiment of the present application, the re-identification prediction result includes the distance between the positive and negative sample pairs, and the calculation module 33 is specifically used to calculate the second loss value through the distance between the positive and negative sample pairs and the preset second loss function. The model training device also includes:
[0090] A sampling module, for each of the first image and the second image, dividing the image into at least one batch, each batch including P pedestrian labels, each pedestrian label corresponding to K images, each pedestrian label corresponding to the K images including a fixed image a;
[0091] The first determination module is used to determine, for each fixed image a in each batch, images with the same pedestrian label as the fixed image a as the positive sample set A, and images with different pedestrian labels from the fixed image a as the negative sample set B, and calculate the distance between the positive and negative sample pairs based on the fixed image a, the positive sample set A and the negative sample set B.
[0092] As an embodiment of the present application, the positive and negative sample pair distances include positive sample pair distances and negative sample pair distances, and the first determination module may include:
[0093] A first calculation unit, used to calculate the positive sample pair distance between each image in the positive sample set A and the fixed image a;
[0094] The second calculation unit is used to calculate the negative sample pair distance between each image in the negative sample set B and the fixed image a.
[0095] As an embodiment of the present application, the calculation module 33 is specifically used to calculate the third loss value by using a preset third loss function, and the third loss function is:
[0096]
[0097] Among them, N is the total number of categories of pedestrian labels in the sample set, q i is the predicted label, p i is the predicted probability that the pedestrian in the image belongs to the i-th category of pedestrian labels, and y is the true label of the pedestrian in the image.
[0098] As an embodiment of the present application, the re-identification module 32 further includes:
[0099] A feature extraction unit, configured to extract features from the first image and the second image based on the backbone network to obtain a first feature and a second feature;
[0100] A vectorization unit, used for vectorizing the first feature and the second feature based on the average pooling layer to obtain a first feature vector and a second feature vector;
[0101] The re-identification unit is used to perform pedestrian re-identification based on the fully connected layer, the first feature vector and the second feature vector to obtain a re-identification prediction result.
[0102] As an embodiment of the present application, the model training device 30 further includes:
[0103] The upload module is used to upload the sample set, the re-identification model to be trained and / or the trained re-identification model to the blockchain.
[0104] It should be understood that Figure 3 In the structural block diagram of the model training device shown, each unit is used to execute Figure 1The steps in the corresponding embodiments, and for Figure 1 Each step in the corresponding embodiment has been explained in detail in the above embodiment. Figure 1 as well as Figure 1 The relevant descriptions in the corresponding embodiments are not repeated here.
[0105] Figure 4 is a structural block diagram of a terminal device provided by another embodiment of the present application. Figure 4 As shown, the terminal device 40 of this embodiment includes: a processor 41, a memory 42, and a computer program 43 stored in the memory 42 and executable on the processor 41, such as a program of the model training method. When the processor 41 executes the computer program 43, the steps in each embodiment of the model training method are implemented, such as Figure 1 Alternatively, the processor 41 implements the above-mentioned Figure 3 The functions of each module in the corresponding embodiment are, for example, Figure 3 For details on the functions of modules 31 to 34 shown, please refer to Figure 3 The relevant descriptions in the corresponding embodiments are not repeated here.
[0106] Exemplarily, the computer program 43 may be divided into one or more units, and the one or more units are stored in the memory 42 and executed by the processor 41 to complete the present application. The one or more units may be a series of computer program instruction segments capable of completing specific functions, and the instruction segments are used to describe the execution process of the computer program 43 in the terminal 40. For example, the computer program 43 may be divided into a data augmentation module 31, a re-identification module 32, a calculation module 33, and an optimization module 34, and the specific functions of each module are as described above.
[0107] The terminal device may include, but is not limited to, a processor 41 and a memory 42. Those skilled in the art will appreciate that Figure 4 It is only an example of the terminal device 40 and does not constitute a limitation of the terminal device 40. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the above-mentioned terminal device may also include input and output devices, network access devices, buses, etc.
[0108] The processor 41 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0109] The memory 42 may be an internal storage unit of the terminal device 40, such as a hard disk or memory of the terminal device 40. The memory 42 may also be an external storage device of the terminal device 40, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the terminal device 40. Further, the memory 42 may include both an internal storage unit of the terminal device 40 and an external storage device. The memory 42 is used to store the computer program and other programs and data required by the terminal device. The memory 42 may also be used to temporarily store data that has been output or is to be output.
[0110] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A model training method, characterized in that: The model training method comprises: For each sample image in the sample set, performing two different data augmentation operations on the sample image to obtain a first image and a second image; Based on the re-identification model to be trained, pedestrian re-identification is performed on the first image and the second image respectively to obtain a re-identification prediction result, wherein the re-identification model includes a backbone network, an average pooling layer, and a fully connected layer; Calculating a first loss value, a second loss value, and a third loss value of the re-identification model to be trained based on the re-identification prediction result, wherein the first loss value is used to describe the loss between the true probability and the predicted probability of the label to which the image belongs, the second loss value is used to describe the loss between the true distinguishing feature and the extracted distinguishing feature of the image, and the third loss value is used to describe the loss between the true label and the predicted label of the image; The total loss value of the re-identification model to be trained is calculated based on the first loss value, the second loss value, the third loss value and a preset target loss function, and the re-identification model to be trained is optimized based on the total loss value until the target loss function converges to obtain a trained re-identification model; The re-identification prediction result includes a first prediction probability of the first image and a second prediction probability of the second image, and the first loss value is calculated in the following manner: The first prediction probability and the second prediction probability are constrained based on the KL divergence and a preset first loss function to obtain the first loss value, where the first loss function is: Wherein, p1 is the first prediction probability of the first image, p2 is the second prediction probability of the second image, and D KL (p1||p2) is the relative entropy of the first image, and the D KL (p2||p1) is the relative entropy of the second image.
2. The model training method according to claim 1, characterized in that: The re-identification prediction result includes a positive-negative sample pair distance, the second loss value is calculated by the positive-negative sample pair distance and a preset second loss function, and the positive-negative sample pair distance is obtained by the following steps: For each of the first image and the second image, the image is divided into at least one batch, each batch includes P pedestrian labels, each pedestrian label corresponds to K images, and each of the K images corresponding to the pedestrian label includes a fixed image a; For each fixed image a in each batch, the images with the same pedestrian label as the fixed image a are determined as the positive sample set A, and the images with different pedestrian labels from the fixed image a are determined as the negative sample set B, and the distance between the positive and negative sample pairs is calculated based on the fixed image a, the positive sample set A and the negative sample set B.
3. The model training method according to claim 2, characterized in that: The positive and negative sample pair distances include a positive sample pair distance and a negative sample pair distance, and the calculation of the positive and negative sample pair distances based on the fixed image a, the positive sample set A, and the negative sample set B includes: Calculate the positive sample pair distance between each image in the positive sample set A and the fixed image a; Calculate the negative sample pair distance between each image in the negative sample set B and the fixed image a.
4. The model training method according to claim 1, characterized in that: The third loss value is calculated by a preset third loss function, and the third loss function is: Wherein, N is the total number of categories of pedestrian labels in the sample set, and q i is the predicted label, the p i is the predicted probability that the pedestrian in the image belongs to the i-th category of pedestrian label, and y is the true label of the pedestrian in the image.
5. The model training method according to any one of claims 1 to 4, characterized in that: The step of performing pedestrian re-identification on the first image and the second image based on the re-identification model to be trained to obtain a re-identification prediction result includes: Based on the backbone network, feature extraction is performed on the first image and the second image respectively to obtain a first feature and a second feature; Vectorizing the first feature and the second feature based on the average pooling layer to obtain a first feature vector and a second feature vector; Pedestrian re-identification is performed based on the fully connected layer, the first feature vector and the second feature vector to obtain a re-identification prediction result.
6. The model training method according to claim 1, characterized in that: After obtaining the trained re-recognition model, the model training method further includes: Upload the sample set, the re-identification model to be trained, and / or the trained re-identification model to the blockchain.
7. A model training device, characterized in that: The model training device comprises: A data augmentation module, configured to perform two different data augmentation operations on each sample image in a sample set to obtain a first image and a second image; A re-identification module, configured to perform pedestrian re-identification on the first image and the second image respectively based on a re-identification model to be trained to obtain a re-identification prediction result, wherein the re-identification model includes a backbone network, an average pooling layer, and a fully connected layer; a calculation module, configured to calculate a first loss value, a second loss value, and a third loss value of the re-identification model to be trained based on the re-identification prediction result, wherein the first loss value is used to describe the loss between the true probability and the predicted probability of the label to which the image belongs, the second loss value is used to describe the loss between the true distinguishing feature and the extracted distinguishing feature of the image, and the third loss value is used to describe the loss between the true label and the predicted label of the image; an optimization module, configured to calculate a total loss value of the re-recognition model to be trained based on the first loss value, the second loss value, the third loss value and a preset target loss function, and optimize the re-recognition model to be trained based on the total loss value until the target loss function converges, thereby obtaining a trained re-recognition model; The re-identification prediction result includes a first prediction probability of the first image and a second prediction probability of the second image, and the calculation module is specifically used to: The first prediction probability and the second prediction probability are constrained based on the KL divergence and a preset first loss function to obtain the first loss value, where the first loss function is: Wherein, p1 is the first prediction probability of the first image, p2 is the second prediction probability of the second image, and D KL (p1||p2) is the relative entropy of the first image, and the D KL (p2||p1) is the relative entropy of the second image.
8. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Object recognition model training method, object recognition method and corresponding devices
CN110414432A
Object recognition network training method and system
CN111178115A
Face recognition method and device, server and storage medium
CN112241664A
Model training method and device, prediction method and device, re-identification model and electronic equipment
CN112801235A
SAR image recognition method and device and storage medium
CN113688757A
