Model determination method and related apparatus
By generating image sample features of different scene parameters and using texture images, the recognition model is trained, which solves the generalization problem of cross-scenario and cross-attack type recognition, and improves the recognition accuracy and application value.
Patent Information
- Application Number
- PCT/CN2024/071927
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-03-07
- Filing Date
- 2024-01-12
- Publication Date
- 2024-10-24
AI Technical Summary
Existing recognition models are difficult to meet the required generalization requirements when faced with cross-scenario recognition and cross-attack type recognition, resulting in limited application value.
By generating second image sample features with different scene parameters but the same recognition label, and combining them with texture images, the recognition loss function is used to train the initial recognition model to improve the model's recognition capabilities for different scene environments and diverse attacks.
It realizes the good generalization ability of the recognition model under cross-scenarios and cross-attack types, improves the recognition accuracy and security, and expands the application value of the model.
Smart Images

Figure CN2024071927_24102024_PF_FP_ABST
Abstract
Description
A model determination method and related device
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on March 7, 2023, with application number 2023102602211 and application name “A model determination method and related device”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] This application relates to the field of artificial intelligence, and in particular to model training technology. Background Art
[0003] A recognition model refers to a model that identifies the type of object in an image. By training the initial recognition model based on a certain number of image samples, a recognition model with certain recognition capabilities can be obtained. This recognition model can be applied to many aspects of production and life.
[0004] In actual applications, recognition models often encounter multiple recognition scenarios and multiple attack types, and may even encounter new recognition scenarios and new attack types that have never been encountered during training. For example, when training a recognition model, it is trained based on image samples of indoor scenes, but in actual applications, the recognition images encountered by the recognition model may be images of outdoor scenes. Or, when the recognition model is used to identify living things, the attack type of the image samples used when training the recognition model is to disguise real living things through photos, but in actual applications, the attack type of the recognition images encountered by the recognition model may be to disguise real living things through video replay. In other words, recognition models will encounter a variety of recognition scenarios and attack types in actual applications.
[0005] However, when recognizing the type of objects in images, the recognition models trained in related technologies have difficulty meeting the required generalization requirements for cross-scene recognition and cross-attack type recognition, which makes it difficult for the recognition models to be widely used.
[0006] Summary of the Invention
[0007] In order to solve the above technical problems, the present application provides a model determination method and related devices, which can train a recognition model with good generalization capabilities for cross-scene recognition and cross-attack type recognition.
[0008] The embodiments of this application disclose the following technical solutions:
[0009] In one aspect, an embodiment of the present application provides a model determination method, which is executed by a computer device, and the method includes:
[0010] obtaining a first image sample, wherein the first image sample has an identification label that identifies an object type to which an object in the first image sample belongs;
[0011] Inputting the first image sample into an initial encoder of an initial recognition model to obtain a first image sample feature of the first image sample, the initial recognition model further comprising an initial decoder and an initial classifier;
[0012] generating a second image sample feature based on the first image sample feature, where the second image sample feature and the first image sample feature have different scene parameter values and correspond to the same identification label;
[0013] Inputting the first image sample feature and the second image sample feature into the initial decoder respectively to obtain a first texture image corresponding to the first image sample feature and a second texture image corresponding to the second image sample feature;
[0014] Inputting the first image sample features and the first texture image into the initial classifier to obtain a first prediction result of the object type; and inputting the second image sample features and the second texture image into the initial classifier to obtain a second prediction result of the object type;
[0015] generating a recognition loss function based on differences between the first prediction result and the second prediction result and the recognition label;
[0016] The initial recognition model is trained using the recognition loss function to obtain an updated recognition model.
[0017] On the other hand, an embodiment of the present application provides a model determination device, which includes a sample acquisition unit, a first determination unit, a first generation unit, a texture acquisition unit, a second determination unit, a second generation unit, and a training unit:
[0018] The sample acquisition unit is configured to obtain a first image sample, wherein the first image sample has an identification tag that identifies an object type to which an object in the first image sample belongs;
[0019] The first determining unit is configured to input the first image sample into an initial encoder of an initial recognition model to obtain a first image sample feature of the first image sample, the initial recognition model further comprising an initial decoder and an initial classifier;
[0020] The first generating unit is configured to generate a second image sample feature based on the first image sample feature, where the second image sample feature and the first image sample feature have different scene parameter values and correspond to the same identification label;
[0021] The texture acquisition unit is configured to input the first image sample feature and the second image sample feature into the initial decoder respectively, so as to obtain a first texture image corresponding to the first image sample feature and a second texture image corresponding to the second image sample feature;
[0022] The second determining unit is configured to input the first image sample feature and the first texture image into the initial classifier to obtain a first prediction result of the object type, and input the second image sample feature and the second texture image into the initial classifier to obtain a second prediction result of the object type;
[0023] The second generating unit is configured to generate a recognition loss function based on differences between the first prediction result and the second prediction result and the recognition label;
[0024] The training unit is used to train the initial recognition model using the recognition loss function to obtain an updated recognition model.
[0025] In another aspect, an embodiment of the present application provides a computer device, comprising a processor and a memory:
[0026] The memory is used to store computer programs and transmit computer programs to the processor;
[0027] The processor is configured to execute the above-described method according to the computer program.
[0028] In another aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store a computer program, and the computer program is used to execute the method described in the above aspects.
[0029] On the other hand, an embodiment of the present application provides a computer program product including a computer program, which, when executed on a computer device, enables the computer device to execute the method described in the above aspects.
[0030] It can be seen from the above technical solution that the present application provides a training method for a recognition model for identifying the object type of an object in an image, and the initial recognition model to be trained includes an initial encoder, an initial decoder and an initial classifier. When specifically training the initial recognition model, the first image sample feature of the first image sample is first determined by the initial encoder, and the first image sample has an identification label that identifies the object type to which the object belongs; in order to improve the model's recognition ability for objects in different scene environments, in the present application, a second image sample feature is generated based on the first image sample feature, and the second image sample feature has a different scene parameter value from the first image sample feature, but corresponds to the same identification label. For these two image sample features, the corresponding texture image can be obtained through the initial decoder, and the corresponding object type prediction result can be determined by the initial classifier based on the image sample feature and the corresponding texture image. Then, the recognition loss function generated based on the identification label and the prediction result is used to train the initial recognition model to obtain an updated recognition model. By performing a cross-scene conversion on the first image sample features, a second image sample feature with different scene parameters and the same identification label as the first image sample feature is obtained. This allows the initial recognition model to learn the ability to recognize the same object in different scene environments during the training process. In addition, by directly performing a cross-scene conversion on the first image sample features, the encoding processing of additional samples is avoided, which will not have a substantial impact on the model training efficiency. When predicting the object type, in addition to image sample features, texture images are further introduced to express image information more richly from the feature dimension and texture dimension, so that the initial recognition model learns more accurate recognition capabilities during the training process and can cope with more diverse recognition attack methods. The recognition model trained in this way has good generalization capabilities for images with different scenes and images generated by different methods when performing object recognition, which effectively improves the model recognition accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] FIG1 is a schematic diagram of a model determination scenario provided in an embodiment of the present application;
[0032] FIG2 is a flow chart of a model determination method provided in an embodiment of the present application;
[0033] FIG3 is a schematic diagram of a cross-scene conversion of image sample features provided in an embodiment of the present application;
[0034] FIG4 is a schematic diagram of an attention mechanism provided in an embodiment of the present application;
[0035] FIG5 is a schematic diagram of a detail enhancement attention mechanism provided in an embodiment of the present application;
[0036] FIG6 is a specific schematic diagram of a model determination method provided in an embodiment of the present application;
[0037] FIG7 is a test diagram of a recognition model provided in an embodiment of the present application;
[0038] FIG8 is a schematic diagram of a device for a model determination method provided in an embodiment of the present application;
[0039] FIG9 is a structural diagram of a terminal device provided in an embodiment of the present application;
[0040] FIG10 is a structural diagram of a server provided in an embodiment of the present application. DETAILED DESCRIPTION
[0041] The embodiments of the present application are described below with reference to the accompanying drawings.
[0042] Recognition models can be applied to many aspects of production and life. For example, the liveness recognition model in the recognition model can identify whether the face in the face image is from a real living person, thereby verifying the authenticity of the user. The liveness recognition model can resist false face attacks to effectively ensure the security of the face recognition system. That is, the liveness recognition model can be widely used in production and life as an important part of the face recognition system. For example, during the remote bank account opening process, the server will use the facial recognition system to confirm the true identity of the account holder, in which the liveness recognition model is applied. After the application front end obtains the image containing the user's face through the camera, the application front end will transmit the image containing the user's face to the back end and call the liveness recognition model to perform liveness recognition. If it is determined that the face in the image is from a living person, subsequent identity verification operations will be performed, otherwise the identity verification will fail directly; in the process of facial payment through the facial recognition system, the liveness recognition model can improve the security of payment. The liveness recognition model can defend against some transaction attacks that will cause losses to enterprises or individuals, and ensure the security of facial payment; when using the facial recognition system to achieve community security, the facial recognition system can directly obtain the facial image at the front end, and then send the facial image to the encapsulated liveness recognition model for direct judgment.
[0043] The application value of a recognition model is usually determined by its generalization performance. The higher the generalization performance of a recognition model, the more application scenarios the model has, and the higher its corresponding application value. Therefore, in order to ensure the application value of a recognition model, it is necessary to ensure that the recognition model has better generalization performance. Related technologies mainly conduct model training from two aspects to improve generalization performance.
[0044] On the one hand, we focus on improving the generalization performance of recognition models in various recognition scenarios, among which various recognition scenarios may also include unknown recognition scenarios (unknown domains). Unknown domains include different scenes, lighting, acquisition equipment accuracy and other characteristics compared with training image samples. This aspect mainly includes the technology of image classification domain generalization tasks. Through domain adversarial training or meta-learning and other strategies, the model learns domain-independent features to enable the model to achieve better generalization performance in unknown domains. For example, for liveness recognition models, there is a single-side domain generation (Single-Side Domain Generalization for Face Anti-Spoofing, SSDG) algorithm in related technologies. This algorithm uses a domain discriminator to identify live face features from different domains extracted by the feature extractor. When the live face features extracted by the feature extractor can well allow the domain discriminator to identify them as live faces, the features are considered to be cross-domain-independent features. Therefore, the features may also have good recognition capabilities in unknown domains.
[0045] On the other hand, the focus is on improving the detection ability of the recognition model when facing various attack types, especially the detection ability of new attack types; for example, taking the liveness recognition model as an example, the attack types include photos, videos, face-changing, masks and other attack types that can provide false faces. New attack types include attack types that have not appeared in the training image samples. This aspect mainly adopts zero-shot learning or anomaly detection strategies to improve the generalization performance of the model in the face of new attack types, aiming to allow the model to learn attack clues that can be generalized to new attack types; for example, for the liveness recognition model, there is a deep learning tree network (Deep Tree Learning for Zero-shot Face Anti-Spoofing, DTN) algorithm in the related technology. This algorithm uses a zero-shot learning method to divide known attack types into several clusters according to semantics, and perform binary classification liveness detection in each cluster. When facing a new attack type, the new attack type image will be routed to the most similar cluster for binary classification, thereby improving the generalization ability of the liveness recognition model in the face of new attack types.
[0046] However, when the recognition models trained in related technologies identify the types of objects in images in actual applications, recognition scene changes and new attack types may exist at the same time. For example, a liveness recognition model trained using photo attacks in indoor scenes may encounter video replay attacks in outdoor scenes in actual applications. That is, the recognition model will face multiple new recognition scenarios and new attack types, and may even encounter unknown recognition scenarios and new attack types at the same time. At this time, the models trained in related technologies are difficult to meet the required generalization requirements.
[0047] To this end, the embodiments of the present application provide a model determination method and related devices, which not only improve the recognition model's ability to recognize the same object in different recognition environments during the training process, but also allow the model to learn more accurate recognition capabilities during the training process, thereby effectively defending against various types of attacks, thereby obtaining a recognition model with good generalization capabilities for cross-scene recognition and cross-attack type recognition.
[0048] The model determination method provided in the embodiments of the present application can be implemented by a computer device, which can be a terminal device or a server, wherein the server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. Terminal devices include but are not limited to mobile phones, computers, intelligent voice interaction devices, smart home appliances, vehicle-mounted terminals, aircraft, etc. The terminal device and the server can be directly or indirectly connected via wired or wireless communication, which is not limited in this application.
[0049] FIG1 is a schematic diagram of an application scenario of a model determination method provided in an embodiment of the present application, wherein the aforementioned computer device is a server.
[0050] A recognition model refers to a model that identifies the type of object in an image. The recognition model can be obtained by training and optimizing the initial recognition model. In actual applications, the recognition model will encounter multiple recognition scenarios and multiple attack types, and may even encounter unknown recognition scenarios and new attack types that have not been encountered during training. However, when performing object type recognition, the recognition models trained in related technologies face cross-scenario recognition and cross-attack type recognition, and it is difficult to meet the required generalization requirements, thereby reducing the application value of the recognition model.
[0051] In this regard, in the application scenario of this embodiment, the initial recognition model to be trained includes an initial encoder E, an initial decoder D and an initial classifier C. As shown in Figure 1, the initial encoder E can obtain image features that can reflect image information in the feature dimension from image samples, the initial decoder D can generate a texture image that can reflect image information in the texture dimension based on the image features, and the initial classifier C can perform comprehensive recognition of the image based on the image features and the texture image.
[0052] Specifically, the server can input the first image sample into the initial encoder to obtain the corresponding first image sample feature, and in order to improve the recognition ability of the model in different recognition scenarios, the server will generate a second image sample feature based on the first image sample feature, and the first image sample feature and the second image sample feature identify different scene environments but have the same recognition label. For these two image sample features, the corresponding texture image can be obtained through the initial decoder, and the corresponding object type prediction result is determined by the initial classifier based on the image sample feature and the corresponding texture image, and the recognition loss function generated based on the object type prediction result and the recognition label is used to train the initial recognition model to obtain the recognition model. Based on the first image sample feature, a second image sample feature that identifies a different recognition environment but has the same recognition label is generated, and both image sample features are used for the training of the initial recognition model. This can improve the model's recognition ability for the same object in different recognition environments on the basis of expanding the scene environment encountered by the model.
[0053] Moreover, the server directly performs cross-scene conversion on the features of the first image sample. Compared with first performing cross-scene conversion on the first image sample to obtain the corresponding cross-scene image sample, and then determining the corresponding second image sample features based on the cross-scene image sample, this operation reduces the additional computational effort and ensures the training efficiency of the model.
[0054] In addition, when the server uses the initial classifier to identify object types, it not only refers to the image sample features, but also further refers to the texture image. That is to say, during the training process, the initial classifier comprehensively classifies image samples from the feature dimension and the texture dimension of the image, so that the initial recognition model learns more accurate recognition capabilities during the training process, and thus enables the trained recognition model to cope with more diverse recognition attack methods.
[0055] The recognition model trained by this embodiment has good generalization ability for cross-scene recognition and various attack types when performing object type recognition, and has good recognition accuracy.
[0056] FIG2 is a flow chart of a model determination method provided in an embodiment of the present application. The method may be executed by a computer device. In this embodiment, the computer device is described as a server. The method includes:
[0057] S201: The server obtains a first image sample, where the first image sample has an identification tag that identifies the object type to which an object in the first image sample belongs.
[0058] The first image sample refers to an image that can be used as a training sample for the initial recognition model. When the recognition model to be trained is a liveness recognition model, the first image sample can be various images of different people, specifically images of different faces, images of different human palms, etc. In order to realize the supervised learning training of the initial recognition model, the first image sample has a corresponding recognition label, which can identify the object type to which the object in the corresponding image sample actually belongs. For example, when the recognition model is a liveness recognition model, the recognition task of the liveness recognition model is to identify whether the object in the image sample is Living body, accordingly, the identification label of the first image sample is used to identify the object in the first image sample as living body or non-living body; more specifically, when the recognition model is a living body face recognition model, the recognition task of the living body face recognition model is to identify whether the face in the image sample is a living body face, accordingly, when the object type of the face in the first image sample is a real living body, the content of the corresponding identification label is a living body face, or, when the object type of the face in the first image sample is not a living body, the content of the corresponding identification label is a non-living body face, that is, the identification label can reflect the real object type to which the object in the image sample belongs.
[0059] S202: The server inputs the first image sample into an initial encoder of an initial recognition model to obtain a first image sample feature of the first image sample. The initial recognition model further includes an initial decoder and an initial classifier.
[0060] A recognition model refers to a model that identifies the type of object in an image. In practical applications, recognition models include a liveness recognition model for identifying whether the object in the currently acquired image is a real living object. Specifically, it can be used to identify whether the face in the currently acquired face image is from a real living object. It can also be a vehicle recognition model for identifying whether the vehicle in the currently acquired vehicle image is a specific vehicle, and other recognition models.
[0061] The initial recognition model refers to an initial model that can be trained using the first image sample to obtain a recognition model, that is, a recognition model that has not completed model training. The initial recognition model to be trained includes an initial encoder, an initial decoder, and an initial classifier, wherein the initial encoder, the initial decoder, and the initial classifier respectively refer to the encoder, decoder, and classifier that need to be trained and optimized, wherein the encoder can obtain image features that reflect image information in the feature dimension from the image, the decoder can generate a texture image that reflects image information in the texture dimension based on the image features, and the classifier can recognize the image based on the image information in the feature dimension and the texture dimension.
[0062] Image features refer to a series of quantifiable information reflected in an image. Image features can be used to characterize the content in the image or content related to the recognition task. In this embodiment, the first image sample feature refers to the image feature corresponding to the first image sample.
[0063] In this embodiment, the server determines the first image sample feature corresponding to the first image sample through the initial encoder. The first image sample feature can represent a series of information included in the first image sample in the feature dimension, that is, the initial encoder can realize preliminary analysis and processing of the first image sample before identifying the first image sample. The initial encoder is specifically used to perform feature encoding processing on the first image sample to obtain the corresponding first image sample feature; the so-called feature encoding processing refers to converting the image into feature data that can be processed by a computer, that is, image sample features, which can reflect the characteristics of the image. Specifically, a convolutional neural network structure can be used as the above-mentioned initial encoder, and through multiple cascaded convolution layers in the convolutional neural network structure, image sample features are extracted layer by layer from the input image sample, and finally the image sample features output by the last convolution layer are used as the above-mentioned first image sample features.
[0064] S203: The server generates a second image sample feature based on the first image sample feature. The second image sample feature and the first image sample feature have different scene parameter values and correspond to the same identification tag.
[0065] The scene parameter value of the image sample feature is used to reflect the content of the image other than the object to be identified, and can also be understood as the background content of the image other than the object, for example, it can include the background, lighting, accuracy of the acquisition device, and other content reflected in the image; accordingly, the scene parameter can be a background parameter, such as an image parameter used to reflect the background content of the face in the image, and further, it can be a parameter reflecting the background type, brightness, contrast, clarity, etc. It should be understood that image samples can be defined by scene parameters. In the embodiment of the present application, the first image sample corresponding to the first image sample feature and the second image sample corresponding to the second image sample feature are defined by different scene parameters. The two image samples have different scene information, such as different background, lighting, acquisition environment, acquisition device parameters, and other content.
[0066] When a recognition model identifies an image, it is affected by the scene environment in the image. For example, if an image sample is collected in a well-lit environment, the recognition model trained on this image sample will have good recognition capabilities for well-lit images in actual applications. However, if it encounters an image with insufficient lighting, the recognition model may not be able to accurately recognize the image, even if the object included in the image sample is the same as the object included in the image sample. Therefore, it is necessary to improve the recognition model's ability to identify the object type of objects in different scene environments.
[0067] In this regard, in this embodiment, a second image sample feature can be generated based on the first image sample feature. The second image sample feature has different scene parameters from the first image sample feature, but corresponds to the same identification label; it can also be understood that the second image sample feature corresponds to the second image sample, and the second image sample refers to a training sample with a different scene environment than the first image sample and the same identification label. Specifically, the scene environment of the second image sample is different from the scene environment of the first image sample. For example, the first image sample may be an indoor scene, and the second image sample may be an outdoor scene; the identification label of the second image sample is the same as the identification label of the first image sample, indicating that the object type of the objects included in the two is the same and may be the same object. For example, when the recognition model is a liveness recognition model, if the object type of the face in the first image sample is a live face, the object type of the face in the second image sample will also be live, and may be the same face. By obtaining a second image sample corresponding to the same identification label as the first image sample, and using both the second image sample and the first image sample for training the initial recognition model in subsequent steps, the initial recognition model is helped to better identify invariant features from the same object during subsequent training, thereby improving the recognition model's ability to recognize the same object in different scene environments.
[0068] It should be noted that, in this embodiment, the server directly generates the second image sample features based on the first image sample features determined in S202, rather than first performing scene conversion on the first image sample to obtain the corresponding second image sample, and then determining the corresponding second image sample features based on the second image sample. The reason for this processing is that encoding the second image sample through the initial encoder will increase the amount of calculation in the model training process, thereby affecting the training efficiency of the model. In addition, since the first image sample features can more fully reflect the information in the image sample, the second image sample features obtained through the first image sample features can retain more image features in the original first image sample.
[0069] A second image sample feature is generated based on the first image sample feature of the first image sample. Since the second image sample corresponding to the second image sample feature has a different scene environment from the first image sample, the scene environment encountered during model training can be expanded, thereby improving the model's ability to recognize the same object in different scene environments.
[0070] In one possible implementation, one round of training of the initial recognition model may include M (M is an integer greater than 1) first image samples. It should be noted that, in practical applications, the initial recognition model needs to be iteratively trained, that is, the training process of the initial recognition model includes multiple iterative rounds. In each iterative round, M first image samples can be used to train the initial recognition model, that is, the M first image samples can be respectively input into the initial recognition model to be trained. In this way, one round of training of the initial recognition model may include M first image samples.
[0071] Taking the jth (j is an integer greater than or equal to 1 and less than or equal to M) first image sample among the above M first image samples as an example, in S203, the server generates the second image sample feature based on the first image sample feature, specifically including:
[0072] S11 . For each other first image sample except the j-th first image sample among the M first image samples, the server determines a feature similarity between the j-th first image sample and the other first image sample in terms of first image sample features.
[0073] The first image sample feature refers to the image feature corresponding to the first image sample, and the second image sample feature refers to the image feature having different scene parameters from the first image sample feature but corresponding to the same identification label. Since the first image sample feature and the second image sample feature have different scene parameters, the second image sample feature generated based on the first image sample feature needs to have a large difference from the first image sample feature.
[0074] In this regard, for the j-th first image sample, the server may first determine the feature similarity between the first image sample features corresponding to the remaining M-1 first image samples in the M first image samples and the first image sample corresponding to the j-th first image sample. The feature similarity is used to indicate the degree of similarity between different first image samples in the image feature dimension. The higher the degree of similarity between the first image sample features of different first image samples, the larger the corresponding feature similarity value. The feature similarity may be cosine similarity. For example, the first image sample features of the same batch of image samples are first pooled into a sample feature vector v, and then the cosine similarity between the same batch of image samples may be determined by the following formula:
[0075] Where S represents the cosine similarity between the same batch of image samples, Softmax represents the normalization function, and v represents the sample feature vector v determined by the first image sample feature pooling of the same batch of image samples, v T represents the transposed matrix of v, and ||v||2 represents the two-norm of v.
[0076] S12. The server determines other first image samples whose corresponding feature similarities are lower than a similarity threshold as difference samples.
[0077] The server may determine the first image sample whose feature similarity among the M-1 first image samples is lower than the similarity threshold as a difference sample. The difference sample refers to a first image sample that is significantly different from the j-th first image sample. Since the second image sample feature generated based on the first image sample feature needs to be significantly different from the first image sample feature, the difference sample may be used as a basis for generating the second image sample feature. For example, when the feature similarity is cosine similarity, the difference sample may be determined by the following formula: H j,k =1[S j,k <median(S j,: )]
[0078] Among them, H j,k represents the first image sample feature corresponding to the kth first image sample (the kth first image sample is the difference sample of the jth first image sample) among the M first image samples, 1[·] represents the indicator function, S j,k represents the cosine similarity between the jth first image sample and the kth first image sample, S j,: represents the cosine similarity between the jth first image sample and all M-1 first image samples, and median(α) represents the median value of α.
[0079] Through this formula, the similarity threshold can be determined as the middle value of the cosine similarity between the j-th first image sample and the remaining M-1 first image samples, and the image samples whose cosine similarity among the M-1 first image samples is lower than the middle value are determined as difference samples. As shown in Figure 3, the first image sample that has a large difference from the j-th first image sample is determined as the difference sample.
[0080] S13. The server generates a second image sample feature of the jth first image sample according to the first image sample feature of the difference sample and the first image sample feature of the jth first image sample.
[0081] After determining the difference sample, because the second image sample features have different scene parameters than the first image sample features but the same identification label, the second image sample features need to have significant differences from the first image sample features regarding the scene environment, but the similarity between the two regarding the identification label features must be very high. Therefore, the server cannot directly generate the second image sample features based on the first image sample features of the difference sample. Instead, it generates the second image sample features for the jth first image sample based on the first image sample features corresponding to the difference sample and the jth first image sample.
[0082] In addition, in order to further improve the diversity of the second image sample features, after determining the difference samples, a certain number of difference samples can be randomly discarded. For example, as shown in Figure 3, half of the difference samples can be randomly discarded, and then the second image sample features for the jth first image sample can be generated based on the remaining difference samples and the jth first image sample.
[0083] The server first determines a difference sample that is significantly different from the first image sample, and then generates a second image sample feature for the first image sample based on the first image sample features corresponding to the difference sample and the first image sample. In this way, a second image sample feature having different scene parameters from the first image sample feature is obtained, thereby achieving the expansion of the image sample in the scene environment.
[0084] In the process of generating the second image sample feature, it is necessary to ensure that the second image sample corresponding to the second image sample feature and the first image sample have the same identification label. Therefore, in one possible implementation, the server generates the second image sample feature of the jth first image sample based on the first image sample feature of the difference sample and the first image sample feature of the jth first image sample in S13, specifically including:
[0085] S21. The server generates an initial second image sample feature according to the first image sample feature of the difference sample and the first image sample feature of the j-th first image sample.
[0086] The server may first generate an initial second image sample feature for the jth first image sample based on the first image sample features corresponding to the difference sample and the jth first image sample (for example, fusing / merging / splicing the first image sample features of the difference sample and the first image sample features corresponding to the jth first image sample). The initial second image sample feature is an image feature having different feature information from the first image sample feature of the jth first image sample. The initial second image sample feature carries the feature information of the first image sample feature of the difference sample. Since the initial second image sample feature is not equivalent to the second image sample feature, it is essentially an intermediate feature in the process of generating the second image sample feature. Therefore, it is not necessary to ensure that the initial second image sample feature and the first image sample feature represent the same object. For example, the initial second image sample feature for the jth first image sample can be obtained according to the following formula: where S′=Dropout(H*S)
[0087] Wherein, H represents the first image sample feature of the difference sample of the j-th first image sample, S represents the cosine similarity between the same batch of first image samples, α*β represents the element-wise product of α and β, Dropout represents the dropout function, S′ represents the first image sample feature of the remaining difference samples after dropout, ||S′||1 represents the norm of S′, V represents the first image sample feature of the j-th first image sample, and V′ represents the initial second image sample feature of the j-th first image sample.
[0088] In this formula, in order to further improve the diversity of the second image sample features, not all the difference samples are directly used. Instead, the remaining difference samples after random discarding are used. Then, a norm regularization is used on the first image sample features of the remaining difference samples to ensure that the sum of each row is 1, and the initial second image sample features of the jth first image sample are determined in combination with the first image sample features of the jth first image sample.
[0089] S22. The server uses the first image sample feature of the jth first image sample as a fusion constraint, fuses the first image sample feature of the jth first image sample and the initial second image sample feature, and obtains the second image sample feature of the jth first image sample.
[0090] Since the generation of the second image sample feature requires reference to the first image sample feature of the difference sample, and is affected by the first image sample feature of the difference sample, the generated second image sample feature and the first image sample feature of the j-th first image sample may correspond to different identification labels. In the case where the two correspond to different identification labels, the subsequent steps cannot be performed normally, that is, the identification label of the j-th first image sample and the second prediction result determined based on the second image sample feature cannot be used to construct the loss function, and the initial recognition model can be trained accordingly. In order to avoid the above situation, it is necessary to constrain the generated second image sample feature based on the first image sample feature of the j-th first image sample during the generation of the second image sample feature through this step S22, so as to ensure that the generated second image sample feature corresponds to the same identification label as the first image sample feature.
[0091] Specifically, after generating the initial second image sample feature having feature information that is significantly different from the first image sample feature, in order to ensure that the first image sample feature and the second image sample feature represent the same object, the server may use the first image sample feature of the jth first image sample as a fusion constraint in the process of fusing the first image sample feature of the jth first image sample and the initial second image sample feature. This means that the first image sample feature of the jth first image sample and the initial second image sample feature are not fused randomly, but by using the original first image sample feature of the jth first image sample as a constraint to ensure that the obtained second image sample feature and the first image sample feature represent the same object, that is, to ensure that the first image sample feature corresponds to The first image sample and the second image sample corresponding to the second image sample feature have the same identification label. For example, when the recognition model recognizes a living body, the first image sample feature is used as a fusion constraint to ensure that the second image sample corresponding to the obtained second image sample feature and the first image sample represent the same face, thereby avoiding errors when the obtained second image sample feature uses the identification label of the first image sample feature as the corresponding true value in subsequent steps, thereby ensuring that the initial recognition model can be trained and optimized directly according to the second image sample feature and the identification label in subsequent steps, and is conducive to the model better recognizing invariant features from the same object in the subsequent training process. As shown in Figure 3, the feature information of the first image sample feature and the initial second image sample feature can be fused using the Exact Feature Distribution Mixing (EFDMix) technology, thereby ensuring that the feature information of the first image sample feature about the identification label remains unchanged to obtain the corresponding second image sample feature. At the same time, the style transfer algorithm (Adaptive Instance Normalization, AdaIN) can also be used to fuse the first image sample feature and the initial second image sample feature.
[0092] First, an initial second image sample feature is directly generated that has different feature information from the first image sample feature of the jth first image sample. Then, in the process of fusing the first image sample feature and the initial second image sample feature, the original first image sample feature is used as a fusion constraint, so that the obtained second image sample feature and the first image sample feature represent the same object, that is, the second image sample and the first image sample corresponding to the second image sample feature have the same identification label, avoiding errors when the identification label of the first image sample feature is used as the corresponding true value in subsequent steps, thereby ensuring that the initial recognition model can be trained and optimized directly according to the second image sample feature and the identification label in subsequent steps.
[0093] S204: The server inputs the first image sample feature and the second image sample feature into an initial decoder respectively to obtain a first texture image corresponding to the first image sample feature and a second texture image corresponding to the second image sample feature.
[0094] A texture image refers to an image that can reflect the texture of an image. For example, texture images include local binary pattern (LBP) images, color LBP images, LBP in HSV color space or YCbCr color space, and other LBP variant images. Texture is an image feature that can reflect the distribution properties of pixels in an image. It can be expressed by the grayscale distribution of pixels and their surrounding spatial neighborhoods. The texture of an image is usually locally irregular but macroscopically regular. By obtaining the texture image of an image, a richer expression of the image can be made in the texture dimension. In this embodiment, the first texture image refers to the texture image corresponding to the first image sample feature, and the second texture image refers to the texture image corresponding to the second image sample feature.
[0095] In this embodiment, the initial decoder can obtain the first texture image corresponding to the image sample based on the first image sample feature. The first image sample feature refers to a series of information reflected by the image sample in the feature dimension, and the first texture image refers to the visual information in the image reflected by the image sample in the texture dimension. That is, in this embodiment, in addition to analyzing and processing the image sample in the feature dimension, analysis and processing is also performed in the texture dimension. That is, before identifying the object type of the object in the image sample, the initial recognition model analyzes and processes the image sample in both feature and texture dimensions.
[0096] In addition, in this embodiment, the initial decoder can also obtain a corresponding second texture image based on the second image sample feature. The second image sample feature refers to a series of information reflected by the second image sample in the feature dimension, and the second texture image refers to the visual information in the image reflected by the second image sample in the texture dimension. That is, in this embodiment, in addition to obtaining the information of the second image sample in the feature dimension, the information of the second image sample in the texture dimension is further obtained, so that the corresponding information is obtained in both the feature and texture dimensions before the second image sample is identified.
[0097] Specifically, the initial decoder is used to perform feature decoding processing according to the image sample features. The feature decoding processing is the inverse process of the feature encoding processing, which is used to restore the image sample features in the data form into a texture image in the image form.
[0098] S205. The server inputs the first image sample features and the first texture image into an initial classifier to obtain a first prediction result of the object type; and inputs the second image sample features and the second texture image into the initial classifier to obtain a second prediction result of the object type.
[0099] The prediction result of the object type refers to the prediction result of the object type of the object in the image after the image is recognized by the model. The prediction result can be a probability value. For example, when the recognition model is a liveness recognition model, after the face image is recognized and processed by the liveness recognition model, the prediction result of the object type obtained can be that there is a probability of 0.7 that it is live. In this embodiment, the first prediction result refers to the object type recognition result corresponding to the first image sample, and the second prediction result refers to the object type recognition result corresponding to the second image sample.
[0100] During the training process, the recognition models in related technologies usually only determine the prediction results of the corresponding object types based on the image sample features of the image samples. This will result in the trained recognition models having insufficient recognition capabilities for the information in the image, and further make it difficult for the trained recognition models in related technologies to meet the required generalization requirements when facing cross-attack type recognition.
[0101] Since the recognition model may encounter various types of attacks in actual applications, and may even encounter new types of attacks that have not been trained during the training process, in order to learn more accurate recognition capabilities during the training process of the initial recognition model, in this embodiment, the server will determine the first prediction result of the object type through an initial classifier based on information in two dimensions: the first image sample feature and the first texture image. That is, in this embodiment, the initial classifier does not simply obtain the prediction result corresponding to the first image sample based on the first image sample feature, but comprehensively considers the first image sample feature and the first texture image to obtain the corresponding first prediction result, that is, the model comprehensively classifies the image samples from the feature dimension and the texture dimension during the training process, so that the initial recognition model can more accurately and comprehensively refer to the information in the image sample during the training process and perform classification accordingly.
[0102] In addition, in this embodiment, the second prediction result of the object type corresponding to the second image sample is determined by the initial classifier based on the information in two dimensions of the second image sample feature and the second texture image. That is to say, the initial classifier also comprehensively considers the second image sample feature and the second texture image to obtain the second prediction result of the corresponding object type, that is, the model also comprehensively classifies cross-scene image samples from the feature dimension and the texture dimension during the training process, so that the initial recognition model can refer to the information in the second image sample more accurately and comprehensively during the training process, and perform classification accordingly.
[0103] Based on the initial recognition model including the initial encoder, the initial decoder, and the initial classifier, in one possible implementation, the initial recognition model further includes an initial feature embedding module. In S204, the server inputs the first image sample feature and the first texture image into the initial classifier to obtain a first prediction result of the object type, specifically including:
[0104] The server inputs the first image sample feature into the initial feature embedding module to obtain a corresponding first embedded feature;
[0105] The server inputs the first embedded feature and the first texture image into the initial classifier to obtain a first prediction result.
[0106] The initial feature embedding module refers to a feature embedding module that needs to be trained and optimized. The feature embedding module can perform secondary extraction of image features to obtain more accurate embedded features. Embedded features refer to features that can more accurately reflect image content information.
[0107] In order to further improve the quality of the data processed by the input initial classifier, the server can determine the corresponding first embedded feature based on the first image sample feature through the initial feature embedding module, that is, the image sample feature is secondary processed through the initial feature embedding module to obtain an embedded feature that can more accurately reflect the image content information.
[0108] Based on the first embedded feature obtained through the initial feature embedding module, the first embedded feature and the first texture image can be input into the initial classifier so that the initial classifier can perform classification and recognition based on this. In this embodiment, the first embedded feature that is more accurate than the first image sample feature is input into the initial classifier, which is conducive to the initial classifier obtaining a more accurate type recognition result.
[0109] In addition, in this embodiment, through the initial feature embedding module, a corresponding second embedded feature can be obtained according to the second image sample feature, and the second embedded feature and the second texture image can be input into the initial classifier together to determine the second prediction result of the object type.
[0110] Based on the acquired image sample features, the server performs secondary analysis and processing on the image sample features through the initial feature embedding module to obtain embedded features that can more accurately reflect the image content information, thereby improving the data quality input to the initial classifier and helping the initial classifier to obtain more accurate type recognition results.
[0111] S206: The server generates a recognition loss function based on the differences between the first prediction result and the second prediction result and the recognition label.
[0112] The first prediction result refers to a prediction result of the object type of the object in the first image sample obtained after the first image sample is identified by the initial recognition model. The second prediction result refers to a prediction result of the object type obtained after the second image sample feature and the second texture image are identified by the initial classifier in the initial recognition model. The recognition label refers to a label that identifies the true object type of the object in the first image sample. Based on the difference between the prediction result and the recognition label obtained by the initial recognition model, the server can obtain a recognition loss function that can reflect the training optimization direction of the initial recognition model. For example, for the initial recognition model, the recognition loss function can be obtained by the following formula: L CE =-[ylog(y′)+(1-y)log(1-y′)]
[0113] Among them, L CE Refers to the recognition loss function, y refers to the recognition label, and y′ refers to the first prediction result or the second prediction result. The recognition loss function of the initial recognition model can be obtained through the above formula. For example, when the recognition model recognizes a living body, the object in the image sample is a real living body, and the corresponding recognition label value is 1. If the probability value of the first prediction result of the image sample is 0.8, the corresponding recognition loss function can be calculated according to the recognition label and the first prediction result through the above formula.
[0114] It should be noted that since the second image sample feature is generated based on the first image sample feature, the server can apply a certain weight to the loss corresponding to the second prediction result in the process of generating the recognition loss function based on the differences between the first prediction result and the second prediction result and the recognition label. For example, a weight of 0.1 is applied to the loss corresponding to the second prediction result, so that the recognition loss function still uses the actually obtained image samples as the main training samples.
[0115] S207: The server uses the recognition loss function to train the initial recognition model to obtain an updated recognition model.
[0116] After obtaining the recognition loss function in S205, since the recognition loss function can reflect the training optimization direction of the initial recognition model, the server can train the initial recognition model according to the recognition loss function, thereby obtaining an applicable recognition model.
[0117] Because the recognition loss function is derived from a combination of the first and second prediction results, which correspond to the first and second image samples, respectively, the recognition model trained with this loss function can achieve good generalization capabilities for cross-scene recognition. Furthermore, because the prediction results are derived from a combination of feature and texture dimensions, the recognition model trained with this loss function has more accurate and comprehensive recognition capabilities, capable of handling diverse recognition attack methods. In short, this recognition model has good generalization capabilities for cross-scene recognition and various attack types.
[0118] In the process of obtaining a prediction result of the object type by using the initial classifier to identify image sample features and texture images of different dimensions, if the image sample features and texture images can be better interacted at the information level, a more accurate type recognition result can be obtained. In one possible implementation, in S204, the server inputs the first image sample features and the first texture image into the initial classifier to obtain a first prediction result of the object type, specifically including:
[0119] S31. The server maps the first image sample feature to the feature space of the first texture image to obtain the mapped sample feature.
[0120] Since the first image sample feature refers to a series of information reflected by the first image sample in the feature dimension, and the first texture image refers to the visual information in the image reflected by the first image sample in the texture dimension, the two are not in the same feature space. Therefore, in order to be able to interact with the first image sample feature and the first texture image at the information level in the same feature space, the server can map the first image sample feature to the feature space of the first texture image to obtain the mapped sample feature in the feature space of the first texture image. The mapped sample feature and the first image sample feature have the same image information, and both can reflect the content of the image sample in the feature dimension, as shown in Figure 4. In Figure 4, F represents the first image sample feature, and T represents the first texture image. F can be projected into a space with the same channel dimension as T through a 1×1 convolutional neural network h1, that is, F is projected into the feature space of T to obtain the mapped sample feature F′.
[0121] S32. The server determines a sample attention map based on the mapped sample features and the feature distribution of the same image area in the first texture image. The sample attention map is used to identify the attention weight corresponding to the image area in the first image sample in the object type recognition task.
[0122] The mapping sample features and the first texture image located in the same feature space have corresponding feature distributions in the image area of the first image sample. Since the mapping sample features and the first texture image reflect the content of the image area from different dimensions, the feature distributions of the mapping sample features and the first texture image for the same image area are usually not the same. For example, when the feature distribution of the mapping sample features for a certain image area has more feature information, the feature distribution of the first texture image for the image area may have more feature information or less feature information.
[0123] To this end, the server can determine a sample attention map that can comprehensively reflect the feature distribution of the first image sample based on the mapped sample features and the feature distribution of the first texture image for the same image area. The sample attention map is used to identify the attention weight corresponding to the image area in the first image sample in the object type recognition task. More specifically, it is used to identify the attention weight of the image area in the image sample for the identified object type under the guidance of the mapped sample features and the feature distribution of the first texture image. The attention weight is conducive to the initial classifier to subsequently better classify and recognize based on the mapped sample features and the first texture image. For example, when the feature distribution of the mapped sample features for a certain image area has more feature information, and the feature distribution of the first texture image for the image area also has more feature information, the attention weight of the image area reflected in the sample attention map is higher. The higher the attention weight of the image area, the more attention will be allocated to the image area when the initial classifier is used to recognize the object type in the subsequent step, thereby making the corresponding category recognition result more accurate. That is, by allowing the mapped sample features and the first texture image to interact at the information level, an attention map that can guide the recognition of the initial classifier is obtained. As shown in Figure 4, the sample attention map A can be obtained by performing matrix multiplication on the mapped sample features F′ and the first texture image T.
[0124] S33. The server generates an attention sample feature according to the mapped sample feature and the sample attention map, and generates an attention texture image according to the first texture image and the sample attention map.
[0125] After obtaining the sample attention map, the server can generate an attention sample feature corresponding to the mapping sample feature and an attention texture image corresponding to the first texture image through the sample attention map. The attention sample feature supplements the feature information of the first texture image through the sample attention map on the basis of the mapping sample feature. The attention sample feature carries the feature information of the first texture image. The attention texture image supplements the feature information of the mapping sample feature through the sample attention map on the basis of the first texture image. The attention texture image carries the feature information of the mapping sample feature, thereby completing the feature complementarity of the mapping sample feature and the first texture feature. As shown in Figure 4, the attention map A can be applied to the mapping sample feature F′ and the first texture image T respectively, and the attention texture image T can be obtained through another 1×1 convolutional neural network h2. att and attention sample features F att .
[0126] S34. The server inputs the attention sample features and the attention texture image into the initial classifier to determine the first prediction result.
[0127] After obtaining the attention sample features and the attention texture image, the initial classifier can combine the attention sample features and the attention texture image to obtain the corresponding first prediction result. Specifically, the attention texture image T can be combined through a cascade operation. att and attention sample features F att As the input of the initial classifier. Since the attention sample feature carries not only the information of the first image sample feature but also the information of the first texture image, and the attention texture image carries not only the information of the first texture image but also the information of the first image sample feature, the initial classifier can classify the image samples more comprehensively, and the first prediction result is more reliable.
[0128] It should be noted that, in this embodiment, the server may also map the second image sample features into the feature space of the second texture image to obtain cross-scene mapping sample features; and then determine the cross-scene sample attention map based on the cross-scene mapping sample features and the feature distribution of the same image area in the second texture image; and then, generate cross-scene attention sample features based on the cross-scene mapping sample features and the cross-scene sample attention map, and generate a cross-scene attention texture image based on the second texture image and the cross-scene sample attention map; finally, input the cross-scene attention sample features and the cross-scene attention texture image into the initial classifier to determine the second prediction result.
[0129] For image samples, by combining the attention mechanism of feature dimension and texture dimension, the first image sample feature and the first texture image can interact at the information level, and the attention texture image carrying the information of the first image sample feature and the attention sample feature carrying the information of the first texture image are obtained. Using the attention texture image and the attention sample feature as the input of the initial classifier can effectively improve the data quality of the input initial classifier, thereby improving the accuracy of the corresponding category recognition results.
[0130] When fusing information of different dimensions according to the attention mechanism, in order to obtain a sample attention map that can reflect more detailed information from a finer-grained perspective, in one possible implementation, the method further includes:
[0131] S41. The server divides the first image sample into N sub-image areas, where N is an integer greater than 1.
[0132] The server in S31 maps the first image sample feature to the feature space of the first texture image to obtain the mapped sample feature, specifically including:
[0133] S42. The server determines N sub-features corresponding to the N sub-image regions based on the first image sample feature, and maps the N sub-features respectively into the feature space of the first texture image to obtain N sub-mapping features constituting the mapping sample feature;
[0134] For the i-th sub-image area among the N sub-image areas, where i is an integer greater than or equal to 1 and less than or equal to N, the server in S32 determines a sample attention map based on the mapped sample features and the feature distribution of the same image area in the first texture image, specifically including:
[0135] S43, the server obtains the i-th sub-mapping feature corresponding to the i-th sub-image area in the mapping sample feature, and the i-th texture grid corresponding to the i-th sub-image area in the first texture image;
[0136] S44. The server determines the sub-attention map corresponding to the i-th sub-image area in the sample attention map according to the i-th sub-mapping feature and the feature distribution of the i-th texture grid.
[0137] Since the feature information contained in different image areas in the first image sample is not uniform, and the first image sample feature reflects the image feature of the entire image area in the first image sample, and the first texture image reflects the texture image of the entire image area in the first image sample, if the sample attention map corresponding to the entire image area of the first image sample is directly determined based on the first image sample and the first texture image corresponding to the entire image area, the obtained sample attention map may lose some detailed information of the image sample.
[0138] In this regard, the server can first divide the first image sample into multiple sub-image areas, that is, partition the first image sample first. The finer the division of the image area, the more sub-image areas are obtained, and the better the recognition model can pay attention to the detailed information of the image sample in subsequent steps. However, the calculation amount of the model will also increase accordingly. Therefore, the number of sub-image areas can be set by relevant technical personnel as needed. At the same time, in the division process, the image area can be divided evenly or unevenly, which is not limited here. When the image area is evenly divided, the image area can be divided into P×P grids, where the value of P is set as needed. For example, P can be 2, 4, 8, etc. As shown in Figure 5, the value of P can be 3, and the image area is divided into 3×3 grids.
[0139] After the first image sample is divided into multiple sub-image areas, the server can map the first image sample features to the feature space of the first texture image according to the multiple sub-image areas. Specifically, the sub-features corresponding to each of the multiple sub-image areas are first determined in the first image sample features. The sub-features refer to the image features corresponding to the sub-image areas. That is, the first image sample features are first divided according to the sub-image areas to obtain the sub-features corresponding to the sub-image areas, and then the sub-features corresponding to the multiple sub-image areas are respectively mapped to the feature space of the first texture image to obtain the sub-mapping features corresponding to the multiple sub-image areas. The sub-mapping features refer to the mapping image features corresponding to the sub-image areas, which lays the foundation for the subsequent processing of the first texture image and the mapping sample features according to the multiple sub-image areas in the feature space of the first texture image. As shown in FIG5 , the first image sample feature F can be divided according to the 3×3 grids to obtain multiple sub-features, wherein the i-th sub-feature corresponding to the i-th sub-image area can be expressed by F i Then, F can be transformed into i Projected into the space with the same channel dimension as the first texture image T, that is, F i Projected to the feature space of T, the i-th sub-mapping feature F′ corresponding to the i-th sub-image area is obtained i .
[0140] After obtaining the sub-mapping features corresponding to each of the multiple sub-image areas, the server can determine a sample attention map based on the multiple sub-image areas. Taking the i-th sub-image area among the multiple sub-image areas as an example for specific explanation, the i-th sub-mapping feature corresponding to the i-th sub-image area and the i-th texture grid corresponding to the i-th sub-image area in the first texture image can be obtained first, wherein the i-th sub-mapping feature refers to the mapping image feature corresponding to the i-th sub-image area, and the i-th texture grid refers to the texture image corresponding to the i-th sub-image area; then, based on the feature distribution of the i-th sub-mapping feature and the i-th texture grid, determine the i-th sub-attention map that can reflect the feature distribution of the i-th sub-image area from two dimensions, as shown in Figure 5, by performing the i-th sub-mapping feature F′ i and the i-th texture grid T i Perform matrix multiplication to obtain the i-th sub-attention map A i .
[0141] That is, after dividing the sub-image area, the server can determine the corresponding sub-attention map based on the divided sub-image area. The sub-attention map refers to the attention map corresponding to the sub-image area, specifically refers to the attention weight of the sub-image area for identifying the object type under the guidance of the sub-mapping features and the feature distribution of the sub-texture grid corresponding to the sub-image area. That is, in this embodiment, instead of directly obtaining the attention weight of the entire image area of the first image sample, the attention weight of each sub-image area is obtained by partitioning, so that the first image sample features and the first texture image can realize the information-level interaction more finely according to the sub-image area, so that the initial classifier can subsequently notice which sub-image area features in the first image sample are more relevant to object type recognition, that is, it can enable the initial classifier to better pay attention to the detailed information related to object type recognition in the first image sample, thereby improving the recognition accuracy.
[0142] In addition, after obtaining the sub-attention map, the server can first generate the sub-attention sample features corresponding to the sub-mapping features and the sub-attention texture grid corresponding to the sub-texture grid through the sub-attention map. As shown in Figure 5, the i-th sub-attention map A i Element-wise product is applied to the i-th mapping feature F′ i and the i-th texture grid T i And get the i-th sub-attention sample feature through residual connection and the i-th sub-attention texture grid For example, the following formula can be used to obtain and
[0143] in, Represents the i-th sub-attention texture grid, Avg(α) represents the average value of α in a certain dimension, A i represents the sub-attention map, represents the Kronecker product, T i represents the i-th texture grid, represents the i-th sub-attention sample feature, h2 represents a 1×1 convolutional neural network used to project the input to the same i Spaces with the same number of channel dimensions, F′ i represents the i-th sub-mapping feature, F i represents the i-th sub-feature.
[0144] Then, the attention sample features are reassembled according to the sub-attention sample features, and the attention texture image is reassembled according to the sub-attention texture grid, as shown in Figure 5. and sub-attention texture grid Reassemble the corresponding attention sample features F att and attention texture image T att , and merge them through cascade operations to att and F att as the input of the initial classifier.
[0145] It should be noted that, in this embodiment, for the second image sample, the server may also first divide the image area of the first image sample into multiple sub-image areas; then, based on the multiple sub-image areas, map the second image sample features to the feature space of the second texture image to obtain multiple sub-cross-scene mapping features; then, based on the multiple sub-cross-scene mapping features and the texture grids corresponding to the multiple sub-image areas, determine the corresponding sub-cross-scene attention maps for the multiple sub-image areas.
[0146] For image samples, by first dividing the sub-image areas and then determining the attention weights, the first image sample features and the first texture image can interact at the information level more finely according to the sub-image areas. From a more fine-grained perspective, the initial classifier can notice which sub-image area features in the image sample are more relevant to object type recognition, that is, the initial classifier can better pay attention to the detailed information related to object type recognition in the image sample, further improving the recognition accuracy of the model.
[0147] It can be seen that the present application provides a training method for a recognition model for identifying the object type of an object in an image, and the initial recognition model to be trained includes an initial encoder, an initial decoder and an initial classifier. When specifically training the initial recognition model, the first image sample feature of the first image sample is first determined by the initial encoder, and the first image sample has an identification label that identifies the object type to which the object belongs; in order to improve the model's recognition ability for objects in different scene environments, in the present application, a second image sample feature is generated based on the first image sample feature, and the second image sample feature has different scene parameters from the first image sample feature, but corresponds to the same identification label. For these two image sample features, the corresponding texture image can be obtained through the initial decoder, and the corresponding object type prediction result can be determined by the initial classifier based on the image sample feature and the corresponding texture image. Then, the recognition loss function generated based on the identification label and the prediction result is used to train the initial recognition model to obtain an updated recognition model. By performing a cross-scene conversion on the first image sample features, a second image sample feature with different scene parameters and the same identification label as the first image sample feature is obtained. This allows the initial recognition model to learn the ability to recognize the same object in different scene environments during the training process. In addition, by directly performing a cross-scene conversion on the first image sample features, the encoding processing of additional samples is avoided, which will not have a substantial impact on the model training efficiency. When predicting the object type, in addition to image sample features, texture images are further introduced to express image information more richly from the feature dimension and texture dimension, so that the initial recognition model learns more accurate recognition capabilities during the training process and can cope with more diverse recognition attack methods. The recognition model trained in this way has good generalization capabilities for images with different scenes and images generated by different methods when performing object recognition, which effectively improves the model recognition accuracy.
[0148] In this application, the prediction results of the initial recognition model will be measured by the recognition loss function, that is, the difference between the model prediction value (prediction result) and the actual value (recognition label) of the initial recognition model will be evaluated by the recognition loss function, and the initial recognition model will be trained by the recognition loss function to obtain a recognition model with a certain recognition accuracy.
[0149] In this regard, in order to further improve the recognition accuracy of the recognition model, other types of loss functions may be introduced to jointly train the initial recognition model with the recognition loss function. In one possible implementation, the first image sample includes a positive sample and a negative sample, the recognition label of the positive sample indicates that the object in the positive sample belongs to a real object type, and the recognition label of the negative sample indicates that the object in the negative sample belongs to a false object type. Based on the texture image generated in S203, the method further includes:
[0150] The server generates a texture loss function based on the difference between the first texture image corresponding to the positive sample and the texture label of the positive sample; the first texture image corresponding to the positive sample is obtained by inputting the first image sample feature of the positive sample into the initial decoder.
[0151] The server in S206 trains the initial recognition model using the recognition loss function to obtain the recognition model, which specifically includes:
[0152] The server trains the initial recognition model through the recognition loss function and the texture loss function to obtain an updated recognition model.
[0153] The first image samples refer to images that can be used as model training samples. For the initial recognition model, positive samples are image samples in which the objects included in the samples are real objects, while negative samples are image samples in which the objects included in the samples are fake objects. For example, when the recognition model is trained to identify living objects, the objects included in the positive samples are real living objects, while the objects included in the negative samples can be fake faces such as faces captured in video screenshots or photographs. If only positive samples are used to train the initial recognition model, the resulting recognition model will have a high false detection probability and false recognition rate. Therefore, to reduce the false detection probability and false recognition rate of the model, the first image samples will include not only positive samples but also negative samples.
[0154] When training the initial recognition model, both the positive and negative samples will obtain corresponding recognition loss functions through the initial encoder, initial classifier, and initial recognizer in the initial recognition model, thereby obtaining a recognition model with certain recognition capabilities. That is, in S203, both the positive and negative samples will obtain corresponding texture images through the initial decoder. In this embodiment, in order to enable the recognition model to better distinguish between real object types and false object types, the server will only measure the generation accuracy of the first texture image corresponding to the positive sample. In order to prevent the information of the negative sample from interfering with the generation of the texture loss function involving only the positive sample, instance normalization (IN) can be used to process a single image sample instead of using batch normalization (BN) commonly used in convolutional neural networks to process the same batch of image samples. Specifically, the server can generate a texture loss function based on the difference between the first texture image of the positive sample and the texture label of the positive sample, where the texture label refers to the texture image expected to be generated for the positive sample, that is, the texture image that the server expects the initial recognition model to be able to generate and can fully reflect the information of the positive sample in the texture dimension, for example, for the batch image samples of the living body recognition model. Where n is the number of image samples in a batch, h and w are the height and width of the image samples, and the positive samples of the liveness recognition model are samples whose objects are real live objects, and the negative samples are samples whose objects are false non-live objects. The texture loss function of the liveness recognition model can be obtained by the following formula: L AE =||D(E(X live ))-M live ||1
[0155] Among them, L AE represents the texture loss function, X live represents the positive samples in the batch of image samples, E represents the processing corresponding to the initial encoder, D represents the processing corresponding to the initial decoder, D(E(X live )) represents the first texture image corresponding to the positive sample, M live represents the texture label of the positive sample, and ||α||1 represents the norm of α.
[0156] Through this formula, the difference between the first texture image obtained by processing the positive sample through the initial encoder and the initial decoder and the texture label of the positive sample is evaluated, that is, the generation accuracy of the first texture image for the positive sample is measured.
[0157] It should be noted that, although the second image sample corresponding to the positive sample in this application also generates a corresponding second texture image, in order to ensure the training efficiency of the model, the server directly generates the second image sample features through the first image sample features, rather than first performing a cross-scene conversion on the first image sample to obtain the corresponding second image sample, and then determining the corresponding second image sample features through the second image sample. If you want to measure the generation accuracy of the second texture image, you need to first generate the second image sample based on the second image sample features, and then generate the corresponding cross-scene texture label based on the second image sample, so that the generation accuracy of the second texture image can be evaluated based on the cross-scene texture label. This will undoubtedly increase the computational complexity of the model, and in this application, the parameters used by the initial decoder to generate the first texture image and the second texture image are the same. Therefore, on the basis of evaluating the generation accuracy of the first texture image, it is not necessary to evaluate the generation accuracy of the second texture image.
[0158] After obtaining the texture loss function, the server can use the recognition loss function and the texture loss function to train the initial recognition model together. Since the texture loss function is obtained by the difference between the first texture image of the positive sample and the texture label of the positive sample, it only involves positive samples and does not involve negative samples, that is, the texture loss function is asymmetric. Training the initial recognition model with the asymmetric texture loss function can enable the trained recognition model to better distinguish the difference in texture images between positive and negative samples. Since the images to be processed encountered by the recognition model during actual use may have various attack types, or even new attack types that are different from the negative samples in the training process, by allowing the recognition model to better distinguish the difference in texture images between positive and negative samples, when encountering a new attack type different from the negative sample, the recognition model can distinguish that the new attack type is not the object type that the recognition model needs to recognize, thereby improving the generalization ability of the recognition model when facing various attack types.
[0159] The difference between the first texture image of the positive sample and the texture label of the positive sample is used to generate a texture loss function that can measure the generation accuracy of the texture image of the positive sample. The initial recognition model is trained together with the asymmetric texture loss function and the recognition loss function, so that the trained recognition model can better distinguish the differences between the texture images of positive and negative samples, which is conducive to improving the generalization ability of the recognition model in the face of various attack types and effectively improving the recognition accuracy of the recognition model.
[0160] In one possible implementation, the texture label of the positive sample can be obtained as follows:
[0161] Perform image texture conversion on the positive sample to obtain the texture label.
[0162] The texture label refers to the texture image expected to be generated for the positive sample, that is, the texture image that the server expects the initial recognition model to be able to generate and that can fully reflect the information of the positive sample in the texture dimension. In practical applications, the image texture conversion operation can be directly performed on the positive sample itself to obtain the corresponding texture label. The image texture conversion operation is used to perform texture conversion on the image itself to obtain a texture image that can fully reflect the information of the image in the texture dimension. By directly performing image texture conversion on the positive sample, the information loss caused by other operations is minimized, and the reliability of the obtained texture label is guaranteed. For example, the positive sample image can be directly grayscale processed to obtain the corresponding grayscale image, which can be used as a texture label.
[0163] By performing image texture conversion on the positive sample itself, a texture label that can fully reflect the positive sample information in the texture dimension is obtained, so that the texture label can be used as the basis for calculating the texture loss function.
[0164] In order to further improve the recognition accuracy of the recognition model, in addition to the texture loss function, other types of loss functions may be introduced to jointly train the initial recognition model with the recognition loss function. In one possible implementation, the first image sample includes a positive sample and a negative sample, the recognition label of the positive sample indicates that the object in the positive sample belongs to a real object type, and the recognition label of the negative sample indicates that the object in the negative sample belongs to a false object type. The method further includes:
[0165] The server inputs the positive sample and the negative sample into the initial encoder respectively to obtain the first undetermined feature of the positive sample and the second undetermined feature of the negative sample;
[0166] The server generates a distance loss function based on a first difference between the first undetermined feature and the anchor feature, and a second difference between the second undetermined feature and the anchor feature, where the anchor feature is determined based on the positive sample;
[0167] The server in S206 trains the initial recognition model using the recognition loss function to obtain the recognition model, which specifically includes:
[0168] The server trains the initial recognition model using the recognition loss function and the distance loss function to obtain an updated recognition model, wherein the initial recognition model is trained using the distance loss function based on the optimization goal of minimizing the first difference and maximizing the second difference.
[0169] In order to reduce the false detection probability and false recognition rate of the recognition model, the first image sample will include positive samples and negative samples, where the positive sample refers to the first image sample in which the object included in the sample is a real object type, and the negative sample refers to the first image sample in which the object included in the sample is a false object type. Both positive and negative samples will participate in the training of the initial recognition model.
[0170] The pending feature refers to the feature information obtained by the server from the first image sample through the initial encoder. The first pending feature is the pending feature obtained from the positive sample through the initial encoder, and the second pending feature is the pending feature obtained from the negative sample through the initial encoder. Since the objects included in the positive sample are all real object types, the distribution difference of the first pending feature corresponding to the positive sample will be small, that is, the distribution of the first pending feature in the feature space will be more compact, and negative samples are usually collected in various ways. For example, when the recognition model identifies a living body, the negative samples include various attack methods such as video screenshots and photos, that is, the second pending features corresponding to the negative samples are usually difficult to aggregate together. And although the object types of the objects included in the positive samples and the negative samples are different, that is, the first pending feature corresponding to the positive sample and the second pending feature corresponding to the negative sample will have different parts, but since the positive sample and the negative sample may have similar parts in terms of scene environment, for example, when the same acquisition device is used to obtain positive samples and negative samples indoors, the positive samples and negative samples have similar characteristics in at least two aspects: indoors and the parameters of the acquisition device, that is, the boundary of the first pending feature and the second pending feature in the feature space is not clear. At this time, if the feature distribution distance of the positive sample can be further aggregated and the feature distribution distance of the positive sample and the negative sample can be widened, thereby generating a more discriminative and identifiable feature space, it will be beneficial to improve the generalization ability of the recognition model when facing various attack types.
[0171] In this regard, the server can generate an asymmetric distance loss function based on the first difference between the first undetermined feature and the anchor feature, and the second difference between the second undetermined feature and the anchor feature. The anchor feature refers to the feature information obtained from the sample serving as the anchor. Since it is expected in this embodiment to aggregate the feature distribution of the positive sample and to separate the feature distributions of the positive and negative samples, the anchor point is determined from the positive sample in this embodiment. The anchor point can be randomly selected from the positive sample. Accordingly, it can be determined based on the feature information of the positive sample serving as the anchor (such as the feature information extracted from the positive sample by the initial encoder). For example, the corresponding anchor feature can be obtained by performing mean pooling on the feature information of each positive sample serving as the anchor. The first difference refers to the difference between the first undetermined feature corresponding to the positive sample and the anchor feature, specifically the distance between the first undetermined feature and the anchor feature in the feature space. The second difference refers to the difference between the second undetermined feature corresponding to the negative sample and the anchor feature, specifically the distance between the second undetermined feature and the anchor feature in the feature space. In this embodiment, a suitable distance metric such as Euclidean distance and cosine distance can be used to measure the above differences. The server can generate a distance loss function for comprehensively evaluating the first difference and the second difference based on the first difference and the second difference. For example, when the undetermined feature f is a feature vector output by the initial encoder after global average pooling, the distance loss function can be determined by the following formula: w p =Softmax(d(f a ,f p )) w n =Softmax(-d(f a ,f n ))
[0172] Among them, L WT represents the distance loss function, δ represents the softplus function, f a ,f p ,f n They represent the anchor feature, the first undetermined feature and the second undetermined feature respectively, d(·,·) is a distance metric, d(f a ,f p ) represents the first difference, d(f a ,f n ) represents the second difference, w p ,w n denote the weighting parameters of the first difference and the second difference, respectively, and Softmax denotes a normalization function.
[0173] Using the above formula, the distance between the anchor feature and the first undetermined feature in feature space is taken as the first difference, and the distance between the anchor feature and the second undetermined feature in feature space is taken as the second difference. Since the weighting parameter is used to normalize the first difference or the second difference, adding the corresponding weighting parameter before the first difference and the second difference can dynamically assign more importance to difficult samples. The distance loss function can be obtained by subtracting the weighted first difference corresponding to all positive samples and the weighted second difference corresponding to all negative samples and processing them through the softplus function. When the value of the distance loss function output by the softplus function is close to zero, the difference generated by the weighted first difference corresponding to all positive samples and the weighted second difference corresponding to all negative samples will be a large negative number, that is, the weighted first difference will be close to zero and the weighted second difference will be a large positive number, which indicates that the difference between the first undetermined feature and the anchor feature is small and the difference between the second undetermined feature and the anchor feature is large, that is, the distance between the positive sample and the anchor is small and the distance between the negative sample and the anchor is large.
[0174] After obtaining the distance loss function, the server can jointly train the initial recognition model through the recognition loss function and the distance loss function, and in the training process, it will be based on the optimization goal of minimizing the first difference and maximizing the second difference, that is, by reducing the first difference between the first pending feature and the anchor feature, and expanding the second difference between the second pending feature and the anchor feature, to gather the feature distribution distance of the positive sample and widen the feature distribution distance between the positive sample and the negative sample.
[0175] It should be noted that, in this embodiment, there is no requirement to cluster the feature distribution distances of negative samples. This is because the attack types in negative samples are not exactly the same, and it is difficult to cluster the feature distributions of negative samples with different feature distributions. Moreover, for negative samples including various types of false objects, determining a common feature distribution area will also affect the recognition accuracy of the trained recognition model when facing various attack types in actual use. Therefore, the feature distribution distances of positive samples are clustered, and the feature distribution distances of positive and negative samples are widened, so that the feature distributions of positive samples and negative samples generate clearer boundaries in the feature space, which can effectively improve the recognition accuracy of the recognition model.
[0176] An asymmetric distance loss function can be generated by the first difference between the first undetermined feature of the positive sample and the anchor feature determined based on the positive sample, as well as the second difference between the second undetermined feature of the negative sample and the anchor feature. Then, the initial recognition model is trained together with the distance loss function and the recognition loss function. During the training process, the distance loss function is used to minimize the first difference and maximize the second difference to gather the feature distribution distance of the positive sample and widen the feature distribution distance between the positive sample and the negative sample, thereby obtaining a feature space with more discriminative and identifying properties, which is conducive to improving the generalization ability of the recognition model in the face of various attack types and effectively improving the recognition accuracy of the recognition model.
[0177] In one possible implementation, the initial encoder includes multiple network layers in addition to the input layer. The first to-be-determined feature and the second to-be-determined feature are output features of the target network layer in the initial encoder. When the target network layer is the output layer of the initial encoder, the first to-be-determined feature is the first image sample feature of the positive sample, and the second to-be-determined feature is the first image sample feature of the negative sample.
[0178] In this embodiment, in addition to the input layer, the initial encoder may include multiple network layers. Based on the positive samples or negative samples input through the input layer, any one of the multiple network layers can determine the corresponding output features for the positive samples and the negative samples respectively. Since the scales of the output features of different layers in the multiple network layers are not the same, according to the needs of model training, the output features of any one of the network layers (i.e., the above-mentioned target network layer) for the positive samples and the negative samples can be used as the first to-be-determined features and the second to-be-determined features to generate the distance loss function corresponding to the layer. Specifically, when the output layer in the multiple network layers generates the first image sample features corresponding to the positive samples and the negative samples respectively, the first image sample features generated by the output layer for the positive samples and the negative samples can also be directly used as the first to-be-determined features and the second to-be-determined features to generate the distance loss function corresponding to the output layer. In order to better train and optimize the initial encoder, the distance loss function can be determined according to the output features of each layer in the multiple network layers, so that the output features of different scales output by each layer in the initial encoder are trained and optimized.
[0179] For any of the multiple network layers of the initial encoder, the corresponding distance loss function can be determined, so that the network layer to be trained and optimized can be accurately optimized according to the needs of model training. Even each layer in the initial encoder can be trained and optimized to better improve the performance of the trained recognition model.
[0180] In order to further improve the recognition accuracy of the recognition model, in addition to the texture loss function and the distance loss function, other types of loss functions may be introduced to jointly train the initial recognition model with the recognition loss function. In one possible implementation, the first image sample includes a positive sample and a negative sample, the recognition label of the positive sample indicates that the object in the positive sample belongs to a real object type, and the recognition label of the negative sample indicates that the object in the negative sample belongs to a false object type. The method further includes:
[0181] The server generates a calibration loss function based on the feature similarity between the first image sample feature of the positive sample and the second image sample feature corresponding to the positive sample; the second image sample feature corresponding to the positive sample is a second image sample feature generated based on the first image sample feature of the positive sample.
[0182] The server in S206 uses the recognition loss function to train the initial recognition model to obtain an updated recognition model, specifically including:
[0183] The server trains the initial recognition model using the recognition loss function and the calibration loss function to obtain an updated recognition model, wherein the initial recognition model is trained by the calibration loss function based on the optimization target of the first image sample feature of the fixed positive sample.
[0184] In order to reduce the false detection probability and false recognition rate of the recognition model, the first image sample will include positive samples and negative samples, where the positive sample refers to the image sample in which the object included in the sample is a real object type, and the negative sample refers to the image sample in which the object included in the sample is a false object type. Both positive and negative samples will participate in the training of the initial recognition model.
[0185] In S202, the server generates a second image sample feature corresponding to a different scene parameter based on the first image sample feature. By using both the first image sample feature and the second image sample feature for training the initial recognition model, the initial recognition model can learn the ability to recognize the same object in different scene environments during the training process. Since various object type recognition environments are encountered in the actual application of the recognition model, if the initial recognition model can learn the invariant features related to the recognition of the real object type in the positive sample during the training process, then in the actual application process, for an image to be processed that includes a real object type, no matter how the scene environment included in the image to be processed changes, the recognition model can recognize that the object included in the image to be processed is a real object type based on the invariant features, which is conducive to improving the generalization ability of the recognition model when facing various recognition environments.
[0186] To this end, the server can use the first image sample feature of the positive sample as a scale to reduce the difference between the second image sample feature corresponding to the second image sample and the first image sample feature, so as to facilitate the initial recognition model to learn the invariant feature from the first image sample feature and the second image sample feature with smaller differences. Specifically, the server can generate a calibration loss function based on the feature similarity between the first image sample feature and the second image sample feature. The feature similarity is used to represent the degree of similarity between different image samples in the dimension of image features. The feature similarity can be represented by the distance of image features in the feature space. For example, suitable distance metrics such as Euclidean distance and cosine distance can be used to represent feature similarity. The generated calibration loss function can reduce the difference between the second image sample feature and the first image sample feature in the process of training the initial recognition model. For example, when the recognition model recognizes a living body, for the first image sample feature f corresponding to the positive sample live The corresponding second image sample features The calibration loss function can be determined by the following formula:
[0187] Among them, L Cal represents the calibration loss function, f live Represents the first image sample feature of the positive sample, represents the second image sample feature of the cross-scene image sample corresponding to the positive sample, <·> represents the gradient stop operation, and d(·,·) is a distance metric.
[0188] Through the above formula, the gradient stop operation can be performed on the first image sample feature to fix the first image sample feature unchanged, that is, the first image sample feature is used as a scale. When the value of the calibration loss function is close to zero, it means that the second image sample feature and the fixed first image sample feature are highly similar.
[0189] After obtaining the calibration loss function, the server can jointly train the initial recognition model through the recognition loss function and the calibration loss function, and fix the first image sample features during the training process. The calibration loss function is used to reduce the difference between the second image sample features corresponding to the positive sample and the first image sample features of the positive sample, so that the second image sample features generated based on the first image sample features can retain the invariant features related to the identification of the real object type in the first image sample features as much as possible, further improving the accuracy of cross-scene sample amplification, so that the initial recognition model can learn the invariant features during the training process.
[0190] It should be noted that in this embodiment, a calibration loss function is not generated for negative samples. This is because the attack types of negative samples are diverse, and the invariant features related to identifying false object types corresponding to different attack types are not the same. It is difficult for the initial recognition model to learn the invariant features related to identifying false object types during the training process. Moreover, in the face of various attack types encountered by the model in actual applications, if the initial recognition model can better learn the invariant features related to identifying real object types during the training process, the obtained recognition model can accurately identify real object types during actual use.
[0191] Through the feature similarity between the first image sample feature of the positive sample and the corresponding second image sample feature, a calibration loss function can be generated, and the initial recognition model is trained together with the calibration loss function and the recognition loss function. During the training process, the first image sample feature is used as a scale to reduce the difference between the second image sample feature and the first image sample feature, so that the second image sample feature generated based on the first image sample feature can retain the invariant features related to the recognition of the real object type in the first image sample feature as much as possible, that is, the accuracy of cross-scene sample amplification is improved, so that the initial recognition model can learn the invariant features during the training process, which is conducive to improving the generalization ability of the recognition model in the face of various recognition environments, and effectively improving the recognition accuracy of the recognition model.
[0192] In order to further improve the recognition accuracy of the recognition model, in a possible implementation method, the recognition loss function, texture loss function, distance loss function and calibration loss function can be used to jointly train the initial recognition model. As shown in Figure 6, during the training process, first, the first image sample features corresponding to the positive sample and the negative sample are obtained through the initial encoder E, wherein the distance loss function can be applied to each layer of the initial encoder E; secondly, the second image sample features can be generated based on the first image sample features, thereby realizing the cross-scene conversion of the first image sample; after obtaining the second image sample features, on the one hand, the initial decoder D can be used to generate the corresponding first texture image and second texture image according to the first image sample features and the second image sample features, wherein based on the positive sample The first texture image of this method can generate a texture loss function for model training. On the other hand, the first embedding feature and the second embedding feature can be generated according to the first image sample feature and the second image sample feature through the initial feature embedding module B; then, the texture image and the embedded feature are complemented by the attention mechanism, wherein the image area of the image sample can be divided to enhance the details; then, the calibration loss function can be used to reduce the difference between the first embedded feature and the second embedded feature of the cross-scene image sample corresponding to the positive sample with the first embedded feature of the positive sample as the scale; finally, the initial classifier is used to obtain the corresponding category recognition result based on the embedded feature and the texture image, and the recognition loss function for model training is obtained according to the category recognition result and the recognition label.
[0193] During the training process, the server can combine the recognition loss function, texture loss function, distance loss function and calibration loss function to obtain the total loss function for model training. For example, the total loss function can be obtained by the following formula: L = L CE +λ AE L AE +λ WT L WT +λ Cal L Cal
[0194] Among them, L CE Represents the recognition loss function, L AE represents the texture loss function, L WT Represents the distance loss function, L Cal represents the calibration loss function, λ AE ,λ WT ,λ Cal are the weights corresponding to the texture loss function, distance loss function and calibration loss function respectively.
[0195] Through the above formula, the total loss function can be obtained by the recognition loss function, texture loss function, distance loss function and calibration loss function, and the initial recognition model can be trained by the total loss function to obtain a recognition model that has good generalization capabilities for cross-scene recognition and recognition of various attack types.
[0196] As shown in FIG7 , the framework of a recognition model with a certain generalization capability generates a corresponding texture image for the input image instead of directly performing recognition detection on the image. Reconstructing the texture image of the image can help the model recognize objects in the image in both the feature dimension and the texture image dimension. The resulting recognition model has high generalization capability for cross-scene recognition and new attack types. To verify the generalization capability of the recognition model, the server can test the recognition model using new recognition scenarios and new attack types that are different from those used during training. Specifically, when the initial recognition model is trained using samples from the MSU database, the resulting recognition model can be tested using samples from the OULU database, where the image samples in the MSU database and the image samples in the OULU database have different recognition scenarios. When the initial recognition model is trained using the curved photo attack, the resulting recognition model can be tested using the video replay attack. The recognition model obtained in this embodiment achieves good results in both the new recognition scenario and the new attack type test, indicating that the recognition model obtained in this embodiment has good generalization capability across scenarios and new attack types.
[0197] Based on the embodiments corresponding to the aforementioned Figures 1-7, Figure 8 is a schematic diagram of a model determination device provided in an embodiment of the present application. The model determination device 800 includes a sample acquisition unit 801, a first determination unit 802, a first generation unit 803, a texture acquisition unit 804, a second determination unit 805, a second generation unit 806, and a training unit 807:
[0198] The sample acquisition unit 801 is configured to obtain a first image sample, where the first image sample has an identification tag that identifies an object type to which an object in the first image sample belongs;
[0199] A first determining unit 802 is configured to input the first image sample into an initial encoder of an initial recognition model to obtain a first image sample feature of the first image sample, wherein the initial recognition model further includes an initial decoder and an initial classifier;
[0200] A first generating unit 803 is configured to generate a second image sample feature based on the first image sample feature, where the second image sample feature and the first image sample feature have different scene parameter values and correspond to the same identification label;
[0201] a texture acquisition unit 804, configured to input the first image sample feature and the second image sample feature into the initial decoder, respectively, to obtain a first texture image corresponding to the first image sample feature and a second texture image corresponding to the second image sample feature;
[0202] A second determining unit 805 is configured to input the first image sample feature and the first texture image into the initial classifier to obtain a first prediction result of the object type; and input the second image sample feature and the second texture image into the initial classifier to obtain a second prediction result of the object type;
[0203] A second generating unit 806 is configured to generate a recognition loss function based on the difference between the first prediction result and the second prediction result and the recognition label;
[0204] The training unit 807 is configured to train the initial recognition model using the recognition loss function to obtain an updated recognition model.
[0205] In one possible implementation, when the first image sample includes a positive sample, and the identification label of the positive sample identifies the object in the positive sample as a real object type, the second generation unit 806 is further configured to generate a texture loss function based on a difference between a first texture image of the positive sample and the texture label of the positive sample; the first texture image corresponding to the positive sample is obtained by inputting the first image sample feature of the positive sample into the initial decoder;
[0206] The training unit 806 is specifically configured to train the initial recognition model using the recognition loss function and the texture loss function to obtain an updated recognition model.
[0207] In a possible implementation, the texture acquisition unit 804 is further configured to perform image texture conversion on the positive sample to obtain a texture label.
[0208] In a possible implementation, the second determining unit 805 is specifically configured to:
[0209] Mapping the first image sample feature into the feature space of the first texture image to obtain a mapped sample feature;
[0210] determining a sample attention map based on the mapped sample features and a feature distribution of the same image region in the first texture image, wherein the sample attention map is used to identify an attention weight corresponding to the image region in the first image sample in an object type recognition task;
[0211] generating an attention sample feature based on the mapped sample feature and the sample attention map, and generating an attention texture image based on the first texture image and the sample attention map;
[0212] The attention sample features and the attention texture image are input into the initial classifier to determine the first prediction result.
[0213] In a possible implementation, the model determination device 800 further includes a division unit, configured to divide the first image sample into N sub-image regions, where N is an integer greater than 1;
[0214] The second determining unit 805 is specifically configured to:
[0215] Determining N sub-features corresponding to N sub-image regions based on the first image sample feature, and mapping the N sub-features respectively into the feature space of the first texture image to obtain N sub-mapping features constituting the mapping sample feature;
[0216] For an i-th sub-image region among the N sub-image regions, where i is an integer greater than or equal to 1 and less than or equal to N, obtain an i-th sub-mapping feature corresponding to the i-th sub-image region in the mapping sample feature and an i-th texture grid corresponding to the i-th sub-image region in the first texture image;
[0217] According to the feature distribution of the i-th sub-map and the i-th texture grid, the sub-attention map corresponding to the i-th sub-image area in the sample attention map is determined.
[0218] In a possible implementation, when the first image sample includes a positive sample and a negative sample, the identification label of the positive sample identifies that the object in the positive sample belongs to a real object type, and the identification label of the negative sample identifies that the object in the negative sample belongs to a false object type, the second generating unit 806 is further configured to:
[0219] Inputting the positive sample and the negative sample distribution into the initial encoder to obtain a first undetermined feature of the positive sample and a second undetermined feature of the negative sample;
[0220] generating a distance loss function based on a first difference between the first undetermined feature and the anchor feature, and a second difference between the second undetermined feature and the anchor feature, wherein the anchor feature is determined based on the positive sample;
[0221] The training unit 807 is specifically used to train the initial recognition model using the recognition loss function and the distance loss function to obtain an updated recognition model; wherein, based on the optimization goal of minimizing the first difference and maximizing the second difference, the distance loss function is used to train the initial recognition model.
[0222] In one possible implementation, the initial encoder includes multiple network layers in addition to the input layer. The first to-be-determined feature and the second to-be-determined feature are output features of the target network layer in the initial encoder. When the target network layer is the output layer of the initial encoder, the first to-be-determined feature is the first image sample feature of the positive sample, and the second to-be-determined feature is the first image sample feature of the negative sample.
[0223] In a possible implementation, the first generating unit 803 is specifically configured to:
[0224] In M first image samples of a round of training of the initial recognition model, where M is an integer greater than 1, for the j-th image sample, where j is an integer greater than or equal to 1 and less than or equal to M, the first generating unit 803 is specifically configured to:
[0225] For each other first image sample except the j-th first image sample among the M first image samples, determine a feature similarity between the j-th first image sample and the other first image sample in terms of first image sample features;
[0226] Determine other first image samples whose corresponding feature similarities are lower than a similarity threshold as difference samples;
[0227] The second image sample feature of the j-th first image sample is generated according to the first image sample feature of the difference sample and the first image sample feature of the j-th first image sample.
[0228] In a possible implementation, the first generating unit 803 is specifically configured to:
[0229] Generate an initial second image sample feature according to the first image sample feature of the difference sample and the first image sample feature of the j-th first image sample;
[0230] The first image sample feature of the jth first image sample is used as a fusion constraint, and the first image sample feature of the jth first image sample and the initial second image sample feature are fused to obtain the second image sample feature of the jth first image sample.
[0231] In a possible implementation, when the first image sample includes a positive sample and a negative sample, the identification label of the positive sample indicates that the object in the positive sample belongs to a real object type, and the identification label of the negative sample indicates that the object in the negative sample belongs to a false object type, the second generating unit 806 is further configured to:
[0232] generating a calibration loss function based on feature similarity between a first image sample feature of a positive sample and a second image sample feature corresponding to the positive sample; wherein the second image sample feature corresponding to the positive sample is a second image sample feature generated based on the first image sample feature of the positive sample;
[0233] The training unit 807 is specifically used to train the initial recognition model using the recognition loss function and the calibration loss function to obtain an updated recognition model; wherein, based on the optimization target of fixing the first image sample feature of the positive sample, the calibration loss function is used to train the initial recognition model.
[0234] In a possible implementation, when the initial recognition model further includes an initial feature embedding module, the second determining unit 805 is specifically configured to:
[0235] Inputting the first image sample feature into the initial feature embedding module to obtain a corresponding first embedded feature;
[0236] The first embedded feature and the first texture image are input into the initial classifier to obtain the first prediction result.
[0237] The embodiment of the present application further provides a computer device, which is the computer device described above and may include a terminal device or a server, and the model determination device may be configured in the computer device. The computer device is described below with reference to the accompanying drawings.
[0238] If the computer device is a terminal device, as shown in FIG9 , an embodiment of the present application provides a terminal device, taking a mobile phone as an example:
[0239] FIG9 is a block diagram showing a partial structure of a mobile phone related to a terminal device provided in an embodiment of the present application. Referring to FIG9 , the mobile phone includes components such as a radio frequency (RF) circuit 1410, a memory 1420, an input unit 1430, a display unit 1440, a sensor 1450, an audio circuit 1460, a wireless fidelity (WiFi) module 1470, a processor 1480, and a power supply 1490. Those skilled in the art will appreciate that the mobile phone structure shown in FIG9 does not limit the mobile phone and may include more or fewer components than shown, or combine certain components, or arrange the components differently.
[0240] The following is a detailed introduction to the various components of the mobile phone in conjunction with Figure 9:
[0241] The RF circuit 1410 may be used for receiving and sending signals during information transmission or calls. In particular, after receiving downlink information from the base station, it is sent to the processor 1480 for processing. In addition, the designed uplink data is sent to the base station.
[0242] Memory 1420 can be used to store software programs and modules. Processor 1480 executes the various functional applications and data processing functions of the mobile phone by running the software programs and modules stored in memory 1420. Memory 1420 may primarily include a program storage area and a data storage area. The program storage area may store an operating system and at least one application required for a function (such as sound playback or image playback); the data storage area may store data generated based on the use of the mobile phone (such as audio data and a phone book). Memory 1420 may also include high-speed random access memory and non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state memory device.
[0243] The input unit 1430 may be configured to receive input digital or character information and generate key signal input related to user settings and function control of the mobile phone. Specifically, the input unit 1430 may include a touch panel 1431 and other input devices 1432 .
[0244] The display unit 1440 may be configured to display information input by the user or information provided to the user, as well as various menus of the mobile phone. The display unit 1440 may include a display panel 1441 .
[0245] The mobile phone may also include at least one sensor 1450, such as a light sensor, a motion sensor, and other sensors.
[0246] The audio circuit 1460 , the speaker 1461 , and the microphone 1462 can provide an audio interface between the user and the mobile phone.
[0247] WiFi is a short-range wireless transmission technology. The mobile phone can help users send and receive emails, browse web pages, and access streaming media through the WiFi module 1470, providing users with wireless broadband Internet access.
[0248] The processor 1480 is the control center of the mobile phone. It uses various interfaces and lines to connect various parts of the entire mobile phone. It executes various functions of the mobile phone and processes data by running or executing software programs and / or modules stored in the memory 1420 and calling data stored in the memory 1420.
[0249] The mobile phone also includes a power supply 1490 (such as a battery) for supplying power to various components.
[0250] In this embodiment, the processor 1480 included in the terminal device is also used to execute the model determination method provided in the above-mentioned embodiment of the present application.
[0251] If the computer device is a server, an embodiment of the present application also provides a server, as shown in Figure 10, which is a structural diagram of a server 1500 provided in an embodiment of the present application. The server 1500 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPUs) 1522 (for example, one or more processors) and a memory 1532, and one or more storage media 1530 (for example, one or more mass storage devices) storing application programs 1542 or data 1544. Among them, the memory 1532 and the storage medium 1530 can be temporary storage or permanent storage. The program stored in the storage medium 1530 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the server. Furthermore, the central processing unit 1522 can be configured to communicate with the storage medium 1530 to execute a series of instruction operations in the storage medium 1530 on the server 1500.
[0252] The server 1500 may also include one or more power supplies 1526, one or more wired or wireless network interfaces 1550, one or more input and output interfaces 1558, and / or one or more operating systems 1541, such as Windows Server 2003. TM , Mac OS X TM , Unix TM ,Linux TM , FreeBSD TM etc.
[0253] The steps executed by the server in the above embodiment may be based on the server structure shown in FIG10 .
[0254] In addition, an embodiment of the present application further provides a storage medium, which is used to store a computer program, and the computer program is used to execute the method provided by the above embodiment.
[0255] An embodiment of the present application further provides a computer program product including a computer program, which, when executed on a computer device, enables the computer device to execute the method provided in the above embodiment.
[0256] Those skilled in the art will understand that all or part of the steps of implementing the above-mentioned method embodiment can be completed by hardware related to program instructions, and the above-mentioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above-mentioned method embodiment; and the above-mentioned storage medium can be at least one of the following media: read-only memory (English: Read-only Memory, abbreviated: ROM), RAM, magnetic disk or optical disk, etc., various media that can store computer programs.
[0257] It should be noted that the various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device and system embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments. The device and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of this embodiment. A person of ordinary skill in the art can understand and implement it without expending creative work.
[0258] The above is only one specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the scope of protection of the present application. Moreover, based on the implementation methods provided in the above aspects, the present application can also be further combined to provide more implementation methods. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.
Claims
1. A model determination method, executed by a computer device, comprising: Obtaining a first image sample, the first image sample having an identification tag identifying an object type to which an object in the first image sample belongs; Inputting the first image sample into an initial encoder of an initial recognition model to obtain a first image sample feature of the first image sample, wherein the initial recognition model further includes an initial decoder and an initial classifier; generating a second image sample feature based on the first image sample feature, wherein the second image sample feature and the first image sample feature have different scene parameter values and correspond to the same identification label; Inputting the first image sample feature and the second image sample feature into the initial decoder respectively to obtain a first texture image corresponding to the first image sample feature and a second texture image corresponding to the second image sample feature; Inputting the first image sample feature and the first texture image into the initial classifier to obtain a first prediction result of the object type; and inputting the second image sample feature and the second texture image into the initial classifier to obtain a second prediction result of the object type; generating a recognition loss function based on the difference between the first prediction result and the second prediction result and the recognition label; The initial recognition model is trained using the recognition loss function to obtain an updated recognition model.
2. The method according to claim 1, wherein the first image sample comprises a positive sample, and the identification label of the positive sample identifies that the object in the positive sample belongs to a real object type; the method further comprises: Generate a texture loss function based on the difference between the first texture image corresponding to the positive sample and the texture label of the positive sample; The first texture image corresponding to the positive sample is obtained by inputting the first image sample feature of the positive sample into the initial decoder; The using the recognition loss function to train the initial recognition model to obtain an updated recognition model includes: The initial recognition model is trained using the recognition loss function and the texture loss function to obtain the updated recognition model.
3. The method according to claim 2, further comprising: Performing image texture conversion on the positive sample to obtain the texture label.
4. The method according to any one of claims 1 to 3, wherein inputting the first image sample feature and the first texture image into the initial classifier to obtain a first prediction result of the object type comprises: Mapping the first image sample features into the feature space of the first texture image to obtain mapped sample features; Determining a sample attention map based on the mapped sample features and the feature distribution of the same image area in the first texture image, wherein the sample attention map is used to identify the attention weight corresponding to the image area in the first image sample in the object type recognition task; generating an attention sample feature according to the mapped sample feature and the sample attention map, and generating an attention texture image according to the first texture image and the sample attention map; The attention sample features and the attention texture image are input into the initial classifier to determine the first prediction result.
5. The method according to claim 4, further comprising: Dividing the first image sample into N sub-image areas, where N is an integer greater than 1; Mapping the first image sample feature to the feature space of the first texture image to obtain the mapped sample feature includes: Determine N sub-features corresponding to the N sub-image regions according to the first image sample feature, and map the N sub-features respectively to the feature space of the first texture image to obtain N sub-mapping features constituting the mapping sample feature; For an i-th sub-image area among the N sub-image areas, where i is an integer greater than or equal to 1 and less than or equal to N, determining a sample attention map based on the mapped sample features and a feature distribution of the same image area in the first texture image includes: Acquire an i-th sub-mapping feature corresponding to the i-th sub-image area in the mapping sample feature, and an i-th texture grid corresponding to the i-th sub-image area in the first texture image; A sub-attention map corresponding to the i-th sub-image area in the sample attention map is determined according to the i-th sub-mapping feature and the feature distribution of the i-th texture grid.
6. The method according to any one of claims 1 to 5, wherein the first image sample comprises a positive sample and a negative sample, the identification label of the positive sample indicates that the object in the positive sample belongs to a real object type, and the identification label of the negative sample indicates that the object in the negative sample belongs to a false object type; the method further comprises: Inputting the positive sample and the negative sample into the initial encoder respectively to obtain a first undetermined feature of the positive sample and a second undetermined feature of the negative sample; generating a distance loss function based on a first difference between the first undetermined feature and an anchor feature, and a second difference between the second undetermined feature and the anchor feature, wherein the anchor feature is determined based on the positive sample; The using the recognition loss function to train the initial recognition model to obtain an updated recognition model includes: The initial recognition model is trained using the recognition loss function and the distance loss function to obtain the updated recognition model; wherein the initial recognition model is trained using the distance loss function based on the optimization goal of minimizing the first difference and maximizing the second difference.
7. According to the method of claim 6, the initial encoder includes multiple network layers in addition to the input layer, the first to be determined feature and the second to be determined feature are output features of the target network layer in the initial encoder, and when the target network layer is the output layer of the initial encoder, the first to be determined feature is the first image sample feature of the positive sample, and the second to be determined feature is the first image sample feature of the negative sample.
8. The method according to any one of claims 1 to 7, wherein, in M first image samples of a round of training of the initial recognition model, M is an integer greater than 1, and for the j-th image sample, j is an integer greater than or equal to 1 and less than or equal to M, generating the second image sample feature based on the first image sample feature comprises: For each other first image sample except the j-th first image sample among the M first image samples, determining a feature similarity between the j-th first image sample and the other first image samples in terms of first image sample features; Determine other first image samples whose corresponding feature similarities are lower than a similarity threshold as difference samples; A second image sample feature of the j-th first image sample is generated according to the first image sample feature of the difference sample and the first image sample feature of the j-th first image sample.
9. The method according to claim 8, wherein generating the second image sample feature of the j-th first image sample according to the first image sample feature of the difference sample and the first image sample feature of the j-th first image sample comprises: generating an initial second image sample feature according to the first image sample feature of the difference sample and the first image sample feature of the j-th first image sample; The first image sample feature of the jth first image sample is used as a fusion constraint, and the first image sample feature of the jth first image sample and the initial second image sample feature are fused to obtain the second image sample feature of the jth first image sample.
10. The method according to any one of claims 1 to 9, wherein the first image sample comprises a positive sample and a negative sample, the identification label of the positive sample indicates that the object in the positive sample belongs to a real object type, and the identification label of the negative sample indicates that the object in the negative sample belongs to a false object type; the method further comprises: generating a calibration loss function based on the feature similarity between the first image sample feature of the positive sample and the second image sample feature corresponding to the positive sample; the second image sample feature corresponding to the positive sample is a second image sample feature generated based on the first image sample feature of the positive sample; The using the recognition loss function to train the initial recognition model to obtain an updated recognition model includes: The initial recognition model is trained using the recognition loss function and the calibration loss function to obtain the updated recognition model; wherein, based on the optimization target of fixing the first image sample feature of the positive sample, the initial recognition model is trained using the calibration loss function.
11. The method according to any one of claims 1 to 10, wherein the initial recognition model further comprises an initial feature embedding module, wherein the inputting the first image sample feature and the first texture image into the initial classifier to obtain a first prediction result of the object type comprises: Inputting the first image sample feature into the initial feature embedding module to obtain a corresponding first embedding feature; The first embedded feature and the first texture image are input into the initial classifier to obtain the first prediction result.
12. A model determination device, comprising a sample acquisition unit, a first determination unit, a first generation unit, a texture acquisition unit, a second determination unit, a second generation unit, and a training unit: The sample acquisition unit is used to obtain a first image sample, wherein the first image sample has an identification tag that identifies an object type to which an object in the first image sample belongs; The first determining unit is used to input the first image sample into an initial encoder of an initial recognition model to obtain a first image sample feature of the first image sample, the initial recognition model further comprising an initial decoder and an initial classifier; The first generating unit is used to generate a second image sample feature based on the first image sample feature, wherein the second image sample feature and the first image sample feature have different scene parameter values and correspond to the same identification label; The texture acquisition unit is used to input the first image sample feature and the second image sample feature into the initial decoder to obtain a first texture image corresponding to the first image sample feature and a second texture image corresponding to the second image sample feature; The second determination unit is configured to input the first image sample feature and the first texture image into the initial classifier to obtain a first prediction result of the object type, and input the second image sample feature and the second texture image into the initial classifier to obtain a second prediction result of the object type; The second generating unit is used to generate a recognition loss function based on the difference between the first prediction result and the second prediction result and the recognition label; The training unit is used to train the initial recognition model using the recognition loss function to obtain an updated recognition model.
13. A computer device, comprising a processor and a memory: The memory is used to store a computer program and transmit the computer program to the processor; The processor is configured to execute the method according to any one of claims 1 to 11 according to the computer program.
14. A computer-readable storage medium, wherein the computer-readable storage medium is used to store a computer program, wherein the computer program is used to execute the method according to any one of claims 1 to 11.
15. A computer program product comprising a computer program, which, when executed on a computer device, causes the computer device to execute the method according to any one of claims 1 to 11.
