Sample construction method and device for model cross-domain training, equipment and medium
By constructing a sample set and training the initial model across domains, the problems of feature extraction bias and low accuracy of cross-domain human body weight recognition models in different scenarios were solved, and high-accuracy recognition in the target scenario was achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHENZHEN INTELLIFUSION TECHNOLOGIES CO LTD
- Filing Date
- 2022-12-23
- Publication Date
- 2026-05-15
AI Technical Summary
When used across domains, existing human body weight recognition models suffer from low feature extraction bias and recognition accuracy due to significant differences in human characteristics across different application scenarios.
By acquiring images and personnel identifiers in target human recognition scenarios, a sample set is constructed. Reference images and negative examples are selected, and training samples and positive examples are randomly selected. The sample set is then used to train the initial model across domains, thereby improving the model's discrimination ability in target scenarios.
It improved the model's accuracy in target human recognition scenarios, enabled cross-domain learning across different scenarios, and enhanced the model's recognition capabilities in target scenarios.
Smart Images

Figure CN116246303B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence technology, and in particular to a method, apparatus, device, and medium for constructing samples for cross-domain model training. Background Technology
[0002] With the development of artificial intelligence technology and the increasing demands for enterprise management and public safety, human body recognition technology, due to its ability to track, match, and identify target groups across time and space, has been widely applied in all aspects of social life. Currently, the deployment of human body recognition models in new human body recognition scenarios typically involves directly using the source domain model pre-trained in the initial human body recognition scenario.
[0003] However, with the rapid expansion of application scenarios, the characteristics of people in different application scenarios often vary greatly, such as clothing characteristics. This leads to a certain feature extraction bias in the pre-trained source domain model when extracting human features in the initial human recognition scenario. As a result, the feature extraction effect is not good when directly applied to new target human recognition scenarios, and the human weight recognition result is not accurate enough. That is, the human weight recognition accuracy of the model is low when used across domains. Therefore, how to improve the human weight recognition accuracy of the model when used across domains has become an urgent problem to be solved. Summary of the Invention
[0004] In view of this, embodiments of the present invention provide a sample construction method, apparatus, device and medium for cross-domain model training, in order to solve the problem of low human body weight recognition accuracy of the model when used across domains.
[0005] In a first aspect, embodiments of the present invention provide a sample construction method for cross-domain model training, the sample construction method comprising:
[0006] Obtain at least one human image and its corresponding person identifier in the target human recognition scenario. Combine all human images belonging to the same person identifier into a human image set to obtain N human image sets with corresponding person identifiers, where N is an integer greater than zero.
[0007] Randomly select one human image from the set of human images corresponding to each person identifier as the reference image for the corresponding person identifier, and obtain the reference image corresponding to each person identifier;
[0008] For any person identifier, based on the similarity between reference images, determine the first I target images that are most similar to the reference images corresponding to the person identifier from the reference images corresponding to other person identifiers, and use the person identifier corresponding to the target image as a negative example identifier;
[0009] Two human images are randomly selected from the set of human images corresponding to the personnel identifier. One image is used as a training sample and the other as a positive example sample. One human image is randomly selected from the set of human images corresponding to the negative example identifier as a negative example sample. I is an integer greater than zero and less than N.
[0010] A sample set is constructed using the training samples, the positive samples, and the negative samples. The N personnel identifiers are traversed to obtain N sample sets. The N sample sets are used to perform cross-domain training on the source domain model pre-trained in the initial human recognition scenario to obtain a target domain model for the target recognition scenario.
[0011] Secondly, embodiments of the present invention provide a sample construction apparatus for cross-domain model training, the sample construction apparatus comprising:
[0012] The set partitioning module is used to obtain at least one human image and its corresponding person identifier in the target human recognition scenario, and to form a human image set by combining human images belonging to the same person identifier in all human images, so as to obtain N human image sets with corresponding person identifiers, where N is an integer greater than zero.
[0013] The image selection module is used to randomly select a human image from the human image set corresponding to each person identifier as the reference image for the corresponding person identifier, so as to obtain the reference image corresponding to each person identifier.
[0014] The identifier determination module is used to determine, for any person identifier, the first I target images that are most similar to the reference images corresponding to the person identifier from the reference images corresponding to other person identifiers based on the similarity between reference images, and use the person identifier corresponding to the target image as a negative example identifier, where I is an integer greater than zero and less than N;
[0015] The sample selection module is used to randomly select two human images from the human image set corresponding to the personnel identifier, using one as a training sample and the other as a positive example sample, and to randomly select one human image from the human image set corresponding to the negative example identifier as a negative example sample.
[0016] The set construction module is used to construct a sample set with the training samples, the positive samples, and the negative samples, and to traverse the N personnel identifiers to obtain N sample sets. The N sample sets are used to perform cross-domain training on the source domain model pre-trained in the initial human recognition scenario to obtain a target domain model for the target recognition scenario.
[0017] Thirdly, embodiments of the present invention provide a computer device, the computer device including a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the sample construction method as described in the first aspect.
[0018] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the sample construction method as described in the first aspect.
[0019] The beneficial effects of the embodiments of the present invention compared with the prior art are as follows:
[0020] To obtain at least one human image and its corresponding person identifier in a target human recognition scenario, group all human images belonging to the same person identifier into a human image set, resulting in N human image sets corresponding to each person identifier. Randomly select one human image from each person identifier's corresponding human image set as a reference image for that person identifier, thus obtaining a reference image for each person identifier. For any given person identifier, based on the similarity between reference images, determine the top I target images most similar to the reference images corresponding to other person identifiers. Use the person identifier corresponding to the target image as a negative example identifier. Randomly select at least two human images from the human image sets corresponding to the person identifiers, using one as a training sample. Using Zhang as a positive example sample, at least one human image is randomly selected from the set of human images corresponding to the negative example labels as a negative example sample. A sample set is constructed using training samples, positive examples, and negative examples. By traversing N human labels, N sample sets are obtained. These N sample sets are used to perform cross-domain training on the source domain model pre-trained in the initial human recognition scenario to obtain a target domain model for the target recognition scenario. In the target human recognition scenario, the sample combination with higher discrimination difficulty is determined based on the similarity of the reference images. This sample combination is used to retrain the source domain model pre-trained in the initial human recognition scenario to improve the model's discrimination ability in the target scenario, realize cross-domain learning between different human recognition scenarios, and improve the accuracy of human weight recognition when using the model across domains. Attached Figure Description
[0021] To more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0022] Figure 1This is a schematic diagram of an application environment for a sample construction method for cross-domain model training provided in Embodiment 1 of the present invention;
[0023] Figure 2 This is a flowchart illustrating a sample construction method for cross-domain model training provided in Embodiment 1 of the present invention.
[0024] Figure 3 This is a flowchart illustrating a sample construction method for cross-domain model training provided in Embodiment 2 of the present invention;
[0025] Figure 4 This is a schematic diagram of a sample construction device for cross-domain model training provided in Embodiment 3 of the present invention;
[0026] Figure 5 This is a schematic diagram of the structure of a computer device provided in Embodiment 4 of the present invention. Detailed Implementation
[0027] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of the invention. However, those skilled in the art will understand that the invention can be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods are omitted so as not to obscure the description of the invention with unnecessary detail.
[0028] It should be understood that, when used in this specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.
[0029] It should also be understood that the term “and / or” as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0030] As used in this specification and the appended claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrase "if determined" or "if [described condition or event] is detected" may be interpreted, depending on the context, as meaning "once determined," "in response to determination," "once [described condition or event] is detected," or "in response to detection of [described condition or event]."
[0031] Furthermore, in the description of this invention and the appended claims, the terms "first," "second," "third," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0032] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of the invention include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0033] The embodiments of this invention can acquire and process relevant data based on artificial intelligence technology. Artificial intelligence (AI) refers to the theories, methods, technologies, and application systems that utilize digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to obtain optimal results.
[0034] Foundational technologies for artificial intelligence generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies mainly encompass computer vision, robotics, biometrics, speech processing, natural language processing, and machine learning / deep learning.
[0035] It should be understood that the sequence number of each step in the following embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0036] To illustrate the technical solution of the present invention, specific embodiments are described below.
[0037] The first embodiment of this invention provides a sample construction method for cross-domain model training, which can be applied to, for example... Figure 1In this application environment, the client communicates with the server. The client includes, but is not limited to, handheld computers, desktop computers, laptops, ultra-mobile personal computers (UMPCs), netbooks, cloud terminal devices, and personal digital assistants (PDAs). The server can be a standalone server or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.
[0038] The client can be deployed in target human body recognition scenarios, such as criminal investigation, smart retail, smart security, or smart transportation. These scenarios typically involve several image acquisition devices, including but not limited to cameras, video cameras, camcorders, and handheld cameras. For example, a smart retail scenario is usually inside a shopping mall or store. Several cameras are deployed to capture customers' browsing trajectories of retail goods. However, the capture area of a single camera is limited and cannot cover the entire smart retail scenario. To fully obtain the customer's browsing trajectory in a smart retail scenario, multiple cameras need to work together to capture images. When using multiple image acquisition devices to identify the same target person, the task of target person body recognition is involved—identifying the target person from the images captured by multiple image acquisition devices—in order to obtain the customer's browsing trajectory throughout the smart retail scenario.
[0039] See Figure 2 This is a flowchart illustrating a sample construction method for cross-domain model training provided in Embodiment 1 of the present invention. The above-described sample construction method for cross-domain model training can be applied to… Figure 1 In this context, the client-side computer connects to the server. The server is deployed in the initial human recognition scenario. The client-side computer obtains a pre-trained source domain model from the server. Then, the client-side computer is deployed in the target human recognition scenario and connects to an image acquisition device to obtain the human image captured by the image acquisition device. For example... Figure 2 As shown, the sample construction method for cross-domain model training may include the following steps:
[0040] Step S201: Obtain at least one human image and its corresponding person identifier in the target human recognition scenario. Combine all human images belonging to the same person identifier into a human image set to obtain N human image sets corresponding to person identifiers.
[0041] In this context, the target human body recognition scenario can refer to the human body recognition scenario that the human body recognition task currently needs to apply, the human body image can refer to an image containing the human body region, the person identifier can refer to the identity identifier corresponding to the person, each human body image set can contain at least one human body image, all human body images in a human body image set belong to the same person identifier, and N is an integer greater than zero.
[0042] Specifically, taking the target human body recognition scenario as an example of a smart retail scenario, the human body image can be a customer image collected by various cameras in the smart retail scenario. After the camera collects the image, it is necessary to determine whether the collected image contains the human body area. At this time, the implementer can use deep neural network models such as image classification models, object detection models, and semantic segmentation models to distinguish between human body images and non-human body images.
[0043] In this embodiment, an image classification model is used to distinguish between human images and non-human images. The image classification model may include an encoder and a classifier. The encoder takes the image captured by the camera as input and outputs the image feature vector corresponding to the image captured by the camera. The classifier takes the image feature vector as input and outputs the image category. The image classification model is trained using a binary classification task, with the first category being human images and the second category being non-human images.
[0044] Personnel identification can be done using numerical serial numbers, that is, assigning a number to each person as their identity identifier. A set of human images is created for each personnel identifier, and all human image sets are initialized to an empty set. Each human image is iterated over, and based on the personnel identifier corresponding to that human image, the human image is added to the human image set corresponding to that personnel identifier, resulting in N human images corresponding to each personnel identifier.
[0045] Like a set, a set of human images corresponding to a person identifier contains all human images belonging to that person identifier. Figure 5 picture.
[0046] The steps described above—obtaining at least one human image and its corresponding person identifier from the target human recognition scenario, grouping human images belonging to the same person identifier into a human image set, and obtaining N sets of human images corresponding to the same person identifier—will acquire the human images from the target human recognition scenario.
[0047] Dividing the human image set according to personnel identification facilitates the subsequent extraction of human images that are difficult to distinguish in target human recognition scenarios from different human image sets. The source domain model is then trained using these human images that are difficult to distinguish in target human recognition scenarios, enabling the model to better learn the features of human images in target human recognition scenarios, thereby improving the accuracy of human body recognition when the model is used across domains.
[0048] Step S202: Randomly select a human image from the human image set corresponding to each person identifier as the reference image for the corresponding person identifier, and obtain the reference image corresponding to each person identifier.
[0049] 5. In this embodiment, the reference image may refer to the representative image of the corresponding person. For all human images in a human image set, probability sampling is performed on all human images in the human image set according to the same sampling probability. For example, if the human image set contains K human images, then the sampling probability of each human image in the human image set is 1 / K.
[0050] In one implementation, the implementer may use a random number generation method to randomly generate an integer within the range [1,K], and determine the corresponding human body image as the randomly selected reference image based on the generated integer.
[0051] The above steps, which involve randomly selecting one human image from the set of human images corresponding to each person identifier as the reference image for that person identifier, facilitate subsequent identification of individuals based on the similarity between reference images.
[0052] The similarity between personnel identified by the staff member identifier can effectively identify individuals that are difficult to distinguish, providing challenging examples in target human recognition scenarios for model training. This improves the model's performance after cross-domain training.
[0053] Accuracy of human weight recognition in target human body recognition scenarios.
[0054] Step S203: For any person identifier, based on the similarity between reference images, determine the first I target images that are most similar to the reference images corresponding to other person identifiers, and use the person identifiers corresponding to all target images as negative example identifiers.
[0055] 0 Where I is an integer greater than zero and less than N. Similarity can be calculated using distance metrics such as Euclidean distance, cosine distance, and Manhattan distance. The target image can be the reference image of other personnel identifiers that is most similar to the reference image of the targeted personnel identifier. The negative example identifier can be the personnel identifier corresponding to other personnel that is most similar to the personnel of the targeted personnel identifier.
[0056] Specifically, in this embodiment, cosine similarity is used to calculate the similarity between reference images. The value range of cosine similarity is [0,1]. The closer the cosine similarity is to 1, the more similar the two reference images used to calculate the cosine similarity are. The closer the cosine similarity is to 0, the less similar the two reference images used to calculate the cosine similarity are. For any reference image corresponding to a person identifier, the similarity of the reference image is calculated with the reference images corresponding to the other K-1 person identifiers respectively, and K-1 calculation results are obtained. The largest I value among the K-1 calculation results is determined, and the reference image corresponding to the largest I value is used as the target image.
[0057] The steps described above, which involve determining the top I target images that are most similar to the reference images corresponding to other personnel icons based on the similarity between reference images, and using the personnel icons corresponding to all target images as negative examples, effectively identify personnel that are difficult to distinguish. This provides difficult example samples in target human body recognition scenarios for model training, thereby improving the model's cross-domain training performance and ultimately increasing the model's accuracy in recognizing human body weight in target human body recognition scenarios.
[0058] Step S204: Randomly select at least two human images from the human image set corresponding to the personnel identifier, use one as a training sample and the others as positive samples, and randomly select at least one human image from the human image set corresponding to the negative sample identifier as a negative sample.
[0059] Among them, training samples can refer to human images used to train pre-trained source domain models, positive samples can refer to human images belonging to the same person as the training samples, and negative samples can refer to human images not belonging to the same person as the training samples.
[0060] Specifically, when randomly selecting at least two human images from the set of human images corresponding to personnel identifiers, a random sampling method without replacement is used for the selection of human images. Suppose that the set of human images corresponding to personnel identifiers contains P human images. When selecting the first human image, the sampling probability of each human image in the set of human images corresponding to personnel identifiers is 1 / P. When selecting the second human image, the sampling probability of each human image in the set of human images corresponding to personnel identifiers, except for the first human image, is 1 / (P-1), and the sampling probability of the first human image is 0, and so on. That is, there is no repetition among all the human images randomly selected from the set of human images corresponding to personnel identifiers.
[0061] Similarly, suppose the set of human images corresponding to the negative example label contains Q human images, and the sampling probability of each human image in the set of human images corresponding to the negative example label is 1 / Q.
[0062] In one implementation, the implementer can randomly select R human images from the human image set corresponding to the personnel identifier, and also select R human images from the human image set corresponding to the negative example identifier. R can be an integer greater than zero. The selected 2R human images form a training batch. In this training batch, each human image can be used as a training sample. At this time, other human images in the human image set to which the human image used as a training sample belongs are used as positive examples, and human images in the human image set not to which the human image used as a training sample belongs are used as negative examples. This enables batch training and effectively improves the efficiency of subsequent training processes.
[0063] For example, for a set of human images with personnel identifier 01, and its negative examples identified as 02, 03, and 04, three human images are selected from each of the sets with personnel identifiers 01, 02, 03, and 04, for a total of 12 human images forming a training batch. Within the training batch, human images in the set with personnel identifier 01 are positive examples of each other, human images in the set with personnel identifier 02 are also positive examples of each other, and so on. Human images in human image sets with different personnel identifiers are negative examples of each other. For example, human images in the set with personnel identifier 01 and human images in the set with personnel identifier 02 are negative examples of each other.
[0064] The steps of randomly selecting at least two human images from the set of human images corresponding to the aforementioned personnel identifier, using one as a training sample and the others as positive examples, and randomly selecting at least one human image from the set of human images corresponding to negative examples as negative examples, are as follows: For a training sample of a personnel identifier, human images belonging to the same personnel identifier are selected as positive examples, and human images of persons who are difficult to distinguish from the person corresponding to the personnel identifier in the target human recognition scenario are selected as negative examples. This provides difficult examples for model training, thereby improving the model's discrimination ability and thus improving the accuracy of human weight recognition in the target human recognition scenario.
[0065] Step S205: Construct a sample set using training samples, positive samples, and negative samples, and iterate through N personnel identifiers to obtain N sample sets.
[0066] Here, the sample set can refer to a single input sample of the source domain model during cross-domain training. N sample sets can be used as a batch of training samples. N sample sets are used to perform cross-domain training on the source domain model pre-trained in the initial human recognition scenario to obtain the target domain model for the target recognition scenario.
[0067] Optionally, the sample construction method also includes:
[0068] Based on N sample sets, the pre-trained source domain model is trained across domains to obtain the target domain model.
[0069] The pre-trained source domain model can refer to a human weight recognition model pre-trained based on training samples in the initial human recognition scenario, while the target domain model can refer to a human weight recognition model retrained using a sample set.
[0070] The source domain model and the target domain model have the same model architecture, and both can be human body weight recognition models. The only difference between the source domain model and the target domain model is the model parameters.
[0071] Specifically, since the pre-trained source domain model is pre-trained based on training samples in the initial human body recognition scenario, and the training samples in different human body recognition scenarios have different sample distribution preferences, the human body weight recognition model trained based on the training samples in different human body recognition scenarios has different sensitivities to human image features. Therefore, when the pre-trained source domain model is directly transferred to the target human body recognition scenario, it will become insensitive to some features of the human image in the target human body recognition scenario, resulting in a low human body weight recognition accuracy of the pre-trained source domain model in the target human body recognition scenario.
[0072] For example, if the initial human body recognition scenario is a kitchen, the human body weight recognition model is used to monitor the movements of chefs. In a kitchen, chefs' attire is relatively similar, including chef's uniforms, hats, and masks. Therefore, when training the human body weight recognition model based on training samples from the kitchen scenario, the model will focus more on body shape and posture features, ignoring clothing features, thus achieving convergence during the pre-training process. However, in a smart retail scenario, the clothing of customers is significantly different. Therefore, clothing features can be used as more effective features for human body weight recognition. Directly transferring a source domain model pre-trained based on kitchen training samples to a smart retail scenario will result in insensitivity to clothing features in human images, leading to lower accuracy in human body weight recognition in smart retail scenarios.
[0073] In this embodiment, the pre-trained source domain model is retrained using sample combinations from the target recognition scenario to achieve cross-domain learning between scenarios and improve the accuracy of human weight recognition model in target recognition scenarios.
[0074] Optionally, the pre-trained source domain model includes a pre-trained feature extraction layer;
[0075] Based on N sample sets, the pre-trained source domain model is trained across domains to obtain the target domain model, which includes:
[0076] For any set of samples, the training samples, positive samples, and negative samples in the set are used as input samples. The input samples are fed into a pre-trained feature extraction layer for feature extraction to obtain the initial sample features of the corresponding input samples.
[0077] The initial sample features are normalized, the normalized results are pooled, and the pooling results are determined as the final sample features of the corresponding input samples. The final sample features of all corresponding input samples are determined to form the feature set of the corresponding sample set.
[0078] Traverse all sample sets to obtain N feature sets corresponding to the sample sets. Based on the feature sets of the N corresponding sample sets, train the pre-trained source domain model to obtain the target domain model.
[0079] Among them, the pre-trained feature extraction layer can be used to extract the feature information of the input sample, that is, the initial sample features.
[0080] Instance normalization can refer to normalizing each input sample. Pooling can refer to compound pooling, which means processing the normalization result using multiple pooling methods before weighted calculation. Pooling methods can include mean pooling, max pooling, etc.
[0081] The final sample features can refer to the final output of the pre-trained feature extraction layer.
[0082] In this embodiment, an instance normalization operation is added during the feature extraction process to reduce the impact of eliminating global information, so that the model pays more attention to the discriminative features of a single input sample and improves the model's ability to discriminate input samples.
[0083] Optionally, the pre-trained source domain model also includes a pre-trained classification layer;
[0084] Based on the feature set of N corresponding sample sets, the pre-trained source domain model is trained to obtain the target domain model, which includes:
[0085] For any set of samples, the final sample features corresponding to the training samples in the set are input into a pre-trained classification layer for feature classification, and the recognition results of the training samples in the corresponding set are obtained.
[0086] Obtain the recognition labels corresponding to the training samples in the sample set. Based on the recognition results and recognition labels corresponding to the training samples in the sample set and the preset classification loss function, calculate the sub-loss of the corresponding sample set. Iterate through all sample sets to obtain the sub-loss of the corresponding sample set.
[0087] The sum of the sub-losses of all corresponding sample sets is determined as the classification loss. Based on the classification loss, the pre-trained source domain model is trained to obtain the target domain model.
[0088] The pre-trained classification layer can be implemented using a fully connected layer. The recognition result can refer to the predicted category of the training sample in the sample set, the recognition label can refer to the true category of the training sample in the sample set, the preset classification loss function can be the cross-entropy loss function, the sub-loss can refer to the training loss corresponding to a single sample set, and the classification loss can refer to the training loss corresponding to N sample sets.
[0089] Specifically, in this embodiment, the personnel identifier corresponding to the training sample can be used as the identification label of the training sample, and correspondingly, the identification result can refer to the predicted personnel identifier of the training sample.
[0090] In one implementation, the implementer can use the attribute category corresponding to the training sample as the identification label of the training sample. The attribute category can refer to personnel attributes such as gender and age.
[0091] Based on the classification loss, the pre-trained source domain model is trained using the gradient descent method until the classification loss converges or the training reaches a preset number of training rounds, thus obtaining the target domain model. The gradient descent method can include stochastic gradient descent, batch gradient descent, etc. In this embodiment, the preset number of training rounds is set to 50.
[0092] In this embodiment, a classification task is used to train the model, which makes the model more expressive and thus improves the accuracy of human body weight recognition in target recognition scenarios.
[0093] Optionally, training the pre-trained source domain model based on the feature set of N corresponding sample sets to obtain the target domain model also includes:
[0094] For any sample set, the feature sub-loss of the corresponding sample set is calculated based on the feature set of the sample set and the preset triplet loss function. The feature sub-loss of the corresponding sample set is obtained by traversing all sample sets.
[0095] Accordingly, training the pre-trained human weight recognition model based on classification loss includes:
[0096] The sum of the feature sub-losses of all corresponding sample sets is determined as the feature loss. Based on the classification loss and feature loss, the pre-trained source domain model is trained to obtain the target domain model.
[0097] The preset triplet loss function can refer to Triplet loss, the feature loss can refer to the training loss corresponding to a single sample set, and the feature loss can refer to the training loss corresponding to N sample sets.
[0098] Specifically, the predefined triplet loss function L can be expressed as:
[0099] L=max(d(a,p)-d(a,n)+margin,0)
[0100] Where 'a' can refer to the final sample features of the training samples, 'p' can refer to the final sample features of the positive samples, 'n' can refer to the final sample features of the negative samples, and 'margin' can be a threshold greater than 0. In this embodiment, 'margin' is set to 1.
[0101] In this embodiment, the triplet loss function constrains the features of the training samples and positive samples to be sufficiently close, and constrains the features of the training samples and negative samples to be sufficiently far apart, so that the features learned by the model are more discriminative, thereby improving the accuracy of human body weight recognition in target recognition scenarios.
[0102] Optionally, the sample construction method also includes:
[0103] Obtain a test set for the target human recognition scenario, randomly sample a preset number of test samples from the test set to form a test subset, and statistically obtain the mean and variance of the test subset;
[0104] The test set is batch normalized using mean and variance. Based on the batch normalized test set, the cross-domain training results of the pre-trained source domain model are tested. When the accuracy obtained from the test is greater than a preset threshold, the cross-domain training result is determined to be the target domain model.
[0105] The test set is used to test the trained model to ensure it can be applied to target recognition scenarios. The test set can include several test samples; a test subset refers to a set containing a portion of the test samples; the preset quantity refers to the number of test samples; batch normalization refers to normalizing each test sample in the test set based on the mean and variance of all test samples. Accuracy is the ratio of the number of correctly re-identified test samples to the total number of test samples. The preset threshold is used to measure whether the trained model has a high accuracy rate in human re-identification.
[0106] Specifically, in this embodiment, the preset quantity can be set to 500. Existing re-identification models use the mean and variance of the training set in real time during batch normalization processing, and use the momentum accumulation method to obtain the mean and variance of the global training data. They directly use the fixed mean and variance based on the global training data to transfer to the test set. However, in the application scenario of this embodiment, the model needs to be applied across domains. Therefore, the human images in the training set pre-trained by the source domain model and the cross-domain trained test set are quite different, and the data distribution transferability from the training set to the test set is poor.
[0107] Implementers can also use precision, recall, etc. to validate the trained model. Precision can be the ratio of the number of test samples that correctly identify a person to the total number of test samples that correctly identify a person. Recall can be the ratio of the number of test samples that actually identify a person to the total number of test samples that actually identify that person.
[0108] In this embodiment, the preset threshold is set to 0.6. If precision, recall, or other metrics are used to validate the trained model, a corresponding threshold also needs to be set, for example, it can also be set to 0.6.
[0109] In this embodiment, the mean and variance are dynamically calculated during testing, unlike the fixed values in traditional methods. This allows the cross-domain training results to be recognized as the target domain model only when they are adapted to the target recognition scenario, thereby improving the accuracy of the target domain model in human body recognition scenarios.
[0110] The above steps, which involve constructing a sample set using training samples, positive samples, and negative samples, and iterating through N person identifiers to obtain N sample sets, build a sample set that is difficult to distinguish in the target human body recognition scenario for model training. This enables cross-domain learning between different human body recognition scenarios and improves the model's accuracy in human body weight recognition in the target human body recognition scenario.
[0111] In this embodiment, in the target human body recognition scenario, a sample combination with higher discrimination difficulty is determined based on the similarity of the reference image. This sample combination is used to retrain the source domain model pre-trained in the initial human body recognition scenario, thereby improving the model's discrimination ability in the target scenario, realizing cross-domain learning between different human body recognition scenarios, and improving the accuracy of human body weight recognition of the model when used across domains.
[0112] See Figure 3 This is a flowchart illustrating a sample construction method for cross-domain model training provided in Embodiment 2 of the present invention. In this sample construction method for cross-domain model training, human images acquired by an image acquisition device can be used directly as samples, or the acquired human images can be preprocessed and the preprocessing results can be used as samples.
[0113] When using human images acquired directly from image acquisition devices as samples, please refer to Example 1, which will not be repeated here.
[0114] The process of preprocessing the acquired human images and using the preprocessed results as samples includes the following steps:
[0115] Step S301: Randomly select at least two human images from the human image set corresponding to the personnel identifier to obtain a first image to be processed and at least one second image to be processed; randomly select at least one human image from the human image set corresponding to the negative example identifier to obtain at least one third image to be processed.
[0116] Step S302: Randomly sample a first preprocessing method from a preset set of preprocessing methods, and perform image processing on the first image to be processed according to the first preprocessing method to obtain training samples;
[0117] Step S303: Randomly sample the second preprocessing method from the preprocessing method set, and perform image processing on all the second images to be processed according to the second preprocessing method to obtain positive sample;
[0118] Step S304: Randomly sample the third preprocessing method from the preprocessing method set, and perform image processing on all third images to be processed according to the third preprocessing method to obtain negative sample.
[0119] The set of preprocessing methods can include data augmentation methods such as random channel swapping, random grayscale conversion, random color transformation, and random portrait segmentation. The first, second, and third preprocessing methods are all randomly sampled from the set of preprocessing methods.
[0120] Specifically, due to interference factors such as dark current noise, color difference, distortion, and fixed shooting background in image acquisition equipment, the acquired human body images inevitably contain such impurity information. This causes the model to focus too much on such impurity information during training, making it difficult for the model to extract effective features and achieve more accurate human body weight recognition.
[0121] In this embodiment, data augmentation methods are used to preprocess the acquired human images, making the distribution of such impurity information more uniform among the images, thereby mitigating the influence of interference factors and improving the training efficiency of the model and the accuracy of human body weight recognition.
[0122] Corresponding to the sample construction method for cross-domain model training in the above embodiments, Figure 4 A structural block diagram of a sample construction device for cross-domain model training provided in Embodiment 3 of the present invention is shown. This sample construction device is applied to a client, and the computer device corresponding to the client is connected to a server. The server is deployed in the initial human recognition scenario. The computer device corresponding to the client obtains a pre-trained source domain model from the server. The computer device corresponding to the client is then deployed in the target human recognition scenario and connected to an image acquisition device to obtain human images acquired by the image acquisition device. For ease of explanation, only the parts relevant to the embodiments of the present invention are shown.
[0123] See Figure 4 The sample construction apparatus for cross-domain model training includes:
[0124] The set partitioning module 41 is used to obtain at least one human image and its corresponding person identifier in the target human recognition scenario, and to form a human image set by combining human images belonging to the same person identifier in all human images, so as to obtain N human image sets corresponding to person identifiers, where N is an integer greater than zero.
[0125] The image selection module 42 is used to randomly select a human image from the human image set corresponding to each person identifier as the reference image of the corresponding person identifier, so as to obtain the reference image corresponding to each person identifier.
[0126] The identifier determination module 43 is used to determine the top I target images that are most similar to the reference images corresponding to other personnel identifiers from the reference images corresponding to other personnel identifiers based on the similarity between reference images, and to use the personnel identifiers corresponding to all target images as negative example identifiers, where I is an integer greater than zero and less than N.
[0127] The sample selection module 44 is used to randomly select at least two human images from the human image set corresponding to the personnel identifier, use one as a training sample and the others as positive samples, and randomly select at least one human image from the human image set corresponding to the negative sample identifier as a negative sample.
[0128] The set construction module 45 is used to construct a sample set with training samples, positive samples and negative samples. It iterates through N personnel identifiers to obtain N sample sets. The N sample sets are used to perform cross-domain training on the source domain model pre-trained in the initial human recognition scenario to obtain the target domain model for the target recognition scenario.
[0129] Optionally, the above-mentioned sample construction apparatus further includes:
[0130] The cross-domain training module is used to train a pre-trained source domain model across domains based on N sample sets to obtain a target domain model.
[0131] Optionally, the pre-trained source domain model includes a pre-trained feature extraction layer;
[0132] The aforementioned cross-domain training module includes:
[0133] The feature extraction submodule is used to extract features from a pre-trained feature extraction layer for any sample set, taking the training samples, positive samples and negative samples in the sample set as input samples respectively, and obtaining the initial sample features of the corresponding input samples.
[0134] The normalization submodule is used to perform instance normalization on the initial sample features, perform pooling on the instance normalization result, determine the pooling result as the final sample feature of the corresponding input sample, and determine the feature set of the corresponding sample set composed of the final sample features of all corresponding input samples.
[0135] The model training submodule is used to traverse all sample sets to obtain feature sets of N corresponding sample sets. Based on the feature sets of N corresponding sample sets, the pre-trained source domain model is trained to obtain the target domain model.
[0136] Optionally, the pre-trained source domain model also includes a pre-trained classification layer;
[0137] The above model training submodule includes:
[0138] The feature classification unit is used to input the final sample features corresponding to the training samples in any sample set into the pre-trained classification layer for feature classification, so as to obtain the recognition result of the training samples in the corresponding sample set.
[0139] The first loss calculation unit is used to obtain the recognition labels corresponding to the training samples in the sample set, calculate the sub-loss of the corresponding sample set based on the recognition results and recognition labels corresponding to the training samples in the sample set and the preset classification loss function, and traverse all sample sets to obtain the sub-loss of the corresponding sample set.
[0140] The loss training unit is used to determine the sum of the categorical sub-losses of all corresponding sample sets as the classification loss. Based on the classification loss, the pre-trained source domain model is trained to obtain the target domain model.
[0141] Optionally, the above model training submodule also includes:
[0142] The second loss calculation unit is used to calculate the feature sub-loss of any sample set based on the feature set of the sample set and the preset triplet loss function, and to traverse all sample sets to obtain the feature sub-loss of the corresponding sample set.
[0143] Accordingly, the aforementioned loss training unit includes:
[0144] The loss training subunit is used to determine the sum of the feature sub-losses of all corresponding sample sets as the feature loss. Based on the classification loss and feature loss, the pre-trained source domain model is trained to obtain the target domain model.
[0145] Optionally, the aforementioned cross-domain training module also includes:
[0146] The test set acquisition submodule is used to acquire the test set for the target human recognition scenario. A preset number of test samples are randomly sampled from the test set to form a test subset, and the mean and variance of the test subset are statistically obtained.
[0147] The model determination submodule is used to perform batch normalization on the test set using the mean and variance. Based on the batch-normalized test set, the cross-domain training results of the pre-trained source domain model are tested. When the accuracy obtained from the test is greater than a preset threshold, the cross-domain training result is determined as the target domain model.
[0148] Optionally, the sample selection module 44 mentioned above includes:
[0149] The random selection submodule is used to randomly select at least two human images from the human image set corresponding to the personnel identifier to obtain a first image to be processed and at least one second image to be processed, and to randomly select at least one human image from the human image set corresponding to the negative example identifier to obtain at least one third image to be processed.
[0150] The first processing submodule is used to randomly sample a first preprocessing method from a preset set of preprocessing methods, and perform image processing on the first image to be processed according to the first preprocessing method to obtain training samples;
[0151] The second processing submodule is used to randomly sample a second preprocessing method from a preset set of preprocessing methods, and perform image processing on all second images to be processed according to the second preprocessing method to obtain positive sample.
[0152] The third processing submodule is used to randomly sample from the preset set of preprocessing methods to obtain the third preprocessing method, and perform image processing on all the third images to be processed according to the third preprocessing method to obtain negative sample.
[0153] It should be noted that the information interaction and execution process between the above modules, sub-modules, units, and sub-units are based on the same concept as the method embodiments of the present invention. For details on their specific functions and technical effects, please refer to the method embodiments section, which will not be repeated here.
[0154] Figure 5 This is a schematic diagram of the structure of a computer device provided in Embodiment 4 of the present invention. Figure 5 As shown, the computer device of this embodiment includes: at least one processor ( Figure 5 Only one is shown in the diagram), a memory, and a computer program stored in the memory and capable of running on at least one processor, which, when executing the computer program, implements the steps in any of the above embodiments of the sample construction method for cross-domain training of the model.
[0155] This computer device may include, but is not limited to, a processor and memory. Those skilled in the art will understand that... Figure 5 The examples of computer devices are merely examples and do not constitute a limitation on computer devices. Computer devices may include more or fewer components than shown, or combinations of certain components, or different components, such as network interfaces, displays, and input devices.
[0156] The processor referred to can be a CPU, but it can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor.
[0157] Memory includes readable storage media, internal memory, etc., wherein internal memory can be the RAM of a computer device, providing an environment for the operation of the operating system and computer-readable instructions stored in the readable storage media. The readable storage media can be the hard drive of a computer device, or in other embodiments, it can be an external storage device of the computer device, such as a plug-in hard drive, Smart Media Card (SMC), Secure Digital (SD) card, or Flash Card. Furthermore, memory can include both internal storage units and external storage devices of a computer device. Memory is used to store the operating system, applications, bootloader, data, and other programs, such as program code for computer programs. Memory can also be used to temporarily store data that has been output or will be output.
[0158] Those skilled in the art will understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is used as an example. In practical applications, the functions described above can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this invention. The specific working process of the units and modules in the above device can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here. If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention can implement all or part of the processes in the methods of the above embodiments by instructing related hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the above method embodiments. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. A computer-readable medium can include at least: any entity or device capable of carrying computer program code, a recording medium, a computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media. Examples include USB flash drives, portable hard drives, magnetic disks, or optical disks. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electrical carrier signals or telecommunication signals.
[0159] The present invention can implement all or part of the processes in the methods of the above embodiments, or it can be accomplished by a computer program product. When the computer program product is run on a computer device, the computer device executes the steps in the above method embodiments.
[0160] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0161] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0162] In the embodiments provided by this invention, it should be understood that the disclosed apparatus / computer devices and methods can be implemented in other ways. For example, the apparatus / computer device embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0163] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0164] The above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.
Claims
1. A sample construction method for cross-domain model training, characterized in that, The sample construction method includes: Obtain at least one human image and its corresponding person identifier in the target human recognition scenario. Combine all human images belonging to the same person identifier into a human image set. A set of human images corresponding to individual identifiers. Integers greater than zero; Randomly select one human image from the set of human images corresponding to each person identifier as the reference image for the corresponding person identifier, and obtain the reference image corresponding to each person identifier; For any given person identifier, based on the similarity between reference images, determine the image most similar to the reference image corresponding to the given person identifier from the reference images corresponding to other person identifiers. For each target image, the personnel identifier corresponding to all target images is used as the negative example identifier. greater than zero and less than Integers; At least two human images are randomly selected from the set of human images corresponding to the personnel identifier, one of which is used as a training sample and the others as positive samples. At least one human image is randomly selected from the set of human images corresponding to the negative sample identifier as a negative sample. Construct a sample set using the training samples, the positive samples, and the negative samples, and iterate through them. Individual identification, obtained A set of samples, the A set of samples is used to perform cross-domain training on the source domain model pre-trained in the initial human recognition scenario to obtain the target domain model for the target human recognition scenario.
2. The sample construction method according to claim 1, characterized in that, The sample construction method further includes: According to the above A set of samples is used to perform cross-domain training on the pre-trained source domain model to obtain the target domain model.
3. The sample construction method according to claim 2, characterized in that, The pre-trained source domain model includes a pre-trained feature extraction layer; According to the A set of samples is used to perform cross-domain training on the pre-trained source domain model to obtain the target domain model, which includes: For any sample set, the training samples, positive samples, and negative samples in the sample set are used as input samples, and the input samples are fed into the pre-trained feature extraction layer for feature extraction to obtain the initial sample features of the corresponding input samples. The initial sample features are normalized, the normalized result is pooled, and the pooling result is determined as the final sample feature of the corresponding input sample. The final sample features of all corresponding input samples are determined to form the feature set of the corresponding sample set. Iterate through all sample sets to obtain The feature set of each corresponding sample set, according to the The feature set of each corresponding sample set is used to train the pre-trained source domain model to obtain the target domain model.
4. The sample construction method according to claim 3, characterized in that, The pre-trained source domain model also includes a pre-trained classification layer; According to the The target domain model is obtained by training the pre-trained source domain model with a feature set corresponding to a sample set, and then training the pre-trained source domain model with the feature set of the sample set. For any set of samples, the final sample features corresponding to the training samples in the set of samples are input into the pre-trained classification layer for feature classification to obtain the recognition result of the corresponding training samples in the set of samples. Obtain the recognition labels corresponding to the training samples in the sample set. Based on the recognition results and recognition labels corresponding to the training samples in the sample set and the preset classification loss function, calculate the sub-loss of the corresponding sample set. Traverse all sample sets to obtain the sub-loss of the corresponding sample set. The sum of the sub-losses of all corresponding sample sets is determined as the classification loss. Based on the classification loss, the pre-trained source domain model is trained to obtain the target domain model.
5. The sample construction method according to claim 4, characterized in that, According to the The method for training the pre-trained source domain model using a feature set corresponding to a sample set to obtain the target domain model further includes: For any sample set, the feature sub-loss corresponding to the sample set is calculated based on the feature set of the sample set and the preset triplet loss function. The feature sub-loss of the corresponding sample set is obtained by traversing all sample sets. Accordingly, training the pre-trained human weight recognition model based on the classification loss includes: The sum of the feature sub-losses of all corresponding sample sets is determined as the feature loss. Based on the classification loss and the feature loss, the pre-trained source domain model is trained to obtain the target domain model.
6. The sample construction method according to claim 2, characterized in that, The sample construction method further includes: Obtain a test set for the target human recognition scenario, randomly sample a preset number of test samples from the test set to form a test subset, and statistically obtain the mean and variance of the test subset; The test set is batch normalized using the mean and variance. Based on the batch normalized test set, the cross-domain training result of the pre-trained source domain model is tested. When the accuracy obtained from the test is greater than a preset threshold, the cross-domain training result is determined to be the target domain model.
7. The sample construction method according to any one of claims 1 to 6, characterized in that, The step of randomly selecting at least two human images from the set of human images corresponding to the personnel identifier, using one as a training sample and the others as positive examples, and randomly selecting at least one human image from the set of human images corresponding to the negative example identifier as a negative example sample includes: At least two human images are randomly selected from the human image set corresponding to the personnel identifier to obtain a first image to be processed and at least one second image to be processed. At least one human image is randomly selected from the human image set corresponding to the negative example identifier to obtain at least one third image to be processed. The first preprocessing method is randomly sampled from a preset set of preprocessing methods, and the first image to be processed is processed according to the first preprocessing method to obtain the training sample. A second preprocessing method is randomly sampled from the set of preprocessing methods, and image processing is performed on all the second images to be processed according to the second preprocessing method to obtain the positive sample. A third preprocessing method is randomly sampled from the set of preprocessing methods, and image processing is performed on all third images to be processed according to the third preprocessing method to obtain the negative sample.
8. A sample construction apparatus for cross-domain model training, characterized in that, The sample construction apparatus includes: The set partitioning module is used to acquire at least one human image and its corresponding person identifier in the target human recognition scenario, and to group human images belonging to the same person identifier into a human image set, thus obtaining... A set of human images corresponding to individual identifiers. Integers greater than zero; The image selection module is used to randomly select a human image from the human image set corresponding to each person identifier as the reference image for the corresponding person identifier, so as to obtain the reference image corresponding to each person identifier. The identifier determination module is used to, for any given person identifier, determine the most similar reference image from the reference images corresponding to other person identifiers based on the similarity between reference images. For each target image, the personnel identifier corresponding to all target images is used as the negative example identifier. greater than zero and less than Integers; The sample selection module is used to randomly select at least two human images from the human image set corresponding to the personnel identifier, use one as a training sample and the others as positive samples, and randomly select at least one human image from the human image set corresponding to the negative sample identifier as a negative sample. The set construction module is used to construct a sample set using the training samples, the positive samples, and the negative samples, and to iterate through them. Individual identification, obtained A set of samples, the A set of samples is used to perform cross-domain training on the source domain model pre-trained in the initial human recognition scenario to obtain the target domain model for the target human recognition scenario.
9. A computer device, characterized in that, The computer device includes a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the sample construction method as described in any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the sample construction method as described in any one of claims 1 to 7.