Image classification method, device, electronic device and storage medium

By training the initial model with adversarial sample sets and soft labels, the problem of image classification business interruption caused by cloud model downtime is solved, the function and accuracy of the image classification model are restored, and the business interruption problem caused by cloud model downtime is solved.

CN114510592BActive Publication Date: 2024-10-15TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202011287253.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-11-17
Publication Date
2024-10-15
Estimated Expiration
2040-11-17

AI Technical Summary

Technical Problem

When the machine learning model in the cloud goes down, users cannot carry out image classification business normally. It is difficult for existing technology to effectively solve this problem.

Method used

By obtaining the adversarial sample set and inputting it into the target model to generate soft labels, the adversarial sample set and soft labels are used to train the initial model and restore the function and test accuracy of the target model, thereby achieving accurate prediction of image classification.

Benefits of technology

It effectively avoids the interruption of image classification business due to the downtime of the target model cloud server, and realizes the recovery of the basic functions and test accuracy of the image classification model, achieving excellent test accuracy higher than 75% and model function recovery rate higher than 91%. Effect.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114510592B_ABST
    Figure CN114510592B_ABST
Patent Text Reader

Abstract

The embodiments of the present application provide an image classification method, device, electronic device and storage medium, which relate to the field of machine learning technology. The method includes: obtaining an image to be classified; inputting the image to be classified into a pre-trained image classification model to obtain the classification result of the image classification model; wherein the image classification model is trained by an adversarial sample set and a soft label corresponding to the adversarial sample set, and the soft label is generated by the target model based on the adversarial sample set as input, and the adversarial sample set is generated by augmenting a cross-domain image data set by at least two adversarial sample generators. The image classification model of the embodiment of the present application can basically restore the function and test accuracy of the target model, so as to predict accurate classification results for the image to be classified, avoiding the problem that the image classification business cannot be carried out normally because the cloud server of the target model is down.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of machine learning technology. Specifically, the present application relates to an image classification method device, an electronic device and a storage medium. Background Art

[0002] As the depth of the network gradually deepens, the cost of training the network increases. Models with good performance have become important achievements and even property of companies / research institutions. In order to protect the model and open its functions to the public, institutions often deploy the model in the cloud and open the API to users to achieve "machine learning as a service" (MLaaS).

[0003] Machine Learning as a Service (MLaaS) is a set of cloud computing services that provide end users with machine learning products and solutions for data transformation, model training, and ultimately predictive analysis. These services typically allow users to upload clearly labeled images and create specific workflows to meet their needs by using built-in algorithms or directly adopting pre-trained models. For these services, users can access the paid API interface provided by MLaaS and obtain corresponding classification results through the selected input. Generally speaking, users cannot access the details of the target model or the parameters used for optimization (i.e., black box),

[0004] Since the target model is generally deployed in the cloud by the model provider, when the cloud service crashes, users will not be able to call the target model, which will affect their work progress. Summary of the invention

[0005] Embodiments of the present invention provide an image classification method, device, electronic device, and storage medium that overcome the above problems or at least partially solve the above problems.

[0006] In a first aspect, an image classification method is provided, the method comprising:

[0007] Get the image to be classified;

[0008] Input the image to be classified into a pre-trained image classification model to obtain the classification result of the image classification model;

[0009] Among them, the image classification model is trained by an adversarial sample set and soft labels corresponding to the adversarial sample set, the soft labels are generated by the target model with the adversarial sample set as input, and the adversarial sample set is generated by augmenting a cross-domain image dataset through at least two adversarial sample generators.

[0010] In one possible implementation, the training method of the image component model includes:

[0011] Obtain an image dataset, input the image dataset into at least two pre-trained adversarial sample generators for data augmentation, and obtain adversarial sample sets output by at least two adversarial sample generators;

[0012] Input the adversarial sample set into the target model to obtain the soft label output by the target model. The soft label is used to represent the probability distribution of the classification result of the corresponding adversarial sample.

[0013] The initial model is trained until convergence based on the adversarial sample set and soft labels as an image classification model.

[0014] In a possible implementation, an image dataset is obtained, and the image dataset is input into at least two pre-trained adversarial sample generators for data augmentation, including:

[0015] Obtain at least one image data set, and create multiple parallel processing threads according to the number of image data sets and adversarial sample generators, wherein the threads are used to input an image data set into an adversarial sample generator to obtain an adversarial sample set output by the adversarial sample generator;

[0016] Among them, at least one of the image datasets and adversarial sample generators processed by any two threads is different.

[0017] In one possible implementation, inputting the adversarial sample set into the target model includes:

[0018] If any thread obtains the adversarial sample set at the current moment, the adversarial sample set is input into the target model.

[0019] In a possible implementation, the initial model is trained to convergence according to the adversarial sample set and the soft labels as an image classification model, including:

[0020] According to the adversarial sample set obtained by any thread at the current moment and the soft labels corresponding to the adversarial sample set, the initial model of the current stage is trained until convergence, the initial model of the next stage is obtained, and the initial model of the last stage is used as the image classification model;

[0021] Among them, the initial model of the last stage is trained based on the last generated adversarial sample set and the corresponding soft labels.

[0022] In a possible implementation, the image dataset is input into at least two pre-trained adversarial sample generators for data augmentation, and the process also includes:

[0023] Obtain a training sample set, train the adversarial sample generator according to the training sample set, and obtain a trained adversarial sample generator;

[0024] Among them, the data domains of the training sample set and the image dataset are different.

[0025] In a possible implementation, the image dataset is input into at least two pre-trained adversarial sample generators for data augmentation, and the process also includes:

[0026] Obtain a training sample set, train the adversarial sample generator according to the training sample set, and obtain a trained adversarial sample generator;

[0027] The data in the image data set are obtained by performing image transformation on the training samples in the training sample set.

[0028] In one possible implementation, the adversarial sample generator is a ResNet structure.

[0029] In a second aspect, a model recovery method is provided, comprising:

[0030] Obtain an image dataset and at least two pre-trained adversarial sample generators, where the image dataset and the training set of the adversarial sample generator are from different data domains;

[0031] Inputting the image data sets into at least two adversarial sample generators respectively to obtain adversarial sample sets output by at least two adversarial sample generators;

[0032] Input the adversarial sample set into the target model to obtain the soft label output by the target model;

[0033] The initial model is trained until convergence based on the adversarial sample set and soft labels, and used as the recovered target model.

[0034] In a third aspect, an image classification device is provided, comprising:

[0035] An image acquisition module to be classified is used to acquire images to be classified;

[0036] An input module is used to input the image to be classified into a pre-trained image classification model to obtain the classification result of the image classification model;

[0037] Among them, the image classification model is trained by an adversarial sample set and soft labels corresponding to the adversarial sample set, the soft labels are generated by the target model with the adversarial sample set as input, and the adversarial sample set is generated by augmenting a cross-domain image dataset through at least two adversarial sample generators.

[0038] In a possible implementation, the image classification device further includes: a model recovery module, the model recovery module includes:

[0039] An image data set acquisition unit, used to acquire an image data set, input the image data set into at least two pre-trained adversarial sample generators for data augmentation, and obtain adversarial sample sets output by at least two adversarial sample generators;

[0040] A soft label acquisition unit, used to input the adversarial sample set into the target model to obtain the soft label output by the target model, where the soft label is used to represent the probability distribution of the classification result of the corresponding adversarial sample;

[0041] The training unit is used to train the initial model to convergence according to the adversarial sample set and the soft labels as an image classification model.

[0042] In a possible implementation, the image data set acquisition unit is specifically used to: acquire at least one image data set, create multiple parallel processing threads according to the number of image data sets and adversarial sample generators, and the threads are used to input an image data set into an adversarial sample generator to obtain an adversarial sample set output by the adversarial sample generator;

[0043] Among them, at least one of the image datasets and adversarial sample generators processed by any two threads is different.

[0044] In a possible implementation, the soft label acquisition unit is specifically used to: if any thread obtains the adversarial sample set at the current moment, then input the adversarial sample set into the target model.

[0045] In a possible implementation, the training unit is specifically used to: train the initial model of the current stage until convergence according to the adversarial sample set obtained by any thread at the current moment and the soft labels corresponding to the adversarial sample set, obtain the initial model of the next stage, and use the obtained initial model of the last stage as the image classification model;

[0046] Among them, the initial model of the last stage is trained based on the last generated adversarial sample set and the corresponding soft labels.

[0047] In a possible implementation, the model recovery module further includes:

[0048] A first generator training unit is used to obtain a training sample set, train an adversarial sample generator according to the training sample set, and obtain a trained adversarial sample generator;

[0049] Among them, the transferability of the adversarial sample generator meets the preset conditions; the data domain of the training sample set is different from that of the image dataset.

[0050] In a possible implementation, the model recovery module further includes:

[0051] A second generator training unit is used to obtain a training sample set, train the adversarial sample generator according to the training sample set, and obtain a trained adversarial sample generator;

[0052] The data in the image data set are obtained by performing image transformation on the training samples in the training sample set.

[0053] In one possible implementation, the adversarial sample generator is a ResNet structure.

[0054] In a fourth aspect, an embodiment of the present application provides a model recovery device, including:

[0055] A preparation module, configured to obtain an image dataset and at least two pre-trained adversarial sample generators, wherein the image dataset is in a different data domain from a training sample set of the adversarial sample generator;

[0056] An adversarial sample set acquisition module is used to input the image data set into at least two adversarial sample generators respectively to obtain adversarial sample sets output by at least two adversarial sample generators;

[0057] A soft label acquisition module is used to input the adversarial sample set into the target model to obtain the soft label output by the target model;

[0058] The recovery module is used to train the initial model to convergence based on the adversarial sample set and soft labels as the recovered target model.

[0059] In a fifth aspect, an embodiment of the present invention provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the method provided in the first aspect or the second aspect are implemented.

[0060] In a sixth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method provided in the first aspect or the second aspect.

[0061] The image classification method, device, electronic device and storage medium provided by the embodiments of the present invention obtain an adversarial sample set, input the adversarial sample set into the target model to obtain soft labels, use the adversarial sample set and the soft labels to train the initial model, and use the trained initial model as the image classification model. The image classification model can basically restore the function and test accuracy of the target model, thereby predicting accurate classification results for the image to be classified, avoiding the problem of being unable to carry out image classification business normally due to the downtime of the cloud server of the target model. BRIEF DESCRIPTION OF THE DRAWINGS

[0062] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in describing the embodiments of the present application are briefly introduced below.

[0063] Figure 1 A logical diagram of the model recovery method;

[0064] Figure 2 A schematic diagram of the process of an image classification method according to an embodiment of the present application;

[0065] Figure 3 A schematic diagram of a process for restoring a target model provided in an embodiment of the present application;

[0066] Figure 4 A schematic diagram of obtaining an adversarial sample set using multiple threads provided in an embodiment of the present application;

[0067] Figure 5 A schematic diagram of a flow chart of a model recovery method provided in an embodiment of the present application;

[0068] Figure 6 A schematic diagram of an application scenario provided in an embodiment of the present application;

[0069] Figure 7 A schematic diagram of another application scenario provided by an embodiment of the present application;

[0070] Figure 8 A flowchart of a model recovery method provided by another embodiment of the present application;

[0071] Fig. 9 A schematic diagram of the structure of an image classification device provided in an embodiment of the present application;

[0072] Fig.10 A schematic diagram of the structure of a model recovery module provided in an embodiment of the present application;

[0073] Fig.11 A schematic diagram of the structure of a model recovery device provided in an embodiment of the present application;

[0074] Fig.12 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0075] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be interpreted as limiting the present invention.

[0076] It will be understood by those skilled in the art that, unless expressly stated, the singular forms "one", "an" and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present application refers to the presence of features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof. It should be understood that when we refer to an element as being "connected" or "coupled" to another element, it may be directly connected or coupled to the other element, or there may be an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein includes all or any unit and all combinations of one or more associated listed items.

[0077] From the above description, it can be seen that when the model deployed in the cloud crashes, the user will not be able to call the target model, which will affect the work progress. Therefore, in order to solve the above problem, the existing technology usually adopts the model recovery method to restore the target model to the local, and then use the restored model to perform image classification.

[0078] Figure 1 The logical diagram of the model recovery method is as follows: Figure 1 As shown in the figure, the generation of the model itself is a process that requires a lot of manpower and material resources. First, the creator of the model must first collect a large number of sample image sets P V (X), the sample images in the sample image set can be represented by x i It means that the acquired sample images need to be annotated, that is, the labels of the sample images are determined, and the training sample set D with sample labels can be obtained. V ={(x i ,y i )} means, where y i Represents the sample image x i When labeling, it is also necessary to determine the initial structure and initial parameters of the model. The model can be expressed as V It means that by training the model with sample labels until convergence, the final model can be obtained, which can be expressed by the expression y = F V (x) means that when x is input to the model, the model outputs F V (x) An opaque black box is deployed in the cloud and a query interface is provided to the outside world. When the outside world accesses the black box through the query interface and inputs images into the black box, they can only obtain the output of the model but not the operation process of the model.

[0079] The image classification method, device, electronic device and computer-readable storage medium provided in this application are intended to solve the above technical problems in the prior art.

[0080] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.

[0081] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.

[0082] Figure 2 Schematic diagram of the process of the image classification method of the embodiment of the present application, such as Figure 2 As shown, including:

[0083] S101, obtaining an image to be classified.

[0084] The image to be classified is an image that needs to be classified. The image to be classified can be a live broadcast image of a live broadcast platform, an image of chat content, a surveillance image, or an image that needs to be classified in other scenes, which is not specifically limited here.

[0085] S102: input the image to be classified into a pre-trained image classification model to obtain a classification result of the image classification model.

[0086] It should be noted that the image classification model of the embodiment of the present application is not a model deployed in the cloud (referred to as the target model), but a model after the target model is restored to the local. By restoring the target model to the local, the problem of being unable to call the target model due to cloud server crashes can be avoided.

[0087] The image classification model of the embodiment of the present application is trained by the adversarial sample set and the soft labels output by the target model for the adversarial sample set. The adversarial sample set is a set composed of adversarial samples. The subsequent input causes the model to give an erroneous output with high confidence. Since the adversarial sample is a normal sample that deliberately adds interference information, by analyzing the soft labels generated by the target model for the adversarial sample, the processing result of the target model on the interference information can be analyzed, which is conducive to restoring the prediction ability of the target model.

[0088] The adversarial sample set in the embodiment of the present application is generated by augmenting a cross-domain image sample set by at least two adversarial sample generators.

[0089] It should be understood that when the data domains of the image dataset and the training sample set used by the training adversarial sample generator are different, it is called generating the adversarial sample set in a cross-domain manner. Generating the adversarial sample set in a cross-domain manner can ensure high-quality augmentation of the adversarial samples compared to when the data domains of the image dataset and the training sample set used by the training adversarial sample generator are the same.

[0090] From the above description, it can be seen that the embodiment of the present application uses adversarial samples in the adversarial sample set as training samples, and uses the soft labels output by the target model according to the adversarial sample set as sample labels to train the initial model until convergence, that is, to obtain an image classification model.

[0091] The embodiment of the present application obtains an adversarial sample set, inputs the adversarial sample set into the target model to obtain soft labels, uses the adversarial sample set and soft labels to train the initial model, and uses the trained initial model as an image classification model. The image classification model can basically restore the function and test accuracy of the target model, thereby predicting accurate classification results for the image to be classified, avoiding the problem of being unable to carry out image classification business normally due to the downtime of the cloud server of the target model. Figure 3 A schematic diagram of a process for restoring a target model provided in an embodiment of the present application is shown in FIG. Figure 3 As shown, the method includes:

[0092] S201. Obtain an image dataset, input the image dataset into at least two pre-trained adversarial sample generators for data augmentation, and obtain an adversarial sample set output by at least two adversarial sample generators.

[0093] It should be understood that the data set is the basis for training and testing neural networks. The embodiments of the present application do not specifically limit the number of classification problems solved by the image data set. For example, it can be an image data set that solves a binary classification problem, or it can be an image data set that solves more categories, such as a ten-category problem. A binary classification problem, that is, the data in the image data set is either type 1 or type 2. For example, an image data set consisting of apple pictures, where the pictures in the image data set either depict green apples or red apples, is an image data set that solves a binary classification problem.

[0094] After acquiring the image data set, the embodiment of the present application does not directly input the image data set into the target model to be restored, but first inputs the image data set into a pre-trained adversarial sample generator to generate an adversarial sample set. As the name implies, the adversarial sample set is a set of adversarial examples. Adversarial examples are input samples formed by deliberately adding subtle interference to the data set. The interfered input causes the model to give an erroneous output with high confidence.

[0095] Examples generator is a generator used to generate adversarial examples. The goal of the adversarial example generator is to generate data that makes the classification results of the initial model and the target model inconsistent, while the goal of the initial model is to imitate the output of the target model. This forms a system of mutual gaming.

[0096] The adversarial sample generator has a multi-branch structure, each branch represents a category, and finally the generator will add a category-controlled loss function to constrain each branch to generate data with specific category attributes. The advantage of this is that the adversarial sample generator can be controlled to generate training data with sufficient diversity for the initial model. If not controlled, the adversarial sample generator will only generate training data with single or partial attributes for the initial model, which will also cause the problem of model collapse of the traditional generative adversarial network. If the initial model can effectively copy the properties of the model to be restored when the adversarial sample generator is strong enough, the function of the target model can be restored or a series of subsequent actions can be performed. For example, in verifying the defense capability of the target model against attacks, the adversarial sample generator obtained in the embodiment of the present application can be used to generate adversarial samples and migrate them to the target model to complete the defense capability verification.

[0097] Data augmentation is one of the commonly used techniques in deep learning, which is mainly used to increase the training data set, make the data set as diverse as possible, and make the trained model have stronger generalization ability. The data augmentation method of the embodiment of the present application can be to input the same image data set into multiple different adversarial sample generators. Since the adversarial sample generators are different, the outputs of the adversarial sample generators will not be the same, so multiple adversarial sample sets can be obtained based on one image data set. Furthermore, before inputting the data set into the pre-trained adversarial sample generator, it also includes:

[0098] A training sample set is obtained, and an adversarial sample generator is trained according to the training sample set to obtain a trained adversarial sample generator.

[0099] The data domains of the training sample set and the image data set in the embodiment of the present application are different. For example, the data domain in the image data set may be cats and dogs, while the data domain of the training sample set may be face images.

[0100] It should be understood that the adversarial sample generator is trained together with the adversarial sample discriminator. The adversarial sample generator is part of the Generative Adversarial Networks (GAN). The Generative Adversarial Networks consists of at least two parts, namely the adversarial sample generator (Generative Model) and the adversarial sample discriminator (Discriminative Model). The purpose of the adversarial sample generator is to generate adversarial samples and make the generated pictures (i.e. adversarial samples) "look" real, while the goal of the adversarial sample discriminator is to correctly judge whether a picture is generated or real. Therefore, the model of the generative adversarial network is: the generative model generates some pictures -> the discriminative model learns to distinguish between generated pictures and real pictures -> the generative model improves itself according to the discriminative model and generates new pictures ->... Specifically, the training process of the adversarial sample generator is as follows:

[0101] (1) Initialize the parameters of the generator G and the discriminator D networks.

[0102] (2) Extract n samples from the training set, input n samples into the generator, and generate n adversarial samples using the defined noise distribution.

[0103] (3) Fix the generator G and use n adversarial samples to train the discriminator D so that the trainer D can distinguish between true and false as much as possible.

[0104] (4) After cyclically updating the discriminator D k times, update the generator G once.

[0105] (5) After multiple updates and iterations, in an ideal state, the discriminator D is unable to distinguish whether the image comes from the real training sample set or from the sample generated by the generator G. At this time, the probability of discrimination is 0.5, and the training is completed.

[0106] Through experiments, the embodiments of the present application found that the effectiveness of adversarial samples on model recovery depends to a large extent on the migration ability of the samples. Therefore, when selecting an adversarial sample generator, the embodiments of the present application need to quantitatively evaluate the transferability of the adversarial sample generator and use an adversarial sample generator with higher transferability to generate adversarial samples.

[0107] Optionally, the embodiment of the present application can quantitatively evaluate the transferability of the adversarial sample generator through an attribution graph. Given an input data, the attribution of a deep model refers to calculating an importance value for each dimension of the input for a certain output of the model. This value reflects the importance of the input dimension to this output. The larger the importance value, the greater the impact of changing the data of this dimension on this output. Since each input dimension has an attribution value corresponding to it, the attribution graph size is the same as the input size. Current model attribution methods can be roughly divided into two categories: perturbation-based attribution and gradient-based attribution. Perturbation-based attribution, as the name implies, observes the change in output by making some changes to one or some dimensions of the input data, and measures the importance of the dimension by the size of the change in output. When estimating mobility, the model generates a set of attribution graphs for a given detection data set. Therefore, each model can be regarded as being embedded in a model space, which is composed of all dimensions of the attribution graph. The mobility between models is measured by the distance between the embedding points of the model in the model space.

[0108] Based on the above embodiments, as an optional embodiment, the model result of the adversarial sample generator in the embodiment of the present application adopts the ResNet structure. ResNet is a residual network that can effectively solve the problems of gradient diffusion / explosion and network degradation. It has been verified that the adversarial sample generator using the ResNet structure has high mobility.

[0109] In addition, the training sample set used to train the adversarial sample generator in the embodiment of the present application also needs to be different from the data domain of the image data set, so as to take advantage of the high mobility of the adversarial sample generator and ensure high-quality augmentation of the adversarial samples.

[0110] It should be noted that when the data domains of the image dataset and the training sample set used by the training adversarial sample generator are different, it is called generating the adversarial sample set in a cross-domain manner. In addition to generating the adversarial sample set in a cross-domain manner, the embodiments of the present application can also obtain the image dataset by performing image transformation on the training sample set. For example, a set of image datasets can be obtained by translating the training samples in the training sample set, a set of image datasets can be obtained by rendering the training samples in the training sample set, and a set of image datasets can also be obtained by scaling the training samples in the training sample set.

[0111] S202: Input the adversarial sample set into the target model to obtain the soft label output by the target model.

[0112] In an embodiment of the present application, an adversarial sample in an adversarial sample set is input into a target model to obtain a soft label output by the target model.

[0113] Soft labels refer to labeling multiple category labels for each sample, indicating the probability distribution of the classification results. For example, when multiple annotators label the same sample, different annotators may label the same sample as different categories due to the confusion of the sample itself and the subjectivity of the annotators when labeling. Labeling samples with soft labels makes it easier to describe the correlation between different categories. For example, a certain adversarial sample is a three-category sample, and the soft label result output by the target model can be: Category 1: 32%, Category 2: 43%, Category 3: 35%, that is, the probability of labeling the adversarial sample in the three categories respectively. Obtaining the soft label output by the target model can obtain more details generated by the target model when making predictions than obtaining hard labels, which is more conducive to model recovery.

[0114] S203: Train the initial model according to the adversarial sample set and the soft labels until convergence, and use it as an image classification model.

[0115] In the field of training neural network models, the cross entropy loss function is usually calculated based on the hard labels and the output of the initial model, and the parameters of the initial model are adjusted to make the model converge. However, the hard labels contain too little information compared to the soft labels. In the embodiment of the present application, after the adversarial sample set is input into the initial model, the cross entropy loss function is directly calculated based on the output of the initial model and the soft labels without making additional modifications. On the one hand, the speed is faster, and on the other hand, the feasibility can be guaranteed.

[0116] The model recovery method of the embodiment of the present application first inputs the image data set into the adversarial sample generator for data augmentation to obtain the adversarial sample set, which can generate training data with sufficient diversity for the initial model to use, and inputs the adversarial sample set into the target model to obtain soft labels. Compared with obtaining hard labels, more prediction details of the target model can be obtained. Finally, the initial model is trained according to the adversarial samples and soft labels until convergence, which can increase the probability of recovery, not only faster recovery speed, but also ensure feasibility. It has been verified that the model recovery method of the embodiment of the present application can achieve excellent results of test accuracy (TestAccuracy) higher than 75% and model function recovery rate (Function Recover Rate) higher than 91%, which is better than the existing model recovery method.

[0117] Based on the above embodiments, as an optional embodiment, the number of adversarial sample generators is at least two.

[0118] Optionally, any two adversarial sample generators in the embodiments of the present application use different training sample sets when training, for example, the data domain of one training sample set is images in the field of facial recognition, and the data domain of the other training sample set is images in the field of fruit recognition. By setting a cross-domain adversarial sample generator, a cross-domain adversarial sample set can be further obtained. Using the cross-domain adversarial sample set to train the initial model can make the prediction ability of the image classification model finally obtained also cross-domain, thereby improving the scope of application scenarios and prediction accuracy; in addition, the training sample sets used when training any two adversarial sample generators can also be different training sample sets in the same data domain.

[0119] On this basis, the embodiment of the present application obtains an image data set and inputs the image data set into at least two pre-trained adversarial sample generators, including:

[0120] At least one image data set is obtained, and a plurality of parallel processing threads are created according to the number of image data sets and adversarial sample generators, wherein the threads are used to input an image data set into an adversarial sample generator to obtain an adversarial sample set output by the adversarial sample generator.

[0121] It is understandable that the image data set of the embodiment of the present application can be the same as the data domain of the training sample of the adversarial sample generator, so that it is more conducive to the adversarial sample generator to generate more misleading adversarial samples. Based on this, the number of image data sets is consistent with the number of adversarial sample generators, and the number of threads created further is also consistent with the number of adversarial sample generators.

[0122] In addition, the image dataset may not be the same as the data domain of the training samples of the adversarial sample generator. In this case, if the number of image datasets is M and the number of adversarial sample generators is N, where M is not less than 1 and N is greater than 1, then M×N threads need to be constructed.

[0123] In the embodiments of the present application, the image datasets and adversarial sample generators processed by any two threads are different. For example, the two threads may input the same image dataset into different adversarial sample generators, or input different image datasets into different adversarial sample generators, or input different image datasets into the same adversarial sample generator. The embodiments of the present application do not make specific limitations.

[0124] The embodiment of the present application generates adversarial sample sets by constructing multiple parallel threads, so that the generation speed of adversarial sample sets is greatly improved compared with the speed of serially generating adversarial sample sets, laying a foundation for improving the model recovery speed.

[0125] Figure 4 A schematic diagram of obtaining an adversarial sample set using multiple threads provided in an embodiment of the present application, such as Figure 4As shown, three processing threads are created, where thread 1 is used to process the image dataset D s1 Input to the adversarial sample generator G adv1 , get the adversarial sample generator G adv1 Output adversarial sample set D st1 ; Thread 2 is used to convert the image dataset D s2 Input to the adversarial sample generator G adv2 , get the adversarial sample generator G adv2 Output adversarial sample set D st2 ; Thread 3 is used to convert the image dataset D s3 Input to the adversarial sample generator G adv3 , get the adversarial sample generator G adv3 Output adversarial sample set D st3 It should be noted that the image dataset D s1 ~D s3 Can be the same or different.

[0126] Based on the above embodiments, as an optional embodiment, inputting the adversarial sample set into the target model includes:

[0127] If any thread obtains the adversarial sample set at the current moment, the adversarial sample set is input into the target model.

[0128] That is to say, the embodiment of the present application runs multiple threads in parallel. When any thread obtains an adversarial sample set, it does not need to wait for the processing results of other threads, and inputs the obtained adversarial sample set into the target model to obtain the soft label output by the target model. This setting can shorten the cycle of model recovery.

[0129] by Figure 4 For example, if thread 1 first obtains the adversarial sample set D st1 , then the adversarial sample set D st1 Input the target model and then transform the adversarial sample set D st1 In the process of inputting the target model, or the adversarial sample set D st1 After inputting the target model, thread 2 obtains the adversarial sample set D st2 , then the adversarial sample set D st2 Input the target model and then transform the adversarial sample set D st2 In the process of inputting the target model, or the adversarial sample set D st2 After inputting the target model, thread 3 obtains the adversarial sample set D st2 , then the adversarial sample set D st3Input the target model. And, from the above description, it can be seen that the input of data (adversarial sample set) into the target model is actually achieved by inputting the data into the public interface of the target model. Since the interface has the function of receiving massive data in real time in actual application, even if multiple adversarial sample sets are input into the target model at the same time, it will not be affected.

[0130] Based on the above embodiments, as an optional embodiment, the initial model is trained until convergence according to the adversarial sample set and the soft label as an image classification model, including:

[0131] According to the adversarial sample set obtained by any thread at the current moment and the soft labels corresponding to the adversarial sample set, the initial model of the current stage is trained until convergence, the initial model of the next stage is obtained, and the initial model of the last stage is used as the image classification model;

[0132] Among them, the initial model of the last stage is trained based on the last generated adversarial sample set and the corresponding soft labels.

[0133] It should be noted that the time when each thread obtains the adversarial sample set in the embodiment of the present application is not consistent, and further, the time when the target model outputs the soft label according to the adversarial sample set is also inconsistent. When training the initial model, the embodiment of the present application determines the training stage according to the order of the time of sample data-adversarial sample set and sample label-soft label as a whole. For example, although the time when thread 1 obtains adversarial sample set 1 is earlier than the time when thread 2 obtains adversarial sample set 2, the time when the target model obtains soft label (set) 1 according to adversarial sample set 1 is later than the time when the target model obtains soft label (set) 2 according to adversarial sample set 2. Then, the initial model of the current stage is first trained according to adversarial sample set 2 and soft label (set) 2 until convergence to obtain the initial model of the next stage, and then the initial model of the next stage is trained according to adversarial sample set 1 and soft label (set) 1 to obtain the initial model of the next stage, ..., when all adversarial sample sets and corresponding soft labels are trained with the initial model, the initial model of the last stage obtained is the image classification model.

[0134] Figure 5 A flow chart of the model recovery method provided in the embodiment of the present application is shown as follows: Figure 5 As shown, three threads are created, where thread 1 is used to convert the image dataset D s1 Input to the adversarial sample generator G adv1 , get the adversarial sample generator G adv1 Output adversarial sample set D st1 ; Thread 2 is used to convert the image dataset D s2 Input to the adversarial sample generator G adv2 , get the adversarial sample generator Gadv2 Output adversarial sample set D st2 ; Thread 3 is used to convert the image dataset D s3 Input to the adversarial sample generator G adv3 , get the adversarial sample generator G adv3 Output adversarial sample set D st3 ; The adversarial sample set D st1 ~D st3 Input them into the target model Mv respectively to obtain the corresponding soft labels L1~L3. For the convenience of description, Figure 5 In the embodiment shown, the adversarial sample set D st1 The acquisition time is earlier than the adversarial sample set D st2 , adversarial sample set D st2 The acquisition time is earlier than the adversarial sample set D st3 , soft label L1 is obtained earlier than soft label L2, and soft label L2 is obtained earlier than soft label L3, so Figure 5 In the first step, according to the adversarial sample set D st1 and soft label L1 to train the initial initial model M s0 Until convergence, the initial model M of the first stage is obtained s1 , then according to the adversarial sample set D st2 And soft label L2 train the initial model M s1 Until convergence, the initial model M of the second stage is obtained s2 , and then according to the adversarial sample set D st3 and soft label L3 to train the initial model M s2 Until convergence, the initial model M of the third stage is obtained s3 , the initial model M s3 As an image classification model.

[0135] Based on the above embodiments, after the initial model is trained to obtain the image classification model, the embodiment of the present application can also deploy the image acquisition model on other servers, so that when the server of the target model crashes, image classification can be performed through the image acquisition model deployed on other servers.

[0136] See also Figure 6 , which is an application scenario diagram provided in an embodiment of the present application, the server 11 and the server 12 are respectively connected to the terminal 13 through a network, for example, through a wired or wireless network connection, etc. The server 11 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud computing services.

[0137] Among them, what is deployed on server 11 is the target model, which is a model with complete image classification capabilities and accuracy. What is deployed on server 12 is the model after the target model is restored, that is, the image classification model in the above embodiments, which restores most of the image classification capabilities and accuracy of the target model.

[0138] The terminal 13 may include a mobile phone, a smart TV, a tablet computer, a laptop computer, or a personal computer (PC). When the terminal 13 needs to classify an image, it initiates a classification request to the target model deployed on the server 11, and the target model predicts the image to be classified contained in the classification request to obtain a classification result. When the server 11 is down, the terminal 13 initiates a classification request to the image classification model deployed on the server 12 when it needs to classify an image, and the image classification model predicts the image to be classified contained in the classification request to obtain a classification result, thereby avoiding the problem that the image classification work cannot be performed due to the downtime of the server 11.

[0139] The execution method of the server of the embodiment of the present application can be completed in the form of cloud computing. Cloud computing is a computing model that distributes computing tasks on a resource pool composed of a large number of computers, so that various application systems can obtain computing power, storage space and information services as needed. The network that provides resources is called a "cloud". The resources in the "cloud" are infinitely expandable in the eyes of users, and can be obtained at any time, used on demand, expanded at any time, and paid for by use.

[0140] As a provider of basic cloud computing capabilities, a cloud computing resource pool (referred to as a cloud platform, generally referred to as an IaaS (Infrastructure as a Service) platform) will be established, and various types of virtual resources will be deployed in the resource pool for external customers to choose to use. The cloud computing resource pool mainly includes: computing devices (virtualized machines, including operating systems), storage devices, and network devices.

[0141] According to the logical function division, the PaaS (Platform as a Service) layer can be deployed on the IaaS (Infrastructure as a Service) layer, and the SaaS (Software as a Service) layer can be deployed on the PaaS layer. SaaS can also be deployed directly on IaaS. PaaS is a platform for software operation, such as databases, web containers, etc. SaaS is a variety of business software, such as web portals, SMS mass senders, etc. Generally speaking, SaaS and PaaS are upper layers relative to IaaS.

[0142] See also Figure 7 , which is another application scenario diagram provided in an embodiment of the present application, the local database 21 and the local database 22 are respectively directly connected to the terminal 23 through a network, for example, through a wired or wireless network connection, etc. The server 11 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud computing services.

[0143] Among them, an application that can implement the target model is deployed on the local database 21. The target model is a model with complete image classification capabilities and accuracy, and the application has a validity period. The model after the target model is restored is deployed on the local database 22, that is, the image classification model in the above-mentioned embodiments. The image classification model restores most of the image classification capabilities and accuracy of the target model.

[0144] The terminal 13 may include a mobile phone, a smart TV, a tablet computer, a laptop computer, or a personal computer (PC, Personal Computer), etc. When the terminal 13 needs to perform image classification, within the validity period of the application, a classification request can be initiated to the application deployed on the local database 21 and the image classification model deployed on the local database 22, respectively, so that the target model and the image classification model run by the application will respectively predict the image to be classified contained in the classification request, and obtain two classification results, namely, classification result 1 and classification result 2. If the two classification results are different, the image classification model is trained here using the classification result 1 obtained by the image to be classified and the target model, so as to improve the prediction accuracy of the image classification model, so that when the application fails, only the image classification model in the local database 22 can be used for image classification. In order to verify whether the model recovery method of the embodiment of the present application is effective, the embodiment of the present application is based on the Keras deep learning framework, and the ResNet50 neural network trained on CIFAR10 (50,000 RGB color images of size 32*32) is restored, and the test accuracy (TA, Test Accuracy) reaches 87.91%.

[0145] Using all 120K samples of ImageNet-tiny, we perform three cross-domain black-box adversarial data augmentations (qz, adversarial sample generators are trained on paintings, animations, and natural images, respectively), and obtain 480K samples for querying the black box to obtain soft labels. These sample-label pairs are used to train three models, Xception, DenseNet, and InceptionV3, for 10 epoch iterations. Finally, using the 10,000 test sets of CIFAR10 to test the accuracy of the three models, we obtain TAs of 81.31%, 80.80%, and 75.15%, respectively, and the corresponding FRRs (Function Recover Rates) are 92.5%, 91.9%, and 85.5%, respectively. It can be seen that the functions of the original model can be largely restored using the embodiments of the present invention.

[0146] The present application also provides a model method, see Figure 8 ,include:

[0147] S301, obtaining an image dataset and at least two pre-trained adversarial sample generators, wherein the image dataset and the training set of the adversarial sample generator have different data domains.

[0148] The embodiment of the present application generates an adversarial sample set by using a cross-domain image dataset, by making the data domain of the image dataset different from that of the training set of the adversarial sample generator. This can ensure high-quality augmentation of the adversarial samples compared to when the data domains of the image dataset and the training sample set used to train the adversarial sample generator are the same.

[0149] S302. Input the image data set into at least two adversarial sample generators respectively to obtain adversarial sample sets output by at least two adversarial sample generators.

[0150] In the embodiment of the present application, an image data set is input into multiple adversarial sample generators. Since different adversarial sample generators have different internal parameters, the adversarial sample sets output by different adversarial sample generators are also different, thereby achieving data augmentation.

[0151] S303: Input the adversarial sample set into the target model to obtain the soft label output by the target model.

[0152] It can be seen from the above embodiments that obtaining the soft labels output by the target model can obtain more details generated by the target model when making predictions, compared with obtaining only the hard labels, which is more conducive to model recovery.

[0153] S304: Train the initial model according to the adversarial sample set and the soft labels until convergence, and use it as the recovered target model.

[0154] It should be understood that step S304 is the same as or similar to step S203 in the above embodiment and will not be described in detail here.

[0155] The model recovery method of the embodiment of the present application first inputs the image data set into the adversarial sample generator for data augmentation to obtain the adversarial sample set, which can generate training data with sufficient diversity for the initial model to use, and inputs the adversarial sample set into the target model to obtain soft labels. Compared with obtaining hard labels, more prediction details of the target model can be obtained. Finally, the initial model is trained according to the adversarial samples and soft labels until convergence, which can increase the probability of recovery, not only faster recovery speed, but also ensure feasibility. It has been verified that the model recovery method of the embodiment of the present application can achieve excellent results of test accuracy (TestAccuracy) higher than 75% and model function recovery rate (Function Recover Rate) higher than 91%, which is better than the existing model recovery method.

[0156] The model recovery method of the embodiment of the present application can use the method of using multiple parallel processing threads as described in the above embodiment when inputting the image data set into at least two pre-trained adversarial sample generators, thereby further improving the speed of model recovery.

[0157] The present application embodiment provides an image classification device, such as Fig. 9 As shown, the device may include: an image acquisition module 101 to be classified and an input module 102, specifically:

[0158] The image acquisition module 101 is used to acquire the image to be classified;

[0159] The image to be classified is an image that needs to be classified. The image to be classified can be a live broadcast image of a live broadcast platform, an image of chat content, a surveillance image, or an image that needs to be classified in other scenes, which is not specifically limited here.

[0160] An input module 102 is used to input the image to be classified into a pre-trained image classification model to obtain a classification result of the image classification model;

[0161] It should be noted that the image classification model of the embodiment of the present application is not a model deployed in the cloud (referred to as the target model), but a model after the target model is restored to the local. By restoring the target model to the local, the problem of being unable to call the target model due to cloud server crashes can be avoided.

[0162] The image classification model of the embodiment of the present application is trained by the adversarial sample set and the soft labels output by the target model for the adversarial sample set. The adversarial sample set is a set composed of adversarial samples. The subsequent input causes the model to give an erroneous output with high confidence. Since the adversarial sample is a normal sample that deliberately adds interference information, by analyzing the soft labels generated by the target model for the adversarial sample, the processing result of the target model on the interference information can be analyzed, which is conducive to restoring the prediction ability of the target model.

[0163] It should be noted that when the data domains of the image dataset and the training sample set used by the training adversarial sample generator are different, it is called generating the adversarial sample set in a cross-domain manner. In this way, the adversarial sample set is generated in a cross-domain manner to ensure high-quality augmentation of the adversarial samples.

[0164] The embodiment of the present application can be applied to black box attacks. The embodiment of the present application uses adversarial samples in the adversarial sample set as training samples, and uses the soft labels output by the target model as sample labels to train the initial model until convergence, that is, to obtain an image classification model.

[0165] The soft labels in the embodiment of the present application are generated by the target model using an adversarial sample set as input, and the adversarial sample set is generated by augmenting a cross-domain image dataset by at least two adversarial sample generators.

[0166] The embodiment of the present application obtains an adversarial sample set, and inputs the adversarial sample set into the target model to obtain soft labels, uses the adversarial sample set and soft labels to train the initial model, and uses the trained initial model as the image classification model. The image classification model can basically restore the function and test accuracy of the target model, thereby predicting accurate classification results for the image to be classified, avoiding the problem that the cloud server of the target model cannot normally carry out the image classification business due to downtime. The image classification device provided by the embodiment of the present invention specifically executes the above method embodiment process. For details, please refer to the content of the above image classification device method embodiment, which will not be repeated here. The image classification device provided by the embodiment of the present invention obtains an adversarial sample set, and inputs the adversarial sample set into the target model to obtain soft labels, uses the adversarial sample set and soft labels to train the initial model, and uses the trained initial model as the image classification model. The image classification model can basically restore the function and test accuracy of the target model, thereby predicting accurate classification results for the image to be classified, avoiding the problem that the cloud server of the target model cannot normally carry out the image classification business due to downtime.

[0167] In a possible implementation, the image classification device further includes: a model recovery module, which is used to recover the target model. Fig.10 , the model recovery module includes:

[0168] An image data set acquisition unit 201 is used to acquire an image data set, input the image data set into at least two pre-trained adversarial sample generators for data augmentation, and obtain adversarial sample sets output by at least two adversarial sample generators;

[0169] It should be understood that the data set is the basis for training and testing neural networks. The embodiments of the present application do not specifically limit the number of classification problems solved by the image data set. For example, it can be an image data set that solves a binary classification problem, or it can be an image data set that solves more categories, such as a ten-category problem. A binary classification problem, that is, the data in the image data set is either type 1 or type 2. For example, an image data set consisting of apple pictures, where the pictures in the image data set either depict green apples or red apples, is an image data set that solves a binary classification problem.

[0170] After acquiring the image data set, the embodiment of the present application does not directly input the image data set into the target model to be restored, but first inputs the image data set into a pre-trained adversarial sample generator to generate an adversarial sample set. As the name implies, the adversarial sample set is a set of adversarial examples. Adversarial examples are input samples formed by deliberately adding subtle interference to the data set. The interfered input causes the model to give an erroneous output with high confidence.

[0171] Examples generator is a generator used to generate adversarial examples. The goal of the adversarial example generator is to generate data that makes the classification results of the initial model and the target model inconsistent, while the goal of the initial model is to imitate the output of the target model. This forms a system of mutual gaming.

[0172] The adversarial sample generator has a multi-branch structure, each branch represents a category, and finally the generator will add a category-controlled loss function to constrain each branch to generate data with specific category attributes. The advantage of this is that the adversarial sample generator can be controlled to generate training data with sufficient diversity for the initial model. If not controlled, the adversarial sample generator will only generate training data with single or partial attributes for the initial model, which will also cause the problem of model collapse of the traditional generative adversarial network. If the initial model can effectively copy the properties of the model to be restored when the adversarial sample generator is strong enough, it can steal the function of the target or carry out a series of subsequent attacks. For example, in verifying the defense capability of the target model against attacks, the adversarial sample generator obtained in the embodiment of the present application can be used to generate adversarial samples and migrate them to the target model to complete the defense capability verification.

[0173] The soft label acquisition unit 202 is used to input the adversarial sample set into the target model to obtain the soft label output by the target model, where the soft label is used to represent the probability distribution of the classification result of the corresponding adversarial sample.

[0174] In an embodiment of the present application, an adversarial sample in an adversarial sample set is input into a target model to obtain a soft label output by the target model.

[0175] Soft labels refer to labeling multiple category labels for each sample, indicating the probability distribution of the classification results. For example, when multiple annotators label the same sample, different annotators may label the same sample as different categories due to the confusion of the sample itself and the subjectivity of the annotators when labeling. Labeling samples with soft labels makes it easier to describe the correlation between different categories. For example, a certain adversarial sample is a three-category sample, and the soft label result output by the target model can be: Category 1: 32%, Category 2: 43%, Category 3: 35%, that is, the probability of labeling the adversarial sample in the three categories respectively. Obtaining the soft label output by the target model can obtain more details generated by the target model when making predictions than obtaining hard labels, which is more conducive to model recovery.

[0176] The training unit 203 is used to train the initial model according to the adversarial sample set and the soft labels until convergence, as an image classification model.

[0177] In the field of training neural network models, the cross entropy loss function is usually calculated based on the hard labels and the output of the initial model, and the parameters of the initial model are adjusted to make the model converge. However, the useful hard labels contain too little information compared to the soft labels. In the embodiment of the present application, after the adversarial sample set is input into the initial model, the cross entropy loss function is directly calculated based on the output of the initial model and the soft labels without making additional modifications. On the one hand, the speed is faster, and on the other hand, the feasibility can be guaranteed.

[0178] The model recovery method of the embodiment of the present application first inputs the image data set into the adversarial sample generator to obtain the adversarial sample set, which can generate training data with sufficient diversity for the initial model to use, and inputs the adversarial sample set into the target model to obtain soft labels. Compared with obtaining hard labels, more prediction details of the target model can be obtained. Finally, the initial model is trained according to the adversarial samples and soft labels until convergence, which can increase the probability of recovery, not only faster recovery speed, but also ensure feasibility. It has been verified that the model recovery method of the embodiment of the present application can achieve excellent results of test accuracy (Test Accuracy) higher than 75% and model function recovery rate (Function Recover Rate) higher than 91%, which is better than the existing model recovery method.

[0179] In one possible implementation, the number of adversarial sample generators is at least two.

[0180] Optionally, any two adversarial sample generators in the embodiments of the present application use different training sample sets when training, for example, the data domain of one training sample set is images in the field of facial recognition, and the data domain of the other training sample set is images in the field of fruit recognition. By setting a cross-domain adversarial sample generator, a cross-domain adversarial sample set can be further obtained. Using the cross-domain adversarial sample set to train the initial model can make the prediction ability of the image classification model finally obtained also cross-domain, thereby improving the scope of application scenarios and prediction accuracy; in addition, the training sample sets used when training any two adversarial sample generators can also be different training sample sets in the same data domain.

[0181] The image data set acquisition unit is specifically used to: acquire at least one image data set, create multiple parallel processing threads according to the number of image data sets and adversarial sample generators, and the threads are used to input an image data set into an adversarial sample generator to obtain an adversarial sample set output by the adversarial sample generator;

[0182] Among them, at least one of the image datasets and adversarial sample generators processed by any two threads is different.

[0183] It is understandable that the image data set of the embodiment of the present application is preferably the same as the data domain of the training sample of the adversarial sample generator, so as to be more conducive to the adversarial sample generator to generate more misleading adversarial samples. Based on this, the number of image data sets is consistent with the number of adversarial sample generators, and the number of threads created is also consistent with the number of adversarial sample generators.

[0184] In addition, the image dataset may not be the same as the data domain of the training samples of the adversarial sample generator. In this case, if the number of image datasets is M and the number of adversarial sample generators is N, where M is not less than 1 and N is greater than 1, then M×N threads need to be constructed.

[0185] In the embodiments of the present application, the image datasets and adversarial sample generators processed by any two threads are different. For example, the two threads may input the same image dataset into different adversarial sample generators, or input different image datasets into different adversarial sample generators, or input different image datasets into the same adversarial sample generator. The embodiments of the present application do not make specific limitations.

[0186] The embodiment of the present application generates adversarial sample sets by constructing multiple parallel threads, so that the generation speed of adversarial sample sets is greatly improved compared with the speed of serially generating adversarial sample sets, laying a foundation for improving the model recovery speed.

[0187] In a possible implementation, the soft label acquisition unit is specifically used to: if any thread obtains the adversarial sample set at the current moment, then input the adversarial sample set into the target model.

[0188] That is to say, the embodiment of the present application runs multiple threads in parallel. When any thread obtains an adversarial sample set, it does not need to wait for the processing results of other threads, and inputs the obtained adversarial sample set into the target model to obtain the soft label output by the target model. This setting can shorten the cycle of model recovery.

[0189] In a possible implementation, the training unit is specifically used to:

[0190] According to the adversarial sample set obtained by any thread at the current moment and the soft labels corresponding to the adversarial sample set, the initial model of the current stage is trained until convergence, the initial model of the next stage is obtained, and the initial model of the last stage is used as the image classification model;

[0191] Among them, the initial model of the last stage is trained based on the last generated adversarial sample set and the corresponding soft labels.

[0192] It should be noted that the time when each thread obtains the adversarial sample set in the embodiment of the present application is not consistent, and further, the time when the target model outputs the soft label according to the adversarial sample set is also inconsistent. When training the initial model, the embodiment of the present application determines the training stage according to the order of the time of sample data-adversarial sample set and sample label-soft label as a whole. For example, although the time when thread 1 obtains adversarial sample set 1 is earlier than the time when thread 2 obtains adversarial sample set 2, the time when the target model obtains soft label (set) 1 according to adversarial sample set 1 is later than the time when the target model obtains soft label (set) 2 according to adversarial sample set 2. Then, the initial model of the current stage is first trained according to adversarial sample set 2 and soft label (set) 2 until convergence to obtain the initial model of the next stage, and then the initial model of the next stage is trained according to adversarial sample set 1 and soft label (set) 1 to obtain the initial model of the next stage, ..., when all adversarial sample sets and corresponding soft labels are trained with the initial model, the initial model of the last stage obtained is the image classification model.

[0193] In a possible implementation, the model recovery module further includes:

[0194] A first generator training unit is used to obtain a training sample set, train an adversarial sample generator according to the training sample set, and obtain a trained adversarial sample generator;

[0195] Among them, the transferability of the adversarial sample generator meets the preset conditions; the data domain of the training sample set is different from that of the image dataset.

[0196] Through experiments, the embodiments of the present application have found that the effectiveness of adversarial samples on model recovery depends largely on the migration ability of the samples. Therefore, when selecting an adversarial sample generator, the embodiments of the present application need to quantitatively evaluate the migration ability of the adversarial sample generator and use an adversarial sample generator with higher migration ability to generate adversarial samples. The training sample set used by the embodiment of the present application to train the adversarial sample generator also needs to be different from the data domain of the image dataset, so as to take advantage of the high migration ability of the adversarial sample generator and ensure high-quality augmentation of the adversarial samples.

[0197] In a possible implementation, the model recovery module further includes:

[0198] A second generator training unit is used to obtain a training sample set, train the adversarial sample generator according to the training sample set, and obtain a trained adversarial sample generator;

[0199] The data in the image data set are obtained by performing image transformation on the training samples in the training sample set.

[0200] It should be noted that when the data domains of the image dataset and the training sample set used by the training adversarial sample generator are different, it is called generating the adversarial sample set in a cross-domain manner. In addition to generating the adversarial sample set in a cross-domain manner, the embodiments of the present application can also obtain the image dataset by performing image transformation on the training sample set. For example, a set of image datasets can be obtained by translating the training samples in the training sample set, a set of image datasets can be obtained by rendering the training samples in the training sample set, and a set of image datasets can also be obtained by scaling the training samples in the training sample set.

[0201] In one possible implementation, the adversarial sample generator is a ResNet structure. ResNet is a residual network that can effectively solve the problems of gradient diffusion / explosion and network degradation. It has been verified that the adversarial sample generator using the ResNet structure has high mobility.

[0202] The present application also provides a model recovery device. Fig.11 ,include:

[0203] A preparation module 301 is used to obtain an image dataset and at least two pre-trained adversarial sample generators, wherein the image dataset and the data domain of the training sample set of the adversarial sample generator are different;

[0204] An adversarial sample set acquisition module 302 is used for the adversarial sample set acquisition module, which is used to input the image data set into at least two adversarial sample generators respectively to obtain adversarial sample sets output by at least two adversarial sample generators;

[0205] A soft label acquisition module 303 is used to input the adversarial sample set into the target model to obtain the soft label output by the target model;

[0206] The recovery module 304 is used to train the initial model according to the adversarial sample set and the soft labels until convergence, which serves as the recovered target model.

[0207] An electronic device is provided in an embodiment of the present application, the electronic device comprising: a memory and a processor; at least one program stored in the memory, which is used to be executed by the processor, and compared with the prior art, it can achieve: by obtaining an adversarial sample set, inputting the adversarial sample set into a target model to obtain a soft label, using the adversarial sample set and the soft label to train an initial model, and using the trained initial model as an image classification model, the image classification model can basically restore the function and test accuracy of the target model, thereby predicting an accurate classification result for the image to be classified, avoiding the problem that the image classification service cannot be carried out normally due to the downtime of the cloud server of the target model. .

[0208] In an alternative embodiment, an electronic device is provided, such as Fig.12 As shown, Fig.12 The electronic device 4000 shown includes: a processor 4001 and a memory 4003. The processor 4001 and the memory 4003 are connected, such as through a bus 4002. Optionally, the electronic device 4000 may also include a transceiver 4004. It should be noted that in actual applications, the transceiver 4004 is not limited to one, and the structure of the electronic device 4000 does not constitute a limitation on the embodiments of the present application.

[0209] Processor 4001 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of this application. Processor 4001 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.

[0210] The bus 4002 may include a path to transmit information between the above components. The bus 4002 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 4002 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig.12 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0211] The memory 4003 can be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited to this.

[0212] The memory 4003 is used to store the application code for executing the solution of the present application, and the execution is controlled by the processor 4001. The processor 4001 is used to execute the application code stored in the memory 4003 to implement the contents shown in the above method embodiment.

[0213] The embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer-readable storage medium is run on a computer, the computer can execute the corresponding content in the aforementioned method embodiment. Compared with the prior art, by obtaining an adversarial sample set, inputting the adversarial sample set into the target model to obtain a soft label, using the adversarial sample set and the soft label to train the initial model, and using the trained initial model as the image classification model, the image classification model can basically restore the function and test accuracy of the target model, thereby predicting accurate classification results for the image to be classified, avoiding the problem of being unable to carry out image classification business normally due to the downtime of the cloud server of the target model.

[0214] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.

[0215] The above are only some embodiments of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. An image classification method, characterized in that: include: Get the image to be classified; Inputting the image to be classified into a pre-trained image classification model to obtain a classification result of the image classification model; The image classification model is trained by an adversarial sample set and soft labels corresponding to the adversarial sample set, and the soft labels are generated by a target model using the adversarial sample set as input; the adversarial sample set is generated by augmenting a cross-domain image dataset by at least two adversarial sample generators; The adversarial sample generator quantitatively evaluates the transferability of multiple candidate adversarial sample generators and selects candidate adversarial sample generators with higher transferability; The cross-domain means that the image dataset and the training sample set used by the training adversarial sample generator have different data domains; The image classification model is a model that is a local model of the target model deployed in the cloud and is different from the target model.

2. The image classification method according to claim 1, characterized in that: The training method of the image component model includes: Acquire the image data set, input the image data set into at least two pre-trained adversarial sample generators for data augmentation, and obtain adversarial sample sets output by at least two adversarial sample generators; Inputting the adversarial sample set into the target model to obtain a soft label output by the target model; The initial model is trained according to the adversarial sample set and the soft labels until convergence as an image classification model.

3. The image classification method according to claim 2, characterized in that: The acquiring of an image dataset and inputting the image dataset into at least two pre-trained adversarial sample generators for data augmentation includes: Acquire at least one image data set, and create a plurality of parallel processing threads according to the number of the image data sets and the adversarial sample generators, wherein the threads are used to input one of the image data sets into an adversarial sample generator to obtain an adversarial sample set output by the adversarial sample generator; Among them, at least one of the image datasets and adversarial sample generators processed by any two threads is different.

4. The image classification method according to claim 3, characterized in that: The step of inputting the adversarial sample set into the target model comprises: If any thread obtains an adversarial sample set at the current moment, the adversarial sample set is input into the target model.

5. The image classification method according to claim 4, characterized in that: The initial model is trained according to the adversarial sample set and the soft labels until convergence as an image classification model, including: According to the adversarial sample set obtained by any thread at the current moment and the soft labels corresponding to the adversarial sample set, the initial model of the current stage is trained until convergence, the initial model of the next stage is obtained, and the initial model of the last stage is used as the image classification model; Among them, the initial model of the last stage is trained according to the last generated adversarial sample set and the corresponding soft labels.

6. The image classification method according to any one of claims 2 to 5, characterized in that: The step of inputting the image dataset into at least two pre-trained adversarial sample generators for data augmentation may also include: A training sample set is obtained, and an adversarial sample generator is trained according to the training sample set to obtain a trained adversarial sample generator; the training sample set is in a different data domain from the image data set.

7. The image classification method according to any one of claims 2 to 5, characterized in that: The step of inputting the image dataset into at least two pre-trained adversarial sample generators for data augmentation may also include: Obtaining a training sample set, and training an adversarial sample generator according to the training sample set to obtain a trained adversarial sample generator; The data in the image data set is obtained by performing image transformation on the training samples in the training sample set.

8. The image classification method according to claim 7, characterized in that: The adversarial sample generator is a ResNet structure.

9. A model recovery method, characterized in that: include: Get an image dataset and at least two pre-trained adversarial example generators. Inputting the image data sets into the at least two adversarial sample generators respectively to obtain adversarial sample sets output by the at least two adversarial sample generators; The adversarial sample set is generated by augmenting a cross-domain image dataset by at least two adversarial sample generators; Inputting the adversarial sample set into the target model to obtain a soft label output by the target model; Train the initial model according to the adversarial sample set and the soft labels until convergence, using the model as the recovered target model; The adversarial sample generator quantitatively evaluates the transferability of multiple candidate adversarial sample generators and selects candidate adversarial sample generators with higher transferability; The cross-domain means that the image dataset and the training sample set used by the training adversarial sample generator have different data domains; The initial model is a model that is a local model of the target model deployed in the cloud and is different from the target model.

10. An image classification device, characterized in that: include: An image acquisition module to be classified is used to acquire images to be classified; An input module, used to input the image to be classified into a pre-trained image classification model to obtain a classification result of the image classification model; The image classification model is trained by an adversarial sample set and soft labels corresponding to the adversarial sample set, the soft labels are generated by a target model using the adversarial sample set as input, and the adversarial sample set is generated by augmenting a cross-domain image dataset by at least two adversarial sample generators; The adversarial sample generator quantitatively evaluates the transferability of multiple candidate adversarial sample generators and selects candidate adversarial sample generators with higher transferability; The cross-domain means that the image dataset and the training sample set used by the training adversarial sample generator have different data domains; The image classification model is a model that is a local model of the target model deployed in the cloud and is different from the target model.

11. A model recovery device, characterized in that: include: A preparation module for obtaining an image dataset and at least two pre-trained adversarial sample generators; An adversarial sample set acquisition module, used to input the data set into the at least two adversarial sample generators respectively, and obtain the adversarial sample sets output by the at least two adversarial sample generators; The adversarial sample set is generated by augmenting a cross-domain image dataset by at least two adversarial sample generators; A soft label acquisition module, used to input the adversarial sample set into the target model to obtain the soft label output by the target model; A recovery module, used to train the initial model according to the adversarial sample set and the soft labels until convergence, as a recovered target model; The adversarial sample generator quantitatively evaluates the transferability of multiple candidate adversarial sample generators and selects candidate adversarial sample generators with higher transferability; The cross-domain means that the image dataset and the training sample set used by the training adversarial sample generator have different data domains; The initial model is a model that is a local model of the target model deployed in the cloud and is different from the target model.

12. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the steps of the image classification method according to any one of claims 1 to 8 or the model restoration method according to claim 9 are implemented.

13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions enable the computer to execute the steps of the image classification method according to any one of claims 1 to 8 or the model recovery method according to claim 9.