Image recognition method and device, equipment and storage medium
By jointly training student models with multiple teacher models and utilizing mean squared error loss and mask generative loss, the feature recognition accuracy of access control and attendance devices is improved, solving the problems of misjudgment and rejection in existing technologies.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-01-14
- Publication Date
- 2026-04-10
AI Technical Summary
Existing access control and attendance systems suffer from misjudgments and rejections when faced with a large number of user IDs and registration databases, resulting in low accuracy in feature recognition.
An image recognition method is adopted, which uses a preset recognition model trained by a student model and at least two teacher models, and uses mean squared error loss and mask generative loss to guide the training of the student model, thereby improving the feature recognition accuracy.
It improves the accuracy of feature recognition in image recognition, reduces the false judgment rate, and enhances the recognition capabilities of access control and attendance equipment.
Smart Images

Figure CN121837652A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image recognition technology, and in particular to an image recognition method, apparatus, device and storage medium. Background Technology
[0002] Existing access control and attendance systems use neural network models to extract user features for access control recognition, which has a high recognition rate and a low false positive rate. However, when faced with an increase in the number of user IDs and the number of registration records, some false positives and rejections still occur, resulting in low feature recognition accuracy. Summary of the Invention
[0003] This application provides an image recognition method, apparatus, device, and storage medium, which can improve the accuracy of feature recognition and thus enhance the image algorithm recognition capability.
[0004] In one aspect, this application provides an image recognition method, the method comprising:
[0005] A user's image to be identified is collected, and the image is input into a preset recognition model for feature extraction to obtain user features. The preset recognition model is trained based on a student model and at least two teacher models. The mean squared error loss calculated from the student feature vector of the student model and the first teacher feature vector of the first teacher model, as well as the mask generative loss calculated from the student feature tensor of the student model and the teacher feature tensor of the second teacher model, are used to calculate the total loss to train the student model.
[0006] Image recognition results are obtained based on the user characteristics.
[0007] In some embodiments of this application, the method further includes:
[0008] The training process involves extracting a first teacher feature vector from the training set using a first teacher model, extracting a teacher feature tensor from the training set using a second teacher model, and extracting student feature vectors and student feature tensors from the training set using a student model. The student feature tensor is obtained by stacking a batch of student feature tensors, and the teacher feature tensor is obtained by stacking the batch of second teacher feature tensors from the second teacher model.
[0009] The mean squared error loss is calculated using the student feature vector and the first teacher feature vector; the category loss is calculated using the student feature vector and the category labels corresponding to the training set; and the mask generative loss is calculated using the student feature tensor and the teacher feature tensor.
[0010] The total loss is calculated using the mean squared error loss, the category loss, and the mask generative loss.
[0011] The model parameters of the student model are updated using the total loss until the student model converges, and the resulting trained student model is used as the preset recognition model.
[0012] In another aspect, this application provides an image recognition device, the device comprising:
[0013] An image feature extraction module is used to acquire a user's image to be identified, input the image to be identified into a preset recognition model for feature extraction, and obtain user features. The preset recognition model is trained based on a student model and at least two teacher models. The mean squared error loss calculated from the student feature vector of the student model and the first teacher feature vector of the first teacher model, as well as the mask generative loss calculated from the student feature tensor of the student model and the teacher feature tensor of the second teacher model, are used to calculate the total loss to train the student model.
[0014] An image recognition module is used to obtain image recognition results based on the user characteristics.
[0015] In some embodiments of this application, the apparatus further includes:
[0016] The feature extraction module is used to extract a first teacher feature vector from the training set using a trained first teacher model, extract a teacher feature tensor from the training set using a trained second teacher model, and extract student feature vectors and student feature tensors from the training set using a student model; wherein the student feature tensor is obtained by stacking a batch of student feature tensors, and the teacher feature tensor is obtained by stacking the batch of second teacher feature tensors of the second teacher model;
[0017] The loss calculation module is used to calculate the mean squared error loss using the student feature vector and the first teacher feature vector, calculate the category loss using the student feature vector and the category label corresponding to the training set, and calculate the mask generative loss using the student feature tensor and the teacher feature tensor; and calculate the total loss using the mean squared error loss, the category loss, and the mask generative loss.
[0018] The parameter update module is used to update the model parameters of the student model through the total loss until the student model converges, and the trained student model is used as the preset recognition model.
[0019] In another aspect, this application also provides an electronic device, including: a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program, when executed by the processor, implements any of the image recognition methods described above.
[0020] In another aspect, this application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements any of the image recognition methods described above.
[0021] In another aspect, this application also provides a computer program product containing instructions that, when run on a computer, cause the computer to perform the image recognition methods described in the above aspects.
[0022] The image recognition method, apparatus, device, and storage medium provided in this application extract features by inputting the user's image to be recognized into a preset recognition model, and obtains the image recognition result based on the extracted user features. The preset recognition model used for feature extraction is trained based on a student model and at least two teacher models. It is mainly obtained by training the student model using the mean squared error loss calculated based on the student feature vector of the student model and the first teacher feature vector of the first teacher model, as well as the mask generative loss calculated based on the student feature tensor of the student model and the teacher feature tensor of the second teacher model. By having at least two teacher models guide the student model, the learning behavior of the teacher model, which has a complex network structure, a large number of parameters, and strong learning ability, is transferred to the student model, which has a simple network structure, a small number of parameters, and weak learning ability, thereby improving the feature recognition ability of the student model. Furthermore, the mean squared error loss in the total loss used to train the student model is calculated by combining the features extracted by the student model with the features extracted by one teacher model, and the mask generative loss used to train the student model is calculated by combining the features extracted by the student model with the features extracted by another teacher model. By using two teacher models with different architectures and guiding the training of the student model through joint feature loss, the similarity difference between the features extracted by the student model and the features extracted by at least two teacher models is minimized, thereby improving the feature recognition ability of the student model and thus improving the feature recognition accuracy of image recognition and reducing the false positive rate. Attached Figure Description
[0023] Figure 1 This is a flowchart illustrating the steps of an image recognition method provided in an embodiment of this application;
[0024] Figure 2 This is a flowchart illustrating the steps of a recognition model training method provided in an embodiment of this application;
[0025] Figure 3This is a schematic diagram illustrating the training of the recognition model provided in an embodiment of this application;
[0026] Figure 4 This is a structural block diagram of an image recognition device provided in an embodiment of this application;
[0027] Figure 5 This is a structural block diagram of an electronic device provided in an embodiment of this application;
[0028] Figure 6 This is a structural block diagram of a computer-readable storage medium provided in an embodiment of this application. Detailed Implementation
[0029] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0030] This application embodiment improves the feature recognition ability of the student model by having at least two teacher models guide the student model. This transfers the learning behavior of the teacher model (complex network structure, large number of parameters, and strong learning ability) to the student model (simple network structure, few parameters, and weak learning ability). Furthermore, the mean squared error loss in the total loss used to train the student model is calculated by combining the features extracted by the student model with those extracted by a teacher model. Similarly, the mask generative loss used to train the student model is calculated by combining the features extracted by the student model with those extracted by another teacher model. By using two teacher models with different architectures and guiding the student model training through joint feature loss, the similarity difference between the features extracted by the student model and those extracted by at least two teacher models is minimized, improving the feature recognition ability of the student model and thus increasing the feature recognition accuracy of image recognition while reducing the false positive rate.
[0031] Reference Figure 1 This document illustrates a flowchart of an image recognition method provided in an embodiment of this application, focusing on the application process of the recognition model, which may specifically include the following steps:
[0032] Step S101: Collect the user's image to be identified, input the image to be identified into a preset recognition model for feature extraction, and obtain the user's features.
[0033] Optionally, the image recognition method provided in this application embodiment can be applied to any device with image recognition function, such as access control equipment, attendance equipment, etc. The user image to be recognized collected may include image data related to identity recognition such as face, palm print, fingerprint, etc. Specifically, image acquisition can be achieved through the acquisition device installed on the aforementioned device with image recognition function, and this application embodiment does not limit this.
[0034] In some embodiments of this application, the device with image recognition function may also have a preset recognition model deployed locally. This preset recognition model can be mainly used to extract user features of the image to be recognized for image recognition.
[0035] The pre-defined recognition model deployed by the device can be trained based on one student model and at least two teacher models. Specifically, the mean squared error loss calculated from the student feature vector of the student model and the first teacher feature vector of the first teacher model, as well as the mask generative loss calculated from the student feature tensor of the student model and the teacher feature tensor of the second teacher model, can be used to calculate the total loss to train the student model.
[0036] In the training process of the preset recognition model, there exists a first teacher model that outputs a two-dimensional feature vector, and a second teacher model that outputs a four-dimensional feature tensor. The first and second teacher models have different model structures. There is also a student model with two outputs: a two-dimensional feature vector and a four-dimensional feature tensor. The first teacher model is used to calculate the mean squared error loss, and the second teacher model is used to calculate the mask generative loss. Using these two teacher models with different architectures, the student model is trained through joint feature loss, updating its model parameters until it converges to its optimal state. This minimizes the similarity difference between the features extracted by the student model and those extracted by at least two teacher models, resulting in the preset recognition model. The trained student model can then be used as the preset recognition model for image recognition.
[0037] For example, when using facial features for access control recognition, the training set during training is a set of facial images, and the teacher model is a deep convolutional neural network model trained using the facial training images. Similarly, when using palm features for access control recognition, the training set during training is a set of palm images, and the teacher model is a deep convolutional neural network model trained using the palm training images. Specifically, facial training images can be obtained from existing publicly available facial datasets, or palm training images can be obtained from existing publicly available palm datasets. It should be noted that the facial images or palm images used in this embodiment are legally authorized or obtained with the consent of the parties involved, and this embodiment does not impose any limitations on their use.
[0038] Step S102: Obtain image recognition results based on user characteristics.
[0039] After extracting user features, the similarity between the user features and the user feature vectors stored in the device database can be calculated. If the similarity exceeds a preset threshold, the image recognition result can be obtained, and then corresponding operations can be performed based on the image result.
[0040] In practical applications, after extracting user features, such as facial features and palm features, the similarity between the user features and various feature vectors stored in the device database, such as facial feature vectors and palm feature vectors, can be calculated. Then, based on the calculated similarity, user feature vectors that exceed a preset threshold are selected, and the user feature vector with the highest similarity is selected for image recognition.
[0041] As an example, assuming the device is an access control device, it can output the identity category corresponding to the user feature vector with the highest similarity and open the access control device; as another example, assuming the device is an attendance device, it can output the identity category corresponding to the user feature vector with the highest similarity and perform the user's check-in operation, thus completing the image recognition of the user.
[0042] Optionally, the device can maintain an attendance or access control database. Users can register by inputting facial or palm feature vectors and identity information, allowing the access control database to store the correspondence between user feature vectors and identity categories. Based on this correspondence, the identity category corresponding to the user feature vector with the highest similarity is extracted as the user's identity category in the image to be identified. If the current user is an unregistered user, i.e., the database does not store the user's user feature vector and identity information, and the similarity obtained during user feature similarity calculation does not exceed a preset threshold, the access control device can provide a voice prompt that the current user is an outsider, or the attendance device can provide a voice prompt that no user exists. This application embodiment does not impose any limitations on this.
[0043] In this embodiment, the user's image to be identified is input into a preset recognition model for feature extraction, so as to obtain the image recognition result based on the extracted user features. The preset recognition model used for feature extraction is trained based on a student model and at least two teacher models. It can be mainly obtained by training the student model using the mean squared error loss calculated based on the student feature vector of the student model and the first teacher feature vector of the first teacher model, as well as the mask generative loss calculated based on the student feature tensor of the student model and the teacher feature tensor of the second teacher model. By having at least two teacher models guide the student model, the learning behavior of the teacher model, which has a complex network structure, a large number of parameters, and strong learning ability, is transferred to the student model, which has a simple network structure, a small number of parameters, and weak learning ability, thereby improving the feature recognition ability of the student model. Furthermore, the mean squared error loss in the total loss used to train the student model is calculated by combining the features extracted by the student model with the features extracted by one teacher model, and the mask generative loss used to train the student model is calculated by combining the features extracted by the student model with the features extracted by another teacher model. By using two teacher models with different architectures and guiding the training of the student model through joint feature loss, the similarity difference between the features extracted by the student model and the features extracted by at least two teacher models is minimized, thereby improving the feature recognition ability of the student model and thus improving the feature recognition accuracy of image recognition and reducing the false positive rate.
[0044] Reference Figure 2 This document illustrates a flowchart of a recognition model training method provided in an embodiment of this application, focusing on the training process of the recognition model, which may specifically include the following steps:
[0045] Step S201: Extract the first teacher feature vector from the training set using the trained first teacher model, extract the teacher feature tensor from the training set using the trained second teacher model, and extract the student feature vector and student feature tensor from the training set using the student model.
[0046] In this embodiment, a mask generative distillation training method is proposed. By using mean squared error loss and mask generative loss, the similarity difference between the student features of the student model and the teacher features of at least two teacher models is minimized to train the student model. Simultaneously, the model parameters of the student model are updated until they are optimal. The model parameters of the teacher models are not updated, and the model structures of at least two teacher models are different.
[0047] Optionally, a pre-trained deep convolutional neural network can be used as the first teacher model to extract features from the training images in the training set, thereby obtaining the first teacher feature vector. First teacher eigenvector The shape is [B, d1], where B is the batch size and d1 is the dimension of the first teacher's feature vector.
[0048] The student feature vector is extracted from the training images in the training set using the student model to be trained. Student feature vector The shape is [B, d2], where B is the batch size and d2 is the dimension of the student feature vectors. A batch of B student feature tensors can be used to construct a student feature tensor, which is four-dimensional. Specifically, it can be obtained by composing batches based on B student feature slices. Student feature tensor The shape is [B,D1,h,w], where D1 is the dimension of the student feature tensor, and h and w are the height and width, respectively, used to indicate the image resolution. Optionally, the student feature tensor used to calculate the mask generative loss in this embodiment can be obtained by stacking individual student feature tensors [D1,h,w] using the torch.stack command. When the torch.stack parameter dim=0, it can be stacked into a four-dimensional tensor. It should be noted that an existing lightweight convolutional neural network can be used as the student model, or a new lightweight convolutional neural network can be constructed as the student model. This embodiment does not limit this.
[0049] The trained second deep convolutional neural network model is used to extract features from the training images in the training set to obtain the second teacher feature vector. Second teacher feature vector The shape is [B, d3], where B is the batch size and d3 is the dimension of the second teacher feature vector. A batch of B second teacher feature tensors can be used to construct a teacher feature tensor, which is four-dimensional. Specifically, it can be obtained by composing batches based on B slices of second teacher features. Teacher feature tensor The shape is [B,D2,h,w], where D2 is the dimension of the teacher feature tensor, and h and w are the height and width, respectively, used to indicate the image resolution. Optionally, the teacher feature tensor used to calculate the mask generative loss in this embodiment can be obtained by stacking individual teacher feature tensors [D2,h,w] using the torch.stack command. When the torch.stack parameter dim=0, it can be stacked into a four-dimensional tensor.
[0050] Feature slicing refers to saving feature data as a file, which can be read into memory during training. This method can save GPU resources and speed up training. Alternatively, features can be generated online by directly calling the teacher model. This application does not limit this approach.
[0051] It should be noted that the model structure of the first teacher model is different from that of the second teacher model. For example, one is a transformer model and the other is a CNN model; and the feature dimension d1 of the first teacher model is also different from that of the second teacher model.
[0052] During training, the training images in the training set can be input into the first teacher model, the second teacher model, and the student model in batches according to the batch size.
[0053] Step S202: Calculate the mean squared error loss using the student feature vector and the first teacher feature vector; calculate the class loss using the student feature vector and the corresponding class labels in the training set; and calculate the mask generative loss using the student feature tensor and the teacher feature tensor.
[0054] The extracted student feature vector and the first teacher feature vector are two-dimensional feature vectors, while the extracted student feature tensor and teacher feature tensor are four-dimensional feature tensors. During training, the mean squared error loss of the two feature vectors for a batch size, as well as the mask generative loss of the two feature tensors, are calculated to jointly guide the training of the student model.
[0055] Optional, student feature vector dimensional d2 and the first teacher feature vector The dimension d1 is the same.
[0056] The loss due to the mean squared error can be calculated using the first teacher eigenvector. and student feature vectors The sum of the equal parts of the differences, divided by the sample size, is used to calculate the mean squared error loss. For example, this is the mean squared error loss. The formula for calculating can be shown below:
[0057]
[0058] In the formula, the i-th feature is selected in order of the number of samples in a batch, and N is the number of samples.
[0059] For student feature vectors The class labels corresponding to the training set can be used to calculate the class loss L based on existing ArcFace Loss, CosFace loss, or AdaFace loss functions, or other softmax-based loss functions. arc However, the embodiments in this application do not impose any limitations on this.
[0060] Optional, student feature tensor Dimension D1 and teacher feature tensor Since the dimensions D2 are different, dimension alignment can be performed.
[0061] Specifically, this can be achieved by performing a convolutional mapping on the student feature tensor, that is, aligning the dimensions of the student feature tensor with the dimensions of the teacher feature tensor after convolutional mapping. Specifically, the convolution operation aligns the dimensions of the student feature tensor with the dimensions of the teacher feature tensor, making them the same dimension. Here, the input channel of the convolution operation is the student feature tensor. The dimension D1, and the output channel is the teacher feature tensor The dimension D2 of the convolution tensor is (1,1), which makes the student feature tensor... The shape changes from [B,D1,h,w] to [B,D2,h,w], denoted as For example, the pseudocode could be as follows:
[0062] Layer=nn.Conv2d(D1,D2,kernel_size=1,stride=1,padding=0)
[0063] =[B,D1,h,w]
[0064] =layer( )-->[B,D2,h,w].
[0065] After obtaining the dimension-aligned student feature tensor Then, the mask generative loss can be calculated.
[0066] To calculate the generative loss of the mask, firstly, a mask tensor can be randomly generated. Then, the student feature tensor, after being dimensionally aligned by the dot product of the mask tensor, is calculated. Obtain the masked student feature tensor Since the masking operation is performed on the dimension-aligned student feature tensor... The masked student feature tensor was performed. The dimension is also the same as the teacher feature tensor. Dimensional alignment; then, the masked student feature tensor can be used. and teacher feature tensor The feature deviations between the features are used to calculate the mask generative loss.
[0067] The generation process of the mask tensor can be represented by comparing the eigenvalues at each position (i, j) in the student feature tensor with the preset first threshold. In one case, if the eigenvalue at position (i, j) in the second feature tensor is less than the preset first threshold, a random number can be generated within a preset range and used as the mask value at position (i, j) in the mask tensor. In another case, if the eigenvalue at position (i, j) in the second feature tensor is greater than or equal to the preset first threshold, the mask value at position (i, j) in the mask tensor can be set to a preset value.
[0068] For example, the shape of the randomly generated mask tensor mask is [B,D2,1,1], and its element representation can be shown by the following formula:
[0069]
[0070] In the formula, These are the elements in the i-th row and j-th column of the mask, where 'a' can be a random number between [0, 0.1]. It is a student feature tensor. It is a preset first threshold, and the value range can be (0, 0.5).
[0071] So, the masked student feature tensor Equal to the dimension-aligned student feature tensor The dot product of the mask tensor (mask) can be calculated using the following formula:
[0072]
[0073] Furthermore, a set of convolutional mappings can be used to enhance the expressive power of the masked student feature tensor, enabling it to learn more complex features, thus obtaining the student feature tensor after convolutional mapping. For example, the specific calculation formula can be as follows:
[0074]
[0075] In the formula, Where conv is a convolutional layer and ReLU is an activation function. This application does not impose any limitations on this.
[0076] So, mask generative loss The formula for calculating can be shown below:
[0077]
[0078] Step S203: Calculate the total loss using the mean squared error loss, category loss, and mask generative loss.
[0079] In some embodiments of this application, the calculation of the total loss can be expressed as comparing the number of training rounds of the student model with the size of a preset second threshold, and different calculation formulas are used to calculate the total loss based on different comparison results.
[0080] In one scenario, if the number of training rounds for the student model is less than a preset second threshold, then the mean squared error loss can be adjusted. Category loss L arc and mask generative loss We perform a weighted summation to obtain the first total loss; in another case, if the number of training rounds of the student model is greater than or equal to a preset second threshold, then we can adjust the category loss L. arc and masked generation loss We perform a weighted summation to obtain the second total loss.
[0081] like Figure 3 As shown, for example, the formula for calculating the total loss L can be as follows:
[0082]
[0083] In the formula, a, b, and c are weights, a+b+c=1, and the specific values are determined by experimental or empirical values; epoch is the training round; num is the preset second threshold, which is usually a positive integer. It can be a constant or dynamically adjusted, and the embodiments of this application do not limit it.
[0084] Step S204: Update the model parameters of the student model using the total loss until the student model converges, and use the trained student model as the preset recognition model.
[0085] In this embodiment, the model parameters of the student model are updated by calculating the total loss until the student model converges, thus obtaining a trained student model. The trained student model is then used as a preset recognition model, and the preset recognition model is deployed to relevant devices for image recognition.
[0086] During training, the mean squared error loss of two feature vectors and the mask generative loss of two feature tensors in a batch can be calculated to jointly guide the training of the student model, update the model parameters of the student model, and improve the student model until the model parameters reach the optimal level.
[0087] In some embodiments of this application, when the number of training rounds is less than a preset second threshold, the model parameters of the student model can be updated using the first total loss; when the number of training rounds is greater than or equal to the preset second threshold, the model parameters of the student model can be updated using the second total loss.
[0088] The total loss can be dynamically adjusted based on the performance of the validation set. Specifically, when the improvement in the validation set loss or metric (such as accuracy) is lower than a preset second threshold (e.g., relative change <1% for 3 consecutive rounds), the model can be considered to have initially converged, and the process is triggered. to This switching strategy avoids the problems of premature or late switching caused by a fixed number of rounds.
[0089] During training, in the initial stage, such as the first 20% to 30% of training rounds, the total loss can be set. ,use The lost strong gradient signal converges rapidly, while simultaneously enhancing robustness; in the mid-to-late stages, when When the loss value drops to within half of its original range, it indicates that the error distribution tends to stabilize, and it can be switched to... To improve the final accuracy, adaptive computation based on the characteristics of the loss function is achieved. It should be noted that the model parameters of the teacher model are not updated during training, but the loss is calculated in real time for each batch; however, the specific process of updating the model parameters is not limited in this embodiment.
[0090] Taking palm features as an example, the evaluation metrics of experimental data without using the image recognition method provided in this application (as baseline data) and experimental data using the image recognition method provided in this application (as optimized data) can be compared as shown in Table 1 below. The evaluation metrics may include equal error rate (EER), false acceptance rate (FAR), and false rejection rate (FRR), etc.
[0091] Table 1 Comparison of Image Recognition Evaluation Metrics
[0092]
[0093] As shown above, although both sets of data conform to the principle that a lower false acceptance rate (FAR) corresponds to a higher false rejection rate (FRR), meaning that an increase in security level is accompanied by a certain increase in the false rejection rate, the image recognition method provided in this application can optimize the palm feature extraction / matching logic, significantly reducing the false rejection rate (FRR) under the same FAR constraint and improving recognition accuracy. Specifically, in a high-security scenario (i.e., FAR ≤ 1e-5), when FAR = 1e-5 (only one false acceptance is allowed per 100,000 verifications), the false rejection rate (FRR) decreases from 0.8383% to 0.4981%, with an absolute improvement of 0.34 percentage points and a relative improvement of over 40%, indicating that the image recognition method provided in this application can improve palmprint recognition performance.
[0094] In this embodiment, by having at least two teacher models guide the student model, the learning behavior of the teacher model, which has a complex network structure, a large number of parameters, and strong learning ability, is transferred to the student model, which has a simple network structure, a small number of parameters, and weak learning ability, thereby improving the feature recognition ability of the student model. Furthermore, the mean squared error loss in the total loss used to train the student model is calculated by combining the features extracted by the student model with the features extracted by a certain teacher model, and the mask generative loss used to train the student model is calculated by combining the features extracted by the student model with the features extracted by another teacher model. By using two teacher models with different architectures and guiding the training of the student model through joint feature loss, the similarity difference between the features extracted by the student model and the features extracted by at least two teacher models is minimized, thereby improving the feature recognition ability of the student model, improving the feature recognition accuracy of image recognition, and reducing the false positive rate.
[0095] It should be noted that, for the sake of simplicity, the method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments of this application are not limited to the described order of actions, because according to the embodiments of this application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of this application.
[0096] Reference Figure 4 The diagram shows a structural block diagram of an image recognition device provided in an embodiment of this application, which may specifically include the following modules:
[0097] The image feature extraction module 401 is used to acquire the user's image to be identified, input the image to be identified into a preset recognition model for feature extraction, and obtain user features. The preset recognition model is trained based on a student model and at least two teacher models. The mean squared error loss calculated from the student feature vector of the student model and the first teacher feature vector of the first teacher model, and the mask generative loss calculated from the student feature tensor of the student model and the teacher feature tensor of the second teacher model are used to calculate the total loss to train the student model.
[0098] Image recognition module 402 is used to obtain image recognition results based on user features.
[0099] In some embodiments of this application, the apparatus provided in this application may further include the following modules:
[0100] The feature extraction module is used to extract the first teacher feature vector from the training set using the trained first teacher model, extract the teacher feature tensor from the training set using the trained second teacher model, and extract the student feature vector and student feature tensor from the training set using the student model; wherein, the student feature tensor is obtained by stacking a batch of student feature tensors, and the teacher feature tensor is obtained by stacking a batch of second teacher feature tensors from the second teacher model.
[0101] The loss calculation module is used to calculate the mean squared error loss using student feature vectors and first teacher feature vectors, the class loss using student feature vectors and corresponding class labels in the training set, and the mask generative loss using student feature tensors and teacher feature tensors; and to calculate the total loss using the mean squared error loss, class loss, and mask generative loss.
[0102] The parameter update module is used to update the model parameters of the student model through the total loss until the student model converges, and the trained student model is used as the preset recognition model.
[0103] In some embodiments of this application, the loss calculation module may include the following sub-modules:
[0104] The mask generative loss calculation submodule is used to perform convolution mapping on the student feature tensor, aligning the dimensions of the student feature tensor after convolution mapping with the dimensions of the teacher feature tensor; randomly generate a mask tensor, and obtain the masked student feature tensor by multiplying the mask tensor by the dimension-aligned student feature tensor; calculate the mask generative loss based on the feature deviation between the masked student feature tensor and the teacher feature tensor.
[0105] In some embodiments of this application, the loss calculation module may further include the following sub-modules:
[0106] The mask tensor generation submodule is used to compare the eigenvalues at each position (i, j) in the student feature tensor with the preset first threshold. If the eigenvalue at position (i, j) in the second feature tensor is less than the preset first threshold, a random number is generated within a preset range and used as the mask value at position (i, j) in the mask tensor. If the eigenvalue at position (i, j) in the second feature tensor is greater than or equal to the preset first threshold, the mask value at position (i, j) in the mask tensor is set to a preset value.
[0107] In some embodiments of this application, the loss calculation module may include the following sub-modules:
[0108] The total loss calculation submodule is used to compare the number of training rounds of the student model with the preset second threshold. If the number of training rounds of the student model is less than the preset second threshold, the mean squared error loss, class loss and mask generation loss are weighted and summed to obtain the first total loss. If the number of training rounds of the student model is greater than or equal to the preset second threshold, the class loss and mask generation loss are weighted and summed to obtain the second total loss.
[0109] In some embodiments of this application, the total loss includes a first total loss and a second total loss, and the parameter update module may include the following sub-modules:
[0110] The parameter update submodule is used to update the model parameters of the student model using the first total loss when the number of training rounds is less than a preset second threshold, and to update the model parameters of the student model using the second total loss when the number of training rounds is greater than or equal to the preset second threshold.
[0111] In this embodiment, the user's image to be identified is input into a preset recognition model for feature extraction, so as to obtain the image recognition result based on the extracted user features. The preset recognition model used for feature extraction is trained based on a student model and at least two teacher models. It can be mainly obtained by training the student model using the mean squared error loss calculated based on the student feature vector of the student model and the first teacher feature vector of the first teacher model, as well as the mask generative loss calculated based on the student feature tensor of the student model and the teacher feature tensor of the second teacher model. By having at least two teacher models guide the student model, the learning behavior of the teacher model, which has a complex network structure, a large number of parameters, and strong learning ability, is transferred to the student model, which has a simple network structure, a small number of parameters, and weak learning ability, thereby improving the feature recognition ability of the student model. Furthermore, the mean squared error loss in the total loss used to train the student model is calculated by combining the features extracted by the student model with the features extracted by one teacher model, and the mask generative loss used to train the student model is calculated by combining the features extracted by the student model with the features extracted by another teacher model. By using two teacher models with different architectures and guiding the training of the student model through joint feature loss, the similarity difference between the features extracted by the student model and the features extracted by at least two teacher models is minimized, thereby improving the feature recognition ability of the student model and thus improving the feature recognition accuracy of image recognition and reducing the false positive rate.
[0112] As the device embodiment is basically similar to the method embodiment, the description is relatively simple, and relevant parts can be found in the description of the method embodiment.
[0113] This application also provides an electronic device, see embodiments thereof. Figure 5 The provided electronic device 500 includes a memory 510, a processor 520, and a computer program 511 stored in the memory 510 and capable of running on the processor 520. When the computer program 511 is executed by the processor, it implements the various processes of the above-described image recognition method embodiments and achieves the same technical effects. To avoid repetition, it will not be described again here. It should be noted that the electronic device can be any device with image recognition function, such as attendance devices, access control devices, etc., and the embodiments of this application do not limit it in this way.
[0114] This application also provides a computer-readable storage medium, see embodiments thereof. Figure 6 The computer-readable storage medium 600 provided stores a computer program 511. When the computer program 511 is executed by the processor, it implements the various processes of the above-described image recognition method embodiments and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0115] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0116] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of the embodiments of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or modules is not necessarily limited to those steps or modules explicitly listed, but may include other steps or modules not explicitly listed or inherent to these processes, methods, products, or devices. The division of modules in the embodiments of this application is merely a logical division; in actual applications, there may be other division methods. For example, multiple modules may be combined into or integrated into another system, or some features may be ignored or not performed. Additionally, the shown or discussed mutual coupling or direct coupling or communication connection may be through some interface, and the indirect coupling or communication connection between modules may be electrical or other similar forms, none of which are limited in the embodiments of this application. Furthermore, the modules or sub-modules described as separate components may or may not be physically separated, may or may not be physical modules, or may be distributed among multiple circuit modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the embodiments of this application.
[0117] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0118] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and modules described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0119] In the embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules 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 indirect coupling or communication connection through some interfaces, apparatuses, or modules, and may be electrical, mechanical, or other forms.
[0120] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0121] Furthermore, the functional modules in the various embodiments of this application can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium.
[0122] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product.
[0123] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a server or data center that integrates one or more available media. The available medium may be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)).
[0124] This application describes embodiments with reference to flowchart illustrations and / or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0125] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing terminal device to operate in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The functions specified in one or more boxes; these computer program instructions may also be loaded onto a computer or other programmable data processing terminal equipment to cause a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0126] Although preferred embodiments of the present application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present application.
[0127] Finally, it should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation portals are provided for users to choose to authorize or refuse.
[0128] The technical solutions provided in the embodiments of this application have been described in detail above. Specific examples have been used in the embodiments of this application to illustrate the principles and implementation methods of the embodiments of this application. The description of the above embodiments is only for the purpose of helping to understand the methods and core ideas of the embodiments of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the embodiments of this application. Therefore, the content of this specification should not be construed as a limitation on the embodiments of this application.
Claims
1. An image recognition method, characterized in that, The method includes: A user's image to be identified is collected, and the image is input into a preset recognition model for feature extraction to obtain user features. The preset recognition model is trained based on a student model and at least two teacher models. The mean squared error loss calculated from the student feature vector of the student model and the first teacher feature vector of the first teacher model, as well as the mask generative loss calculated from the student feature tensor of the student model and the teacher feature tensor of the second teacher model, are used to calculate the total loss to train the student model. Image recognition results are obtained based on the user characteristics.
2. The method according to claim 1, characterized in that, The method further includes: The training process involves extracting a first teacher feature vector from the training set using a first teacher model, extracting a teacher feature tensor from the training set using a second teacher model, and extracting student feature vectors and student feature tensors from the training set using a student model. The student feature tensor is obtained by stacking a batch of student feature tensors, and the teacher feature tensor is obtained by stacking the batch of second teacher feature tensors from the second teacher model. The mean squared error loss is calculated using the student feature vector and the first teacher feature vector; the category loss is calculated using the student feature vector and the category labels corresponding to the training set; and the mask generative loss is calculated using the student feature tensor and the teacher feature tensor. The total loss is calculated using the mean squared error loss, the category loss, and the mask generative loss. The model parameters of the student model are updated using the total loss until the student model converges, and the resulting trained student model is used as the preset recognition model.
3. The method according to claim 2, characterized in that, The calculation of the mask generative loss using the student feature tensor and the teacher feature tensor includes: The student feature tensor is convolved and mapped so that the dimension of the convolved and mapped student feature tensor is aligned with the dimension of the teacher feature tensor. A mask tensor is randomly generated, and the masked student feature tensor is obtained by multiplying the mask tensor by the dimension-aligned student feature tensor. The mask generative loss is calculated by the feature deviation between the masked student feature tensor and the teacher feature tensor.
4. The method according to claim 3, characterized in that, The process of generating the mask tensor includes: Compare the eigenvalues at each position (i, j) in the student feature tensor with the values of a preset first threshold; If the feature value at position (i, j) in the second feature tensor is less than the preset first threshold, then a random number is generated within the preset range, and the random number is used as the mask value at position (i, j) in the mask tensor. If the feature value at position (i, j) in the second feature tensor is greater than or equal to the preset first threshold, then the mask value at position (i, j) in the mask tensor is set to a preset value.
5. The method according to claim 2, characterized in that, The calculation of the total loss using the mean squared error loss, the category loss, and the mask generative loss includes: Compare the training rounds of the student model with the size of a preset second threshold; If the number of training rounds of the student model is less than the preset second threshold, then the mean squared error loss, the class loss and the mask generative loss are weighted and summed to obtain the first total loss; If the number of training rounds of the student model is greater than or equal to the preset second threshold, then the category loss and the masked generation loss are weighted and summed to obtain the second total loss.
6. The method according to claim 2 or 5, characterized in that, The total loss includes a first total loss and a second total loss, and updating the model parameters of the student model using the total loss includes: If the number of training rounds is less than a preset second threshold, the model parameters of the student model are updated using the first total loss. If the number of training rounds is greater than or equal to the preset second threshold, the model parameters of the student model are updated using the second total loss.
7. An image recognition device, characterized in that, The device includes: An image feature extraction module is used to acquire a user's image to be identified, input the image to be identified into a preset recognition model for feature extraction, and obtain user features. The preset recognition model is trained based on a student model and at least two teacher models. The mean squared error loss calculated from the student feature vector of the student model and the first teacher feature vector of the first teacher model, as well as the mask generative loss calculated from the student feature tensor of the student model and the teacher feature tensor of the second teacher model, are used to calculate the total loss to train the student model. An image recognition module is used to obtain image recognition results based on the user characteristics.
8. The apparatus according to claim 7, characterized in that, The device further includes: The feature extraction module is used to extract a first teacher feature vector from the training set using a trained first teacher model, extract a teacher feature tensor from the training set using a trained second teacher model, and extract student feature vectors and student feature tensors from the training set using a student model; wherein the student feature tensor is obtained by stacking a batch of student feature tensors, and the teacher feature tensor is obtained by stacking the batch of second teacher feature tensors of the second teacher model; The loss calculation module is used to calculate the mean squared error loss using the student feature vector and the first teacher feature vector, calculate the category loss using the student feature vector and the category label corresponding to the training set, and calculate the mask generative loss using the student feature tensor and the teacher feature tensor; and calculate the total loss using the mean squared error loss, the category loss, and the mask generative loss. The parameter update module is used to update the model parameters of the student model through the total loss until the student model converges, and the trained student model is used as the preset recognition model.
9. An electronic device, characterized in that, include: A processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program, when executed by the processor, implements the image recognition method as described in any one of claims 1 to 6.
10. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium, which, when executed by a processor, implements the image recognition method as described in any one of claims 1 to 6.