Model training method and device, image recognition method and device
By decoupling the attribute clustering and attribute classification models of animal facial images, the recognition accuracy problem of animal facial recognition models under imbalanced training data is solved, and higher recognition accuracy is achieved.
Patent Information
- Application Number
- CN202210363181.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-07
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2042-04-07
AI Technical Summary
Existing animal face recognition models have low recognition accuracy in some cases, mainly due to the imbalanced distribution of training data types, which leads to bias in model training.
By performing attribute clustering analysis on the training sample data, the attribute labels of each animal face image are obtained, and the parameters of the first animal face recognition model are adjusted based on the attribute classification model to decouple its attribute classification capability and obtain the second animal face recognition model.
The recognition accuracy of the animal face recognition model is improved, avoiding the model bias problem caused by unbalanced training data.
Smart Images

Figure CN116935458B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of artificial intelligence, in particular to a model training method and device, and an image recognition method and device. BACKGROUND
[0002] With the continuous development and popularization of artificial intelligence technology, various artificial intelligence applications have begun to penetrate into all aspects of life, bringing great convenience to people's life.
[0003] Among them, animal face recognition technology based on artificial intelligence technology has been widely used in various life scenarios. Animal face recognition technology can greatly improve the processing efficiency of various life scenarios and is increasingly widely used in daily life.
[0004] However, the animal face recognition model used by the current animal face recognition technology has low recognition accuracy in some cases. SUMMARY
[0005] The embodiments of the present application provide a model training method and device, and an image recognition method and device, which can effectively improve the accuracy of the animal face recognition model.
[0006] The first aspect of the present application provides a model training method, which comprises:
[0007] obtaining training sample data, wherein the training sample data comprises a plurality of animal face images and label data corresponding to each animal face image;
[0008] training a first neural network model according to the training sample data to obtain a first animal face recognition model;
[0009] performing attribute clustering analysis on the plurality of animal face images to obtain an attribute label corresponding to each animal face image;
[0010] extracting image features of each animal face image using the first animal face recognition model, and training a second neural network model based on the image features and the attribute label of each animal face image to obtain an attribute classification model;
[0011] adjusting model parameters of the first animal face recognition model based on the attribute classification model to obtain a second animal face recognition model.
[0012] Correspondingly, the second aspect of the present application provides a model training device, which comprises:
[0013] a first obtaining unit configured to obtain training sample data, wherein the training sample data comprises a plurality of animal face images and label data corresponding to each animal face image;
[0014] a first training unit, configured to train a first neural network model according to the training sample data, to obtain a first animal face recognition model;
[0015] an analysis unit, configured to perform attribute clustering analysis on the plurality of animal face images, to obtain an attribute label corresponding to each animal face image;
[0016] a second training unit, configured to extract an image feature of each animal face image by using the first animal face recognition model, and train a second neural network model based on the image feature and the attribute label of each animal face image, to obtain an attribute classification model;
[0017] an adjustment unit, configured to adjust a model parameter of the first animal face recognition model based on the attribute classification model, to obtain a second animal face recognition model.
[0018] In some embodiments, the analysis unit comprises:
[0019] a division sub-unit, configured to divide the plurality of animal face images according to identity information corresponding to each image, to obtain an animal face image set corresponding to each identity information;
[0020] a first extraction sub-unit, configured to extract an image feature of each animal face image in each animal face image set by using the first animal face recognition model, to obtain an image feature set corresponding to each identity information;
[0021] a second calculation sub-unit, configured to calculate a mean value of a plurality of image features contained in each image feature set, to obtain an identity feature corresponding to each identity information;
[0022] a determination sub-unit, configured to perform attribute clustering analysis based on the identity feature corresponding to each identity information, to obtain an attribute label corresponding to each identity information, and determine an attribute label corresponding to each animal face image according to the attribute label corresponding to each identity information.
[0023] In some embodiments, the determination sub-unit comprises:
[0024] a clustering module, configured to perform feature clustering based on the identity feature corresponding to each identity information, to obtain a plurality of cluster center features;
[0025] a calculation module, configured to calculate a similarity degree between each identity feature and each cluster center feature, and determine a cluster center feature corresponding to each identity feature according to the similarity degree;
[0026] a determination module, configured to determine an attribute label corresponding to each identity information according to the cluster center feature corresponding to each identity feature.
[0027] In some embodiments, the adjusting unit comprises:
[0028] The acquisition sub-unit is configured to acquire a first loss function corresponding to the first animal face recognition model and a second loss function corresponding to the attribute classification model.
[0029] The first generation sub-unit is configured to generate a target loss function based on a difference between the first loss function and the second loss function.
[0030] The first adjusting sub-unit is configured to adjust model parameters of the first animal face recognition model according to the target loss function, to obtain a second animal face recognition model.
[0031] In some embodiments, the adjusting unit comprises:
[0032] The calculation module is configured to perform optimization calculation on the target loss function by using a gradient descent method, until a preset convergence condition is reached, to obtain a target model parameter value.
[0033] The updating module is configured to update the model parameters in the first animal face recognition model according to the target model parameter value, to obtain a second animal face recognition model.
[0034] In some embodiments, the second training unit comprises:
[0035] The second extraction sub-unit is configured to extract image features of each animal face image by using the first animal face recognition model.
[0036] The input sub-unit is configured to input the image features of each animal face image into a second neural network model, to obtain an output result corresponding to each animal face image.
[0037] The second calculation sub-unit is configured to calculate a cross entropy between the output result corresponding to each animal face image and a corresponding attribute label, to obtain a loss function.
[0038] The training sub-unit is configured to train the second neural network model based on the loss function, to obtain an attribute classification model.
[0039] In some embodiments, the adjusting unit comprises:
[0040] The second generation sub-unit is configured to train and generate a generative adversarial network according to the label data corresponding to each animal face image and the attribute label.
[0041] The third generation sub-unit is configured to generate supplementary sample data by using the generative adversarial network.
[0042] The supplement subunit is configured to add the supplement sample data to the training sample data to obtain target training sample data.
[0043] The second adjustment subunit is configured to adjust parameters of the first animal face recognition model based on the target training sample data and the attribute classification model to obtain a second animal face recognition model.
[0044] The third aspect of the present application provides an image recognition method, which comprises the following steps:
[0045] Obtaining a target animal face image;
[0046] Recognizing the target animal face image by using a preset neural network model to obtain target identity information corresponding to the target animal face image, wherein the preset neural network model is the second animal face recognition model in the model training method provided in the first aspect.
[0047] Correspondingly, the fourth aspect of the present application provides an image recognition device, which comprises the following units:
[0048] The second obtaining unit is configured to obtain a target animal face image;
[0049] The recognition unit is configured to recognize the target animal face image by using a preset neural network model to obtain target identity information corresponding to the target animal face image, wherein the preset neural network model is the second animal face recognition model in the model training method provided in the first aspect.
[0050] The fifth aspect of the present application further provides a computer readable storage medium, which stores a plurality of instructions, and the instructions are suitable for being loaded by a processor to execute the steps in the model training method provided in the first aspect.
[0051] The sixth aspect of the present application provides a computer device, which comprises a memory, a processor, and a computer program stored in the memory and capable of running on the processor, and the processor executes the computer program to implement the steps in the model training method provided in the first aspect.
[0052] The seventh aspect of the present application provides a computer program product, which comprises computer programs / instructions, and the computer programs / instructions are executed by a processor to implement the steps in the model training method provided in the first aspect.
[0053] The model training method provided in the embodiments of the present application comprises the following steps: obtaining training sample data, the training sample data comprising a plurality of animal face images and label data corresponding to each animal face image; training a first neural network model according to the training sample data to obtain a first animal face recognition model; performing attribute clustering analysis on the plurality of animal face images to obtain attribute labels corresponding to each animal face image; extracting image features of each animal face image by using the first animal face recognition model, and training a second neural network model based on the image features and the attribute labels of each animal face image to obtain an attribute classification model; and adjusting model parameters of the first animal face recognition model based on the attribute classification model to obtain a second animal face recognition model.
[0054] Therefore, the model training method provided in the present application can avoid the model bias problem caused by uneven distribution of different types of data in the training sample by performing attribute clustering on the features of the animal face images, training an attribute classification model according to the clustering results, and adjusting the animal face recognition model based on the trained attribute classification model to decouple the attribute classification of the animal face recognition model, thereby improving the accuracy of the animal face recognition model. BRIEF DESCRIPTION OF DRAWINGS
[0055] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0056] Figure 1 is a scene schematic diagram of model training in the present application;
[0057] Figure 2 is a flowchart of the model training method provided in the present application;
[0058] Figure 3 is another flowchart of the model training method provided in the present application;
[0059] Figure 4 is a flowchart of the image recognition method provided in the present application;
[0060] Figure 5 is a structural schematic diagram of the model training device provided in the present application;
[0061] Figure 6 is a structural schematic diagram of the image recognition device provided in the present application;
[0062] Figure 7 is a structural schematic diagram of the computer device provided in the present application. DETAILED DESCRIPTION
[0063] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by a person of ordinary skill in the art without creative work fall within the protection scope of the present application.
[0064] The embodiments of the present application provide a model training method and device, a computer readable storage medium and a computer device. The model training method can be used in a model training device. The model training device can be integrated in a computer device, which can be a terminal or a server. The terminal can be a mobile phone, a tablet computer, a notebook computer, a smart television, a wearable smart device, a personal computer (PC), a vehicle-mounted terminal, and the like. The server can be a standalone physical server, a server cluster or a distributed system composed of multiple physical servers, a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery network (CDN), and basic cloud computing services such as big data and artificial intelligence platforms. The server can be a node in a blockchain.
[0065] Please refer to Figure 1 A scene diagram of the model training method provided in the present application is shown in the figure. As shown in the figure, the server A obtains training sample data from the terminal B, the training sample data includes multiple animal face images and label data corresponding to each animal face image; a first neural network model is trained according to the training sample data to obtain a first animal face recognition model; attribute clustering analysis is performed on the multiple animal face images to obtain attribute labels corresponding to each animal face image; the image features of each animal face image are extracted using the first animal face recognition model, and a second neural network model is trained based on the image features and attribute labels of each animal face image to obtain an attribute classification model; the model parameters of the first animal face recognition model are adjusted based on the attribute classification model to obtain a second animal face recognition model.
[0066] It should be noted that, Figure 1The model training scene diagram shown is only an example, and the model training scene described in the embodiments of the present application is used to more clearly illustrate the technical solutions of the present application, and does not constitute a limitation on the technical solutions provided by the present application. Those skilled in the art can know that as the model training scene evolves and new business scenarios appear, the technical solutions provided by the present application are also applicable to similar technical problems.
[0067] Based on the above implementation scenarios, the following are described in detail.
[0068] In the related art, the animal face recognition system applied in various scenarios often has the problem of low recognition accuracy for some types of animals (for example, cats with blue eyeballs). This seriously affects the overall recognition accuracy of the animal face recognition system. Specifically, in a group of animals with certain definable attributes (such as skin color, hair color, or eye color) or potential attributes, the animal face recognition model has too high similarity between classes for the features it extracts, resulting in a high false positive rate, which seriously affects the use effect of the animal face recognition system in certain specific scenarios. The main reason for this phenomenon is that during the training process of the animal face recognition model, the uneven distribution of various types of data causes a certain bias in model training. When data with a specific attribute (for example, black hair color) occupies a major part in the training data, the feature space of the model will tend to be consistent with the feature space distribution of the animal group with this attribute. However, the animal group with other attributes will have a compressed class distance, resulting in a high similarity and causing misidentification. To this end, the present application provides a model training method for alleviating the problem of model bias caused by uneven distribution of training data during model training, so as to improve the recognition accuracy of the animal face recognition model.
[0069] The embodiments of the present application will be described from the perspective of a model training device, which can be integrated in a computer device. The computer device can be a terminal or a server. The terminal can be a mobile phone, a tablet computer, a notebook computer, a smart television, a wearable smart device, a personal computer (PC), and a vehicle-mounted terminal, etc. The server can be a standalone physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery network (CDN), and big data and artificial intelligence platforms, etc. Basic cloud computing services such as cloud computing services. For example, Figure 2 As shown, a flowchart of the model training method provided by the present application, the method comprises:
[0070] Step 101, obtaining training sample data.
[0071] In the embodiments of the present application, the training sample data used can be sample data for training a normal animal face recognition model. The animal face can be a cat face, a dog face, or a monkey face, etc. In some other embodiments, the animal face can also be a human face. Specifically, the sample data can be a plurality of animal face images with labels, where the label of an animal face image can be the identity information corresponding to the image. For example, the label data of image A is the identity information "Xiao A" corresponding to the image A, and the label data of image B is the identity information "Xiao B" corresponding to the image B, etc. The animal face recognition model is based on computer vision technology in artificial intelligence (AI) technology. Computer vision is a science that studies how to make machines "see". Further, it refers to using cameras and computers to replace human eyes to identify and measure targets, and further to process images so that the computer processing becomes more suitable for human eye observation or image transmission to instrument detection. As a scientific discipline, computer vision researches related theories and technologies, and tries to establish artificial intelligence systems that can obtain information from images or multidimensional data. Computer vision technology usually includes image processing, image recognition, image semantic understanding, image retrieval, OCR, video processing, video semantic understanding, video content / behavior recognition, three-dimensional object reconstruction, 3D technology, virtual reality, augmented reality, simultaneous localization and mapping, and other technologies. It also includes common face recognition, fingerprint recognition, and other biometric identification technologies.
[0072] In the training sample data, multiple images can correspond to the same label data, such as the image with the identity information "Xiao A" can have one or more images. Generally, in order to ensure the accuracy of the animal face recognition model, multiple training sample images can correspond to one identity information. The label data corresponding to one animal face image can only have one, and the label data is unique, i.e. the label data can distinguish its corresponding identity information from other identity information. The label data can be a string of characters or other forms of data, as long as it can satisfy the condition that different identity information corresponds to different label data.
[0073] The training sample data can be obtained from a preset database. When the animal face image is a human face image, the use of the human face image in the database can be authorized by each user corresponding to the human face image, and the use process complies with relevant legal regulations.
[0074] At step 102, a first neural network model is trained according to the training sample data, to obtain a first animal face recognition model.
[0075] Wherein, after the training sample data is obtained, the animal face recognition model can be trained according to the animal face images in the training sample and the label data corresponding to each animal face image. The model to be trained here can be referred to as a first neural network model, which is used to distinguish from the second neural network model or the third neural network model in the present application.
[0076] Specifically, the first neural network model can be a convolutional neural network model (CNN). The convolutional neural network is a kind of feedforward neural network containing convolution calculation and having a deep structure, and is one of the representative algorithms of deep learning (DL). The convolutional neural network has representation learning (RL) capability and can perform shift-invariant classification (SC) on input information according to its hierarchical structure, so it is also called "shift-invariant artificial neural network". The first neural network model can also be other classification networks, which are not limited here.
[0077] The training of the first neural network model can be supervised training. The input data of the training is the animal face image in the training sample data, and the supervision label is the label data corresponding to each animal face image, i.e., the identity information corresponding to each animal face image. When the first neural network model is trained, the animal face image data in the training sample data is read, and the read animal face image data is grouped into a batch data and sent to the deep network unit in the first neural network model for processing. In this process, the first neural network model extracts the spatial features of each animal face image to obtain a feature map corresponding to each animal face image, which retains the spatial structure information of the animal face image. This process includes convolution calculation, nonlinear activation calculation, and pooling calculation operations. Then, the feature map corresponding to each animal face image can be further processed through a full connection network and a classification network to obtain an output value, and then the loss function value is calculated according to the output value and the corresponding label value. Then, the gradient is calculated according to the loss function value for gradient backpropagation, thereby realizing the process of optimizing the model parameters of the first neural network model. Specifically, in the process of cyclically optimizing the model parameters of the first neural network by using the gradient descent method, a preset training termination condition can be set. When the model training process meets the training termination condition, the training of the first neural network model is completed, and the first animal face recognition model is obtained. The termination condition can be that the number of iterations reaches a preset number, or the loss function value is less than a set value.
[0078] In step 103, attribute clustering analysis is performed on the plurality of animal face images to obtain an attribute label corresponding to each animal face image.
[0079] In the embodiments of the present application, for the plurality of animal face images included in the training sample data, an attribute label corresponding to each animal face image can be further determined. Specifically, the plurality of animal face images can be classified according to attributes.
[0080] Generally, the classification of animal face images can be performed according to some semantic attributes. For example, the classification can be performed according to skin color in the animal face image, according to hair color in the animal face image, according to facial features in the animal face image, etc. Each category corresponds to an attribute label, and after the classification of the animal face images, the attribute label corresponding to each animal face image can be determined.
[0081] In some embodiments, the attribute clustering analysis is performed on the plurality of animal face images to obtain an attribute label corresponding to each animal face image, including:
[0082] 1. Divide a plurality of animal face images according to identity information corresponding to each image to obtain an animal face image set corresponding to each identity information;
[0083] 2. Extract image features of each animal face image in each animal face image set by using a first animal face recognition model to obtain an image feature set corresponding to each identity information;
[0084] 3. Calculate the mean of a plurality of image features contained in each image feature set to obtain an identity feature corresponding to each identity information;
[0085] 4. Perform attribute clustering analysis based on the identity feature corresponding to each identity information to obtain an attribute label corresponding to each identity information, and determine an attribute label corresponding to each animal face image according to the attribute label corresponding to each identity information.
[0086] In the embodiments of the present application, a general attribute classification method is provided, which no longer uses the traditional semantic-based attribute classification method, but performs attribute classification by clustering analysis according to the identity feature corresponding to each identity information to obtain an attribute label corresponding to each identity information and each animal face image.
[0087] Specifically, as described above, each animal face image included in the training sample data corresponds to a label data, which corresponds to the identity information of the object in the image. Moreover, generally, a plurality of animal face images correspond to one identity information. Therefore, the plurality of animal face images in the training sample data can be divided according to the identity information to obtain an animal face image set corresponding to each identity information. The animal face image set corresponding to each identity information contains animal face images of the object corresponding to the identity information.
[0088] After determining the animal face image set corresponding to each identity information, the first animal face recognition model trained as described above can be used to extract image features of the animal face images in each animal face image set to obtain image features of each animal face image, i.e., to obtain an image feature set corresponding to each identity information. Then, the mean of a plurality of image features in the image feature set corresponding to each identity information can be calculated to obtain an identity feature corresponding to each identity information.
[0089] After the identity features corresponding to each identity information are extracted by using the aforementioned trained animal face recognition model, clustering analysis can be further performed based on the identity features corresponding to each identity information to obtain target clusters corresponding to each identity information, so as to obtain attribute labels corresponding to each identity information. It can be understood that the attribute labels of the animal face images in the animal face image set corresponding to each identity information are the same as the attribute labels corresponding to the identity information, that is, the attribute labels corresponding to each animal face image can be obtained.
[0090] Since the identity features corresponding to each identity information are used in the embodiment, that is, the identity features of each object (the mean of multiple image features) corresponding to each identity information are used for clustering to obtain the attribute categories and attribute labels corresponding to each object, compared with classification using the attribute categories defined by semantics, more generalized attribute categories can be obtained, so that the problem of model training bias caused by uneven distribution of training data of different categories in the model training process can be avoided.
[0091] In some embodiments, the attribute clustering analysis based on the identity features corresponding to each identity information to obtain the attribute labels corresponding to each identity information includes:
[0092] 4.1, performing feature clustering based on the identity features corresponding to each identity information to obtain a plurality of cluster center features;
[0093] 4.2, calculating the similarity degree of each identity feature and each cluster center feature, and determining the cluster center feature corresponding to each identity feature according to the similarity degree;
[0094] 4.3, determining the attribute labels corresponding to each identity information according to the cluster center features corresponding to each identity feature.
[0095] In the embodiments of the present application, the clustering analysis on the identity features corresponding to a plurality of identity information can be performed to determine several cluster center features according to the clustering of the plurality of identity features. Each cluster center feature corresponds to an attribute category, that is, an attribute label, and different attribute categories correspond to different attribute labels.
[0096] After determining multiple cluster center features, the similarity between each identity feature and each cluster center feature can be calculated one by one, and the cluster center feature corresponding to each identity feature can be determined based on the similarity. Calculating the similarity between each identity feature and each cluster center feature can be calculating the cosine similarity between the feature vector corresponding to each identity feature and the feature vector corresponding to each cluster center feature. Then, the target cluster center feature with the highest cosine similarity value between the vectors corresponding to the identity feature among the multiple cluster center features corresponding to each target identity feature can be determined as the cluster center category corresponding to the identity feature, that is, the attribute label corresponding to the target cluster center feature is the attribute label corresponding to the target identity feature. It can be understood that multiple identity features can correspond to the same cluster center feature, that is, multiple identity features can correspond to the same attribute label.
[0097] Step 104 : Using the first animal face recognition model to extract image features of each animal face image, and training a second neural network model based on the image features and attribute labels of each animal face image to obtain an attribute classification model.
[0098] After performing attribute cluster analysis on multiple animal facial images in the training sample data to obtain attribute labels corresponding to each animal facial image, a second neural network model can be further trained based on the image features of each animal facial image and the corresponding attribute labels to obtain an attribute classification model. The image features of each animal facial image can be image features extracted using the aforementioned first animal facial recognition model.
[0099] Since the first animal face recognition model obtained by training with the training sample data mentioned above not only learns the ability to extract animal face image features, but also learns the ability to classify animal face images by attributes during the training process. However, the ability to classify animal face images by attributes will cause a certain bias in model training due to the imbalance of the training sample data. When data with specific attributes occupy a major part of the training data, the feature space of the model will tend to be consistent with the feature space distribution of the animal group with this attribute. However, the inter-class distance compression occurs for animal groups with other attributes, and the similarity becomes higher, causing misidentification. Therefore, the present application extracts this attribute classification ability by training a model that recognizes attribute categories from the image features extracted from the first animal face recognition model, and then decouples the attribute classification ability in the first animal face recognition model based on the trained model to obtain a final animal face recognition model that does not have attribute classification ability.
[0100] Specifically, the image features of each animal face image in the training samples can be extracted by using the first animal face recognition model trained in advance, and then the second neural network model is trained in a supervised manner by taking the image features of each animal face image as input and the attribute label corresponding to each animal face image as a supervised label, to obtain an attribute classification model. The second neural network model can be a classification network, which is generally composed of a convolutional neural network and generally includes convolution (Convolution) calculation, nonlinear activation function (Relu) calculation, pooling (Pooling) calculation and other operations. Similarly, the process of training the second neural network model can be to input the image features of the animal face image into the second neural network model to obtain the predicted classification value output by the second neural network model, then calculate the loss function value based on the cross entropy between the predicted classification value and the corresponding attribute label, and further solve the gradient descent based on the loss function until the preset termination condition is met, complete the training of the second neural network model, and obtain the trained attribute classification model.
[0101] Step 105, adjusting the model parameters of the first animal face recognition model based on the attribute classification model to obtain a second animal face recognition model.
[0102] As described above, the first animal face recognition model trained by using the traditional animal face recognition model training method learns both the identity information recognition ability and the attribute classification ability, and the attribute classification ability may cause the identity information recognition ability to decrease in some scenarios. In this regard, the present application further extracts image features from animal face images based on the trained first animal face recognition model, and determines the attribute label corresponding to each image feature by using image feature clustering analysis, and then trains a classification network by taking the image features as input and the corresponding attribute labels as output to obtain an attribute classification model. The attribute classification model extracts the attribute classification ability learned in the first animal face recognition model.
[0103] In this way, after the first animal face recognition model and the attribute classification model are trained, the attribute classification model can be further used to decouple the attribute classification ability in the first animal face recognition model. That is, the attribute classification model is used to further adjust the model parameters in the animal face recognition model to obtain a second animal face recognition model that only has the identity information recognition ability and does not have the attribute classification ability.
[0104] Specifically, decoupling the attribute classification ability in the first animal face recognition model by using the attribute classification model can be to further train the first animal face recognition model by using an adversarial learning method to obtain a second animal face recognition model.
[0105] In some embodiments, the model parameters of the first animal face recognition model are adjusted based on the attribute classification model to obtain a second animal face recognition model, including:
[0106] 1. obtaining a first loss function corresponding to the first animal face recognition model and a second loss function corresponding to the attribute classification model;
[0107] 2. generating a target loss function based on the difference between the first loss function and the second loss function;
[0108] 3. adjusting the model parameters of the first animal face recognition model according to the target loss function to obtain the second animal face recognition model.
[0109] In the embodiments of the present application, in the supervised model training process, the difference between the output of the model and the label value is generally used to determine the loss function of the model, and the parameters of the model are continuously adjusted based on the loss function until the preset loop termination condition is reached. Generally, the loop termination condition is to minimize the loss function value. That is, the first animal face recognition model and the attribute classification model both have a loss function for training the model, and when the corresponding loss function value reaches the minimum, the training of the model reaches the best effect. Therefore, the first loss function corresponding to the first animal face recognition model and the second loss function corresponding to the attribute classification model can be obtained first. Based on the above analysis, when the first loss function reaches the minimum value, the first animal face recognition model learns the best identity recognition ability; when the second loss function reaches the minimum value, the attribute classification model learns the best attribute classification ability.
[0110] However, in the present application, the purpose of further training the first animal face recognition model is to decouple the attribute classification ability in the first animal face recognition model, i.e., the attribute classification ability in the first animal face recognition model needs to be the weakest. Therefore, in the embodiments of the present application, a new loss function is constructed based on the difference between the first loss function and the second loss function, which can be referred to as a target loss function here. Since the target loss function is a loss function obtained by subtracting the second loss function from the first loss function, when the model parameters of the first animal face recognition model are adjusted based on the target loss function, the first loss function reaches a minimum value when the target loss function reaches a minimum value, and the second loss function reaches a maximum value. At this time, the best identity recognition ability can be learned and the worst attribute classification ability can be learned, so as to decouple the attribute classification ability in the first animal face recognition model and train a second animal face recognition model that only has identity recognition ability and does not have attribute classification ability. Since the second animal face recognition model does not have attribute classification ability, it will not be biased due to the imbalance of the training data, thereby improving the accuracy of the animal face recognition model.
[0111] In some embodiments, adjusting the model parameters of the first animal face recognition model according to the target loss function to obtain the second animal face recognition model comprises:
[0112] 3.1, using gradient descent method to optimize and calculate the target loss function until a preset convergence condition is reached to obtain a target model parameter value;
[0113] 3.2, updating the model parameters in the first animal face recognition model according to the target model parameter value to obtain the second animal face recognition model.
[0114] In the embodiments of the present application, after the target neural network model for adjusting the model parameters of the first neural network model is determined, the gradient descent method can be used to iteratively optimize the target loss function until the preset convergence condition is met, and a second neural network model meeting the requirements is trained.
[0115] In some embodiments, adjusting the model parameters of the first animal face recognition model based on the attribute classification model to obtain the second animal face recognition model comprises:
[0116] A, generating a generative adversarial network according to the label data corresponding to each animal face image and the attribute label;
[0117] B, generating supplementary sample data using the generative adversarial network;
[0118] C, adding the supplementary sample data to the training sample data to obtain target training sample data;
[0119] D, adjusting the parameters of the first animal face recognition model based on the target training sample data using the attribute classification model to obtain a second animal face recognition model.
[0120] Wherein, when adjusting the parameters of the first animal face recognition model based on the target loss function, the animal face image in the training sample data, the label data corresponding to the animal face image and the attribute label corresponding to the animal face image are still needed to be used for training.
[0121] In the embodiments of the present application, the label data corresponding to the animal face image and the attribute label in the aforementioned training sample data can be used to train the generative adversarial network. Wherein, the generative adversarial network (GAN) is a kind of deep learning model, and is one of the most promising methods for unsupervised learning on complex distribution in recent years. The model produces quite good output through the mutual game learning of (at least) two modules in the framework: generative model (GM) and discriminative model (DM). For small data sets, when the data volume is insufficient, the images generated by GAN can be used for data enhancement.
[0122] Therefore, the generative adversarial network can be trained using the label data corresponding to the animal face image and the attribute label, and the GAN trained can be used to generate supplementary sample data to supplement the training sample data to obtain target training sample data, and then the target training sample data is used as training sample data, and the parameters of the first animal face recognition model are adjusted using the attribute classification model to obtain a second animal face recognition model.
[0123] In the embodiments of the present application, the training sample data is expanded by the GAN network, and more abundant sample data is used to train the first animal face recognition model, so that the generalization ability of the second animal face recognition model obtained is stronger, and the accuracy of the animal face recognition model obtained by training can be further improved.
[0124] In some scenarios, the model trained by the model training method provided by the present application can be a face recognition model, which can decouple the attribute features in the face image, so as to extract face features not containing attribute features, and thus the interference of attribute information on face recognition can be avoided, thereby improving the accuracy of face recognition.
[0125] According to the above description, the model training method provided in the embodiments of the present application can obtain training sample data, the training sample data including a plurality of animal face images and label data corresponding to each animal face image; train a first neural network model according to the training sample data to obtain a first animal face recognition model; perform attribute clustering analysis on the plurality of animal face images to obtain attribute labels corresponding to each animal face image; extract image features of each animal face image by using the first animal face recognition model, and train a second neural network model based on the image features of each animal face image and the attribute labels to obtain an attribute classification model; and adjust model parameters of the first animal face recognition model based on the attribute classification model to obtain a second animal face recognition model.
[0126] Therefore, the model training method provided in the present application can perform attribute clustering on the features of animal face images, train an attribute classification model according to the clustering results, and then adjust an animal face recognition model based on the trained attribute classification model to decouple the attribute classification of the animal face recognition model. In this way, the model bias problem caused by uneven distribution of different types of data in the training sample can be avoided, and the accuracy of the animal face recognition model can be improved.
[0127] The present application also provides a model training method, which can be used in a computer device, which can be a terminal or a server. Figure 3 As shown in FIG. 1, another flowchart of the model training method provided in the present application is shown, which specifically includes the following steps:
[0128] In step 201, the computer device obtains training sample data.
[0129] The training sample data includes a plurality of animal face images and identity labels corresponding to each animal face image. The training sample data can be the same as the sample data used to train the animal face recognition model in related technologies. In the embodiments of the present application, the training sample data does not need to be processed additionally, and can only be fine-tuned in the training process to improve the accuracy of the animal face recognition model. The animal face image can be a cat face image, a dog face image, etc. In the embodiments of the present application, the animal face image can also be a human face image, and the animal face recognition model can be a human face recognition model.
[0130] In step 202, the computer device trains an initial animal face recognition model by using the training sample data.
[0131] The initial animal face recognition model can be trained by using the same method as in the related art. Specifically, a preset convolutional neural network model can be trained by using a supervised learning method to obtain the initial animal face recognition model. Since different animal face images differ in identity and attributes, the initial animal face recognition model learned from the training not only has the ability to recognize the identity information contained in the animal face images, but also has the ability to recognize the attribute information contained in the animal face images.
[0132] However, since the distribution of training sample data of different attribute categories is unbalanced during the training of the initial animal face recognition model, the model training is biased. When data with a specific attribute occupies a major part in the training sample data, the feature space of the model tends to be consistent with the feature space distribution of the attribute. Animal face images with other attributes have an inter-class distance compression, a high similarity, and a false recognition. Therefore, in order to avoid the problem of decreased recognition accuracy of the model caused by the recognition of attribute information, the attribute information recognition ability of the initial animal face recognition model needs to be decoupled, so that the animal face recognition model does not have the attribute information recognition ability.
[0133] In step 203, the computer device extracts features of the animal face images in the training sample data by using the initial animal face recognition model to obtain image features of each animal face image.
[0134] After the training of the initial animal face recognition model is completed, the trained initial animal face recognition model can be further used to extract features of each animal face image in the training sample data. The features extracted here can be features in the model processing process or features finally output by the model. The image features retain the spatial structure information of the animal face images. As described above, the initial animal face recognition model obtained after the training not only has the identity recognition ability, but also has the attribute information recognition ability. Therefore, the features extracted by using the initial animal face recognition model not only contain the identity information of the animal face images, but also contain the attribute information of the animal face images.
[0135] In step 204, the computer device classifies the image features according to the identity information corresponding to each animal face image to obtain an image feature set corresponding to each identity information.
[0136] Since each identity information in the training sample data can correspond to multiple images, and the multiple images can represent the object identity corresponding to the identity information. In order to obtain more accurate representation of the identity information, and avoid the individual particularity of a single animal face image leading to inaccurate extraction of the identity feature of the object, the identity feature corresponding to the identity information can be represented by the feature mean value of the multiple animal face images corresponding to each identity information. Therefore, in the embodiments of the present application, the animal face images in the training sample data can be classified according to the identity information corresponding to each animal face image, to obtain the animal face image set corresponding to each identity information. Then the image feature set corresponding to each identity information is further determined.
[0137] In step 205, the computer device calculates the mean value of the image features in the image feature set corresponding to each identity information, to obtain the identity feature corresponding to each identity information.
[0138] Further, after determining the image feature set corresponding to each identity information, the mean value of the image features in the image feature set corresponding to the identity information can be further calculated, to obtain the identity feature corresponding to each identity information. The specific calculation can be according to the following formula (1):
[0139]
[0140] Wherein, F μ is the identity feature corresponding to the identity information, N is the number of features in the image feature set corresponding to the identity information, F i is the i-th image feature in the image feature set corresponding to the identity information.
[0141] In step 206, the computer device performs cluster analysis on the identity features, to obtain the attribute label corresponding to each identity feature.
[0142] After the identity feature corresponding to each identity information is determined, the obtained multiple identity features can be further subjected to attribute clustering to obtain the attribute label corresponding to each identity information. Specifically, the clustering analysis algorithm employed in the embodiments of the present application can be an unsupervised clustering manner, for example, a k-means clustering manner. The k-means clustering algorithm is an iterative solution clustering analysis algorithm, and the steps are as follows: the data is pre-divided into K groups, K objects are randomly selected as initial cluster centers, then the distance between each object and each seed cluster center is calculated, and each object is assigned to the cluster center closest to it. The cluster centers and the objects assigned to them represent a cluster. The cluster centers of the cluster are recalculated according to the existing objects in the cluster after each sample is assigned. This process will be repeated until a certain termination condition is met. The termination condition can be that no (or a minimum number of) objects are reassigned to different clusters, no (or a minimum number of) cluster centers change, or the error sum of squares is locally minimized.
[0143] The constraint function of the above unsupervised clustering algorithm can be represented as formula (2) as follows:
[0144]
[0145] wherein x j is the jth identity feature, u i is the ith cluster center feature, and v(x j , u i ) is the distance between the two, and in the present application, the cosine similarity between features can be used for constraint.
[0146] wherein r ij can be represented by formula (3) as follows:
[0147]
[0148] By using the above clustering algorithm, the cluster center feature corresponding to each identity feature can be determined, and each cluster center feature corresponds to an attribute label, so that the attribute label corresponding to each identity feature can be determined, and the attribute label corresponding to each animal face image can be obtained.
[0149] In step 207, the computer device trains an attribute classification model by using the image features of each animal face image and the corresponding attribute label.
[0150] Since the initial animal face recognition model obtained by the foregoing training learns both the identity recognition capability and the attribute information recognition capability, and the attribute information recognition capability can cause the animal face recognition accuracy to decrease in some scenarios, it is necessary to decouple and remove the attribute information recognition capability in the initial animal face recognition model. Therefore, the model training method provided in this application can first train the attribute classification network by using the attribute label corresponding to each image feature obtained through clustering analysis, to separately learn the attribute information recognition capability in the initial animal face recognition model, and then decouple and remove the attribute information recognition capability in the initial animal face recognition model through the method of adversarial learning, to obtain the target animal face recognition model without the attribute information recognition capability.
[0151] Therefore, after clustering analysis of the identity features is performed to obtain the attribute label corresponding to each identity feature, i.e., to obtain the attribute label corresponding to each image feature, the attribute classification network can be further supervised trained with the image feature as the input and the attribute label corresponding to the image feature as the output. The structure of the attribute classification network can adopt any classification network, and the training process of the attribute classification network is similar to the supervised training process in the related art, which will not be described herein again.
[0152] In step 208, the computer device respectively obtains a first loss function corresponding to the initial animal face recognition model and a second loss function corresponding to the attribute classification model.
[0153] Generally, an optimization function is used to guide the training process of a neural network model. When the initial animal face recognition model is trained, the first loss function corresponding to the model represents the difference between the output of the model and the label value. When the loss function reaches the minimum, the model obtains the best fitting effect, i.e., the animal face recognition model learns the best identity information recognition capability and attribute classification capability at this time. When the attribute classification model is trained, the second loss function corresponding to the model represents the difference between the output of the attribute classification model and the attribute label. When the loss function reaches the minimum, the model obtains the best fitting effect, i.e., the attribute classification model learns the best attribute classification capability at this time. Therefore, by obtaining the first loss function corresponding to the animal face recognition model and the second loss function of the attribute classification model, a target loss function for adversarial learning can be constructed based on the two loss functions.
[0154] In step 209, the computer device determines the target loss function according to the difference between the first loss function and the second loss function.
[0155] Wherein, after obtaining the first loss function of the initial animal face recognition model and the second loss function of the attribute classification model, a new target loss function meeting the requirement that the model only has identity recognition ability but does not have attribute classification ability can be further constructed based on the first loss function and the second loss function. As mentioned before, the initial animal face recognition model has the best identity recognition ability and attribute classification ability when the first loss function is minimized, and the attribute classification model has the best attribute classification ability when the second loss function is minimized. Thus, to obtain the best identity recognition ability without attribute classification ability, the attribute classification ability needs to be the worst, so the positive data of the first loss function and the negative data of the second loss function can be used to determine the target loss function. That is, the difference between the first loss function and the second loss function is calculated to obtain the target loss function. When the target loss function is optimal, that is, the target loss function is minimized, the first loss function is minimized, that is, the optimal identity recognition ability can be obtained; and the second loss function is maximized, that is, the worst attribute classification ability can be obtained, so the target animal face recognition model with only good identity recognition ability but without attribute classification ability can be trained based on the target loss function.
[0156] Specifically, the expression of the target loss function can be as shown in the following formula (4):
[0157]
[0158] Wherein, θ f is the image feature of the animal face image in the training sample data, θ y is the identity label of the animal face image, θ d is the attribute label of the animal face image. is the first loss function value corresponding to the animal face image, is the second loss function value corresponding to the animal face image. n represents the sample quantity, and λ is a hyperparameter. Wherein, and
[0159] Therefore, the optimization goal of the target loss function is to make the animal face recognition model maintain the identity recognition ability but not the ability to distinguish attribute categories.
[0160] Step 210, the computer device optimizes the target loss function to update the parameters of the initial animal face recognition model, and obtains a target animal face recognition model.
[0161] Wherein, after determining the target loss function for further training of the initial animal face recognition model, an attribute information elimination layer can be introduced during model training, and the role of the layer is to be consistent with the input and output when doing forward, that is, R(X) = X. Wherein X is the input of the attribute information elimination layer, and R(X) is the output of the attribute information elimination layer. When performing gradient update, the gradient passing through the layer is adjusted, and the formula is expressed as formula (5):
[0162]
[0163] Wherein, I is the gradient, and γ is a function that changes with the iteration step p, and its expression is shown in formula (6) as follows:
[0164]
[0165] Wherein, k is the total iteration step.
[0166] During the training process, the attribute classification network classifies the attribute information of the features generated by the initial animal face recognition model, and optimizes normally in its network. The attribute information elimination layer is connected with the initial animal face recognition model, and the gradient of the attribute classification network is applied to the initial animal face recognition model in reverse, so that the features extracted by the initial animal face recognition model do not contain information that can be used to distinguish attributes, so as to learn the common information between objects with different attributes, thereby improving the accuracy of animal face recognition in complex scenes.
[0167] The present application adopts an unsupervised clustering algorithm to perform unsupervised clustering on animal face recognition training data. The implicit attributes contained in the animal face recognition training sample data are distinguished. Then, the attribute classification model is used to recognize the attributes of the features learned by the animal face recognition model, and the animal face attribute information elimination operation is performed on the features extracted by the animal face recognition model in an adversarial learning manner, so that the features extracted by the animal face recognition model do not contain information that can distinguish attributes, so that the distribution of objects with different attributes in the feature space is balanced, thereby improving the accuracy of animal face recognition in complex scenes.
[0168] According to the above description, the model training method provided in the present application obtains training sample data, and the training sample data includes multiple animal facial images and label data corresponding to each animal facial image; trains a first neural network model based on the training sample data to obtain a first animal facial recognition model; performs attribute clustering analysis on multiple animal facial images to obtain attribute labels corresponding to each animal facial image; uses the first animal facial recognition model to extract image features of each animal facial image, and trains a second neural network model based on the image features and attribute labels of each animal facial image to obtain an attribute classification model; adjusts the model parameters of the first animal facial recognition model based on the attribute classification model to obtain a second animal facial recognition model.
[0169] Therefore, the model training method provided in this application clusters the attributes of the features of animal facial images, trains an attribute classification model based on the clustering results, and then adjusts the animal facial recognition model based on the trained attribute classification model to decouple the attribute classification of the animal facial recognition model. This can avoid the model bias problem caused by the uneven distribution of different types of data in the training samples, thereby improving the accuracy of the animal facial recognition model.
[0170] The present application also provides an image recognition method, which can be used in a computer device, which can be a terminal or a server. Figure 4 FIG. 1 is another flow chart of the image recognition method provided by the present application, and the method specifically includes:
[0171] Step 301: Acquire a facial image of a target animal.
[0172] The target animal facial image is an animal facial image that requires animal facial recognition, and specifically may be an animal facial image captured by an animal facial image capturing terminal.
[0173] Step 302: Use a preset neural network model to identify the target animal's facial image to obtain target identity information corresponding to the target animal's facial image.
[0174] Among them, the preset neural network model here can be Figure 2 The second animal face recognition model provided in the corresponding embodiment or Figure 3 The target animal face recognition model in the corresponding embodiment.
[0175] The preset neural network model is used to identify the target animal's facial image, and only its identity information is determined without extracting the attribute features in the target animal's facial image. Therefore, the interference of attribute information on the identity recognition result can be avoided, and more accurate target identity information can be obtained.
[0176] To better implement the above model training method, an embodiment of the present application further provides a model training device, which can be integrated in a terminal or a server.
[0177] For example, as shown in Figure 5 Fig. 1 is a structural schematic diagram of a model training device provided by an embodiment of the present application, which can include a first obtaining unit 401, a first training unit 402, an analyzing unit 403, a second training unit 404, and an adjusting unit 405, as follows:
[0178] The first obtaining unit 401 is configured to obtain training sample data, which includes a plurality of animal face images and label data corresponding to each animal face image.
[0179] The first training unit 402 is configured to train a first neural network model according to the training sample data, to obtain a first animal face recognition model.
[0180] The analyzing unit 403 is configured to perform attribute clustering analysis on the plurality of animal face images, to obtain an attribute label corresponding to each animal face image.
[0181] The second training unit 404 is configured to extract image features of each animal face image using the first animal face recognition model, and train a second neural network model based on the image features and the attribute label of each animal face image, to obtain an attribute classification model.
[0182] The adjusting unit 405 is configured to adjust model parameters of the first animal face recognition model based on the attribute classification model, to obtain a second animal face recognition model.
[0183] In some embodiments, the analyzing unit includes:
[0184] The dividing sub-unit is configured to divide the plurality of animal face images according to identity information corresponding to each image, to obtain an animal face image set corresponding to each identity information.
[0185] The first extracting sub-unit is configured to extract image features of each animal face image in each animal face image set using the first animal face recognition model, to obtain an image feature set corresponding to each identity information.
[0186] The second calculating sub-unit is configured to calculate a mean value of a plurality of image features included in each image feature set, to obtain an identity feature corresponding to each identity information.
[0187] The determining sub-unit is configured to perform attribute clustering analysis based on the identity feature corresponding to each identity information, to obtain an attribute label corresponding to each identity information, and determine an attribute label corresponding to each animal face image according to the attribute label corresponding to each identity information.
[0188] In some embodiments, the determining subunit comprises:
[0189] The clustering module is configured to perform feature clustering based on the identity features corresponding to each identity information, to obtain a plurality of cluster center features.
[0190] The computing module is configured to calculate the similarity between each identity feature and each cluster center feature, and determine the cluster center feature corresponding to each identity feature according to the similarity.
[0191] The determining module is configured to determine the attribute label corresponding to each identity information according to the cluster center feature corresponding to each identity feature.
[0192] In some embodiments, the adjusting unit comprises:
[0193] The obtaining subunit is configured to obtain a first loss function corresponding to the first animal face recognition model and a second loss function corresponding to the attribute classification model.
[0194] The first generating subunit is configured to generate a target loss function based on the difference between the first loss function and the second loss function.
[0195] The first adjusting subunit is configured to adjust the model parameters of the first animal face recognition model according to the target loss function, to obtain a second animal face recognition model.
[0196] In some embodiments, the adjusting unit comprises:
[0197] The computing module is configured to perform optimization calculation on the target loss function by using the gradient descent method, until a preset convergence condition is reached, to obtain a target model parameter value.
[0198] The updating module is configured to update the model parameters in the first animal face recognition model according to the target model parameter value, to obtain a second animal face recognition model.
[0199] In some embodiments, the second training unit comprises:
[0200] The second extracting subunit is configured to extract the image features of each animal face image by using the first animal face recognition model.
[0201] The input subunit is configured to input the image features of each animal face image into the second neural network model, to obtain an output result corresponding to each animal face image.
[0202] The second computing subunit is configured to calculate the cross-entropy between the output result corresponding to each animal face image and the corresponding attribute label, to obtain a loss function.
[0203] The training subunit is configured to train the second neural network model based on the loss function to obtain the attribute classification model.
[0204] In some embodiments, the adjusting unit comprises:
[0205] The second generation subunit is configured to train a generative adversarial network according to the label data corresponding to each animal face image and the attribute label.
[0206] The third generation subunit is configured to generate the supplementary sample data by using the generative adversarial network.
[0207] The supplementing subunit is configured to add the supplementary sample data to the training sample data to obtain target training sample data.
[0208] The second adjusting subunit is configured to adjust the parameters of the first animal face recognition model based on the target training sample data by using the attribute classification model to obtain a second animal face recognition model.
[0209] In specific implementation, each of the above units can be implemented as an independent entity, or can be combined as the same or several entities, and the specific implementation of each of the above units can be referred to the method embodiments above, which will not be described herein.
[0210] According to the above description, the model training apparatus provided by the embodiments of the present application can obtain the training sample data by using the first obtaining unit 401, the training sample data comprises a plurality of animal face images and label data corresponding to each animal face image; the first training unit 402 trains the first neural network model according to the training sample data to obtain the first animal face recognition model; the analysis unit 403 performs attribute clustering analysis on the plurality of animal face images to obtain the attribute label corresponding to each animal face image; the second training unit 404 extracts the image features of each animal face image by using the first animal face recognition model, and trains the second neural network model based on the image features of each animal face image and the attribute label to obtain the attribute classification model; and the adjusting unit 405 adjusts the model parameters of the first animal face recognition model based on the attribute classification model to obtain the second animal face recognition model.
[0211] Therefore, the model training method provided by the embodiments of the present application can perform attribute clustering on the features of the animal face images, train the attribute classification model according to the clustering results, and then adjust the animal face recognition model based on the trained attribute classification model to decouple the attribute classification of the animal face recognition model, so as to avoid the model bias problem caused by the uneven distribution of different types of data in the training sample, thereby improving the accuracy of the animal face recognition model.
[0212] In order to better implement the above image recognition method, an image recognition device is further provided in the embodiments of the present application, which can be integrated in a terminal or a server.
[0213] For example, as shown in Figure 6 Fig. 1 is a structural schematic diagram of an image recognition device provided by the embodiments of the present application. The image recognition device can include a second acquisition unit 501 and a recognition unit 502, as follows:
[0214] The second acquisition unit 501 is configured to acquire a target animal face image.
[0215] The recognition unit 502 is configured to recognize the target animal face image by using a preset neural network model to obtain target identity information corresponding to the target animal face image, wherein the preset neural network model is the second animal face recognition model or the target animal face recognition model trained in the above model training method.
[0216] The embodiments of the present application further provide a computer device, which can be a terminal or a server. As shown in Figure 7 Fig. 2 is a structural schematic diagram of a computer device provided by the present application. Specifically:
[0217] The computer device can include a processing unit 601 having one or more processing cores, a storage unit 602 having one or more storage media, a power module 603, an input module 604, and the like. Those skilled in the art can understand that the computer device structure shown in Figure 7 does not constitute a limitation on the computer device, which can include more or fewer components than those shown, or combine certain components, or different component arrangements. Among them:
[0218] The processing unit 601 is the control center of the computer device, which connects various parts of the computer device through various interfaces and lines, and performs various functions of the computer device and processes data by running or executing software programs and / or modules stored in the storage unit 602 and calling data stored in the storage unit 602. Optionally, the processing unit 601 can include one or more processing cores; preferably, the processing unit 601 can integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, the object interface and the application program, etc., and the modem processor mainly processes wireless communication. It can be understood that the above-mentioned modem processor can also not be integrated into the processing unit 601.
[0219] The storage unit 602 can be used to store software programs and modules, and the processing unit 601 executes various functional applications and data processing by running the software programs and modules stored in the storage unit 602. The storage unit 602 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, application programs required by at least one function (such as a sound playing function, an image playing function, and a webpage access, etc.), and the like; and the data storage area can store data created according to the use of the computer device, etc. In addition, the storage unit 602 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other volatile solid-state memory device. Accordingly, the storage unit 602 can also include a memory controller to provide access for the processing unit 601 to the storage unit 602.
[0220] The computer device also includes a power module 603 for powering various components. Preferably, the power module 603 can be logically connected to the processing unit 601 through a power management system, so as to realize functions such as charge management, discharge management, and power consumption management through the power management system. The power module 603 can also include one or more than one direct current or alternating current power supply, a recharging system, a power failure detection circuit, a power converter or inverter, a power state indicator, and the like.
[0221] The computer device can also include an input module 604, which can be used to receive input digital or character information, and generate keyboard, mouse, joystick, optical or trackball signal inputs related to object settings and function controls.
[0222] Although not shown, the computer device can also include a display unit, etc., which will not be described here. Specifically, in the present embodiment, the processing unit 601 in the computer device will load one or more than one executable file corresponding to the process of an application program into the storage unit 602 according to the following instructions, and run the application program stored in the storage unit 602 by the processing unit 601, so as to realize various functions, as follows:
[0223] Obtaining training sample data, the training sample data including a plurality of animal face images and label data corresponding to each animal face image; training a first neural network model according to the training sample data to obtain a first animal face recognition model; performing attribute clustering analysis on the plurality of animal face images to obtain an attribute label corresponding to each animal face image; extracting an image feature of each animal face image by using the first animal face recognition model, and training a second neural network model based on the image feature and the attribute label of each animal face image to obtain an attribute classification model; and adjusting model parameters of the first animal face recognition model based on the attribute classification model to obtain a second animal face recognition model.
[0224] Alternatively, the target animal face image is acquired, a preset neural network model is used to recognize the target animal face image, and target identity information corresponding to the target animal face image is obtained. The preset neural network model is an animal face recognition model trained according to the model training method provided in the present application.
[0225] It should be noted that the computer device provided in the embodiments of the present application and the method in the above embodiments belong to the same concept, and the specific implementation of the above operations can be referred to the previous embodiments, which will not be repeated here.
[0226] Those skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructions, or by instructions controlling related hardware, which can be stored in a computer readable storage medium and loaded and executed by a processor.
[0227] To this end, the embodiments of the present application provide a computer readable storage medium, which stores a plurality of instructions capable of being loaded by a processor to execute the steps in any one of the methods provided by the embodiments of the present application. For example, the instructions can execute the following steps:
[0228] The training sample data is acquired, the training sample data includes a plurality of animal face images and label data corresponding to each animal face image; a first neural network model is trained according to the training sample data to obtain a first animal face recognition model; attribute clustering analysis is performed on the plurality of animal face images to obtain an attribute label corresponding to each animal face image; an image feature of each animal face image is extracted using the first animal face recognition model, and a second neural network model is trained based on the image feature of each animal face image and the attribute label to obtain an attribute classification model; and the model parameters of the first animal face recognition model are adjusted based on the attribute classification model to obtain a second animal face recognition model.
[0229] Alternatively, the target animal face image is acquired, a preset neural network model is used to recognize the target animal face image, and target identity information corresponding to the target animal face image is obtained. The preset neural network model is an animal face recognition model trained according to the model training method provided in the present application.
[0230] The specific implementation of the above operations can be referred to the previous embodiments, which will not be repeated here.
[0231] The computer readable storage medium can include a read only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0232] Since the steps in any of the methods provided by the embodiments of the present application can be executed due to the instructions stored in the computer readable storage medium, the beneficial effects that can be achieved by any of the methods provided by the embodiments of the present application can be achieved, which are described in detail in the foregoing embodiments and will not be described here again.
[0233] According to an aspect of the present application, a computer program product or computer program is provided, which includes computer instructions stored in a storage medium. A processor of a computer device reads the computer instructions from the storage medium, and the processor executes the computer instructions, so that the computer device executes the method provided in any of the optional implementation manners of the model training method or the image recognition method.
[0234] The model training method and device, the image recognition method and device provided by the embodiments of the present application are described in detail above, and the principles and implementation manners of the present application are described by applying specific examples in this paper. The above description of the embodiments is only used to help understand the method of the present application and its core idea; meanwhile, for those skilled in the art, the specific implementation manners and application ranges will be changed according to the idea of the present application. In conclusion, the content of the specification should not be understood as a limitation of the present application.
Claims
1. A model training method, characterized in that: The method comprises: Acquire training sample data, where the training sample data includes a plurality of animal face images and label data corresponding to each animal face image; Training a first neural network model according to the training sample data to obtain a first animal face recognition model; Performing attribute cluster analysis on the plurality of animal facial images to obtain an attribute label corresponding to each animal facial image; Extracting image features of each animal face image using the first animal face recognition model, and training a second neural network model based on the image features and attribute labels of each animal face image to obtain an attribute classification model; The model parameters of the first animal face recognition model are adjusted based on the attribute classification model to obtain a second animal face recognition model.
2. The method according to claim 1, characterized in that The performing attribute cluster analysis on the plurality of animal facial images to obtain an attribute label corresponding to each animal facial image includes: Dividing the plurality of animal facial images according to the identity information corresponding to each image to obtain a set of animal facial images corresponding to each identity information; extracting image features of each animal face image in each animal face image set using the first animal face recognition model to obtain an image feature set corresponding to each piece of identity information; Calculate the mean of multiple image features contained in each image feature set to obtain the identity feature corresponding to each identity information; Based on the identity features corresponding to each identity information, attribute cluster analysis is performed to obtain the attribute label corresponding to each identity information, and the attribute label corresponding to each animal face image is determined based on the attribute label corresponding to each avatar information.
3. The method according to claim 2, characterized in that The attribute cluster analysis is performed based on the identity features corresponding to each identity information to obtain the attribute label corresponding to each identity information, including: Perform feature clustering based on the identity features corresponding to each identity information to obtain multiple cluster center features; Calculating the similarity between each identity feature and each cluster center feature, and determining the cluster center feature corresponding to each identity feature based on the similarity; The attribute label corresponding to each identity information is determined according to the cluster center feature corresponding to each identity feature.
4. The method according to claim 1, wherein The adjusting the model parameters of the first animal face recognition model based on the attribute classification model to obtain a second animal face recognition model includes: Obtaining a first loss function corresponding to the first animal face recognition model and a second loss function corresponding to the attribute classification model; generating a target loss function based on the difference between the first loss function and the second loss function; The model parameters of the first animal face recognition model are adjusted according to the target loss function to obtain a second animal face recognition model.
5. The method according to claim 4, characterized in that The adjusting the model parameters of the first animal face recognition model according to the target loss function to obtain a second animal face recognition model includes: The target loss function is optimized and calculated using the gradient descent method until a preset convergence condition is reached to obtain the target model parameter value; The model parameters in the first animal face recognition model are updated according to the target model parameter values to obtain a second animal face recognition model.
6. The method according to claim 1, characterized in that The method of extracting image features of each animal face image using the first animal face recognition model and training a second neural network model based on the image features and attribute labels of each animal face image to obtain an attribute classification model includes: extracting image features of each animal face image using the first animal face recognition model; Inputting the image features of each animal face image into the second neural network model to obtain an output result corresponding to each animal face image; Calculate the cross entropy between the output result corresponding to each animal face image and the corresponding attribute label to obtain the loss function; The second neural network model is trained based on the loss function to obtain an attribute classification model.
7. The method according to claim 1, characterized in that The adjusting the model parameters of the first animal face recognition model based on the attribute classification model to obtain a second animal face recognition model includes: Train a generative adversarial network based on the label data and attribute labels corresponding to each animal face image; Generating supplementary sample data using the generative adversarial network; Adding the supplementary sample data to the training sample data to obtain target training sample data; The attribute classification model is used to adjust the parameters of the first animal face recognition model based on the target training sample data to obtain a second animal face recognition model.
8. An image recognition method, characterized in that: The method comprises: Acquire the target animal's facial image; A preset neural network model is used to identify the target animal facial image to obtain target identity information corresponding to the target animal facial image. The preset neural network model is the second animal facial recognition model in the model training method according to any one of claims 1 to 7.
9. A model training device, characterized in that: The device comprises: a first acquiring unit, configured to acquire training sample data, wherein the training sample data includes a plurality of animal face images and label data corresponding to each animal face image; a first training unit, configured to train a first neural network model based on the training sample data to obtain a first animal face recognition model; an analyzing unit, configured to perform attribute clustering analysis on the plurality of animal facial images to obtain an attribute label corresponding to each animal facial image; a second training unit, configured to extract image features of each animal face image using the first animal face recognition model, and train a second neural network model based on the image features and attribute labels of each animal face image to obtain an attribute classification model; An adjustment unit is configured to adjust the model parameters of the first animal face recognition model based on the attribute classification model to obtain a second animal face recognition model.
10. The device according to claim 9, characterized in that The analysis unit comprises: a dividing subunit, configured to divide the plurality of animal facial images according to the identity information corresponding to each image, to obtain a set of animal facial images corresponding to each identity information; an extraction subunit, configured to extract image features of each animal face image in each animal face image set using the first animal face recognition model, to obtain an image feature set corresponding to each identity information; A calculation subunit, configured to calculate the mean of multiple image features contained in each image feature set to obtain an identity feature corresponding to each identity information; The determination subunit is used to perform attribute cluster analysis based on the identity features corresponding to each identity information to obtain the attribute label corresponding to each identity information, and determine the attribute label corresponding to each animal face image based on the attribute label corresponding to each avatar information.
11. The device according to claim 10, characterized in that The determining subunit includes: A clustering module is used to perform feature clustering based on the identity features corresponding to each identity information to obtain multiple cluster center features; a calculation module, configured to calculate the similarity between each identity feature and each cluster center feature, and determine the cluster center feature corresponding to each identity feature based on the similarity; The determination module is used to determine the attribute label corresponding to each identity information according to the cluster center feature corresponding to each identity feature.
12. An image recognition device, characterized in that: The device comprises: a second acquiring unit, configured to acquire a facial image of a target animal; An identification unit is used to identify the target animal facial image using a preset neural network model to obtain target identity information corresponding to the target animal facial image, wherein the preset neural network model is the second animal facial recognition model in the model training method according to any one of claims 1 to 7.
13. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a plurality of instructions, which are suitable for loading by a processor to execute the steps in the model training method described in any one of claims 1 to 7 or the image recognition method described in claim 8.
14. A computer device, characterized in that: It includes a memory, a processor, and a computer program stored in the memory and capable of running on the processor, wherein when the processor executes the computer program, it implements the steps in the model training method described in any one of claims 1 to 7 or the image recognition method described in claim 8.
15. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps in the model training method described in any one of claims 1 to 7 or the image recognition method described in claim 8 are implemented.
Citation Information
Patent Citations
Object identification method and device
CN111191655A
Information acquisition method and system based on multi-modal interaction
CN112069484A