Image model detection method, device, electronic device and storage medium
Through adversarial image testing to detect the security performance of deep neural network models, the problem of adversarial sample attacks on the model in the field of image classification is solved, and the security of the model is evaluated and improved.
Patent Information
- Application Number
- CN201910901599.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-09-23
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2039-09-23
AI Technical Summary
Deep neural network models are vulnerable to adversarial sample attacks in the field of image classification, leading to recognition errors and security risks. How to detect their security is an urgent problem that needs to be solved.
By obtaining original image samples, use the momentum-based gradient iteration algorithm of the well-trained mainstream image classification model to conduct adversarial attacks, generate adversarial images, and input the original images and adversarial images into the model to be detected for identification, and judge the consistency of the recognition results. If If they are consistent, it is determined that the model has successfully recognized the adversarial image. The number of misjudgments is counted and the accuracy is calculated to evaluate the security level.
Through adversarial image testing, the security performance of the model to be detected is detected, the anti-interference ability of the model is improved, and the security of the deep neural network model is effectively improved.
Smart Images

Figure CN110851835B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of intelligent terminal technology, and in particular to an image model detection method, device, electronic equipment and storage medium. Background Art
[0002] At present, artificial intelligence is applied in many fields, such as face recognition, voiceprint recognition and other scenarios. Its core technology is based on machine learning or deep learning.
[0003] In practice, it is found that although artificial intelligence has brought a lot of convenience to people, there are still some potential risks. For example, in the field of image classification, if the image is maliciously tampered with, but the model recognizes it incorrectly, this will bring security risks to users. This shows that modern deep neural networks are very vulnerable to adversarial samples. These adversarial samples have only slight perturbations, so that the human visual system cannot detect such perturbations (the images look almost the same). Such attacks will cause the neural network to completely change its classification of the image, resulting in recognition errors.
[0004] It can be seen that how to detect the security of deep neural network models is a technical problem that needs to be solved urgently. Summary of the invention
[0005] In view of the above, it is necessary to provide an image model detection method, device, electronic device and storage medium that can detect the security of deep neural network models.
[0006] A first aspect of the present invention provides an image model detection method, the method comprising:
[0007] Get the original image sample;
[0008] Inputting the original image sample into a trained mainstream image classification model;
[0009] Using the mainstream image classification model and the momentum-based gradient iteration algorithm, an adversarial attack is performed on the original image sample to obtain an adversarial image;
[0010] Obtaining a first recognition result obtained after the image model to be detected recognizes the original image sample, and obtaining a second recognition result obtained after the image model to be detected recognizes the adversarial image;
[0011] Determining whether the first recognition result is consistent with the second recognition result;
[0012] If the first recognition result is consistent with the second recognition result, it is determined that the recognition of the adversarial image by the image model to be detected is successful.
[0013] In a possible implementation, using the mainstream image classification model and a momentum-based gradient iteration algorithm to perform an adversarial attack on the original image sample to obtain an adversarial image includes:
[0014] Using the mainstream image classification model, the perturbation amount is calculated based on the momentum-based gradient iteration algorithm;
[0015] Performing convolution smoothing processing on the disturbance amount;
[0016] The processed disturbance amount is added to the original image to obtain an adversarial image.
[0017] In a possible implementation, before obtaining a first recognition result obtained after the image model to be detected recognizes the original image sample, and obtaining a second recognition result obtained after the image model to be detected recognizes the adversarial image, the method further includes:
[0018] Obtaining an image model to be detected that needs to be subjected to model detection from a user terminal device;
[0019] Install the image model to be detected;
[0020] The original image sample and the adversarial image are respectively input into the image model to be detected.
[0021] In a possible implementation, after using the mainstream image classification model to perform an adversarial attack on the original image sample based on a momentum-based gradient iteration algorithm and obtaining an adversarial image, the method further includes:
[0022] A recognition request carrying the original image sample and the adversarial image is sent to a user-end device, wherein the user-end device is installed with an image model to be detected, and the image model to be detected on the user-end device recognizes the original image sample to obtain a first recognition result, and recognizes the adversarial image to obtain a second recognition result.
[0023] In a possible implementation, the method further includes:
[0024] If the first recognition result is inconsistent with the second recognition result, it is determined that the image model to be detected is misjudged;
[0025] Counting the number of misjudgments of the image model to be detected;
[0026] Calculating the accuracy of the image model to be detected based on the number and the total number of the original image samples;
[0027] The security level of the image model to be detected is determined according to the accuracy rate.
[0028] In a possible implementation manner, before obtaining the original image sample, the method further includes:
[0029] Obtain training samples from a user terminal device that needs to perform model testing;
[0030] Extracting sample features of the training samples;
[0031] The sample features are input into an open source model framework for training to obtain a trained mainstream image classification model.
[0032] In a possible implementation manner, after obtaining the original image sample, the method further includes:
[0033] Perform image enhancement processing on the original image sample.
[0034] The inputting the original image sample into the trained mainstream image classification model comprises:
[0035] The processed original image samples are input into the trained mainstream image classification model.
[0036] A second aspect of the present invention provides an image model detection device, the device comprising:
[0037] A first acquisition module, used for acquiring original image samples;
[0038] An input module, used for inputting the original image samples into a trained mainstream image classification model;
[0039] A generating module, configured to use the mainstream image classification model and a momentum-based gradient iteration algorithm to perform an adversarial attack on the original image sample to obtain an adversarial image;
[0040] A second acquisition module is used to obtain a first recognition result obtained after the image model to be detected recognizes the original image sample, and to obtain a second recognition result obtained after the image model to be detected recognizes the adversarial image;
[0041] A judging module, used to judge whether the first recognition result is consistent with the second recognition result;
[0042] A determination module is used to determine that the recognition of the adversarial image by the image model to be detected is successful if the first recognition result is consistent with the second recognition result.
[0043] A third aspect of the present invention provides an electronic device, comprising a processor and a memory, wherein the processor is configured to implement the image model detection method when executing a computer program stored in the memory.
[0044] A fourth aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, and the computer program implements the image model detection method when executed by a processor.
[0045] According to the above technical scheme, in the present invention, an original image sample can be obtained, and the original image sample can be input into a trained mainstream image classification model. The mainstream image classification model can be used to perform an adversarial attack on the original image sample based on a momentum-based gradient iteration algorithm to obtain an adversarial image. Furthermore, a first recognition result obtained after the image model to be detected recognizes the original image sample can be obtained, and a second recognition result obtained after the image model to be detected recognizes the adversarial image can be obtained, and it can be determined whether the first recognition result is consistent with the second recognition result. If the first recognition result is consistent with the second recognition result, it is determined that the image model to be detected successfully recognizes the adversarial image. It can be seen that in the present invention, an adversarial image can be generated by performing an adversarial attack on the original image sample through a trained mainstream image classification model, and then the image model to be detected can be tested through the adversarial image. In the above manner, the security performance of the image model to be detected can be detected, which is convenient for subsequent improvement of the image model to be detected according to the detection results, and the anti-interference ability of the image model to be detected can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 It is a flow chart of a preferred embodiment of an image model detection method disclosed by the present invention.
[0047] Figure 2 It is a functional module diagram of a preferred embodiment of an image model detection device disclosed in the present invention.
[0048] Figure 3 It is a schematic diagram of the structure of an electronic device of a preferred embodiment of the image model detection method of the present invention. DETAILED DESCRIPTION
[0049] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0050] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used in the specification of the present invention herein are only for the purpose of describing specific embodiments and are not intended to limit the present invention.
[0051] Figure 1 The flowchart of a preferred embodiment of an image model detection method disclosed in the present invention is shown in FIG.
[0052] S11. The electronic device obtains an original image sample.
[0053] If the original image sample is common and universal, the original image sample can be obtained from the network through web crawling technology. If the original image sample is not easy to obtain through public channels, the original image sample can be obtained from the user's terminal device, that is, the original image sample is provided by the user, not locally. The original image sample is a clean sample without any disturbance.
[0054] As an optional implementation, before step S11, the method further includes:
[0055] Obtain training samples from a user terminal device that needs to perform model testing;
[0056] Extracting sample features of the training samples;
[0057] The sample features are input into an open source model framework for training to obtain a trained mainstream image classification model.
[0058] In this optional implementation, the open source model framework is based on mainstream image classification frameworks, such as resnet, inceptionV3, and other model frameworks disclosed in the open source community. During training, it is necessary to obtain training samples from the user-end device in advance, such as face image samples, non-face image samples, etc., further extract sample features of the training samples, such as face features, and input the sample features into the open source model framework for training to obtain image classification results. Finally, the parameters of the open source model framework are continuously updated according to the image classification results until they converge to obtain a trained mainstream image classification model. Subsequently, the trained mainstream image classification model needs to be attacked.
[0059] Among them, the model with known specific structure and parameters (such as the above-mentioned trained mainstream image classification model) can be called a white-box model, and the model with unknown specific structure and parameters can be called a black-box model. Generally, the attack methods of image perturbation are mainly divided into white-box attack and black-box attack.
[0060] The above method can be used to target white-box attacks, that is, attacks on known models, while improving its robustness and transferability, so that the results after the white-box attack can also successfully attack models whose specific structures and parameters are unknown.
[0061] S12: The electronic device inputs the original image sample into a trained mainstream image classification model.
[0062] Among them, after training the mainstream image classification model, it is also necessary to attack the mainstream image classification model, such as white box attack or black box attack.
[0063] As an optional implementation, after step S11, the method further includes:
[0064] Perform image enhancement processing on the original image sample.
[0065] The inputting the original image sample into the trained mainstream image classification model comprises:
[0066] The processed original image samples are input into the trained mainstream image classification model.
[0067] In order to make the subsequent adversarial images better attack the black box model and enhance the perturbation ability of the image to simulate the real attack scenario, the original image samples need to be enhanced. Specifically, before the trained mainstream image classification model is inferred, the original image samples can be randomly resized, and then randomly padded to a size of 331x331, and then resized to the input size of the mainstream image classification model, such as 224x224. Because the original image samples vary in variety, the perturbation can be universal and can adapt to different situations, thereby achieving the purpose of improving the robustness and transferability of the model.
[0068] S13. The electronic device uses the mainstream image classification model and a momentum-based gradient iteration algorithm to perform an adversarial attack on the original image sample to obtain an adversarial image.
[0069] Among them, the white-box model adopts white-box attack, and for white-box attack, a momentum-based gradient iteration algorithm is adopted.
[0070] Specifically, the use of the mainstream image classification model and the momentum-based gradient iteration algorithm to perform an adversarial attack on the original image sample to obtain the adversarial image includes:
[0071] Using the mainstream image classification model, the perturbation amount is calculated based on the momentum-based gradient iteration algorithm;
[0072] Performing convolution smoothing processing on the disturbance amount;
[0073] The processed disturbance amount is added to the original image to obtain an adversarial image.
[0074] The formula of the momentum-based gradient iteration algorithm is as follows:
[0075]
[0076] x′ t+1 = x′ t +∈·clip [-10,10] g t+1
[0077] Among them, g refers to the disturbance amount, g t is the perturbation amount at the tth iteration, μ is the momentum coefficient used to control the noise of the change, J θ (x′ t , y) means x′ t ,y is input to the model function J θ (x, y) and calculate the cross entropy to get l, where l refers to the cross entropy loss value between the output result of the second-to-last fully connected layer of the mainstream image classification model and the category of the original image sample. The solution is to find the change in the gradient direction of each pixel divided by the variance of its perturbation, which is used to calculate the perturbation amount, x′ t+1 It refers to the result of adding the t-th iterative perturbation to the original image sample, ∈ refers to the perturbation coefficient, which is used to control the difference between the perturbed image and the original image sample, clip [-10,10] g t+1 Used to t+1 Clipped to the range [-10,10].
[0078] Among them, in order to make the subsequently obtained adversarial images better attack the black box model and enhance the perturbation ability of the image to simulate the real attack scenario, after the perturbation amount is calculated, it is also necessary to perform convolution smoothing processing on the perturbation amount. Specifically, a randomly generated 4x4 Gaussian convolution kernel is used to perform convolution processing on gt without changing its dimensionality, so that the perturbation is smooth and more transferable.
[0079] Among them, the number of iterations can be tested and set in advance based on multiple experiments. Usually, the number of iterations is between 100 and 200. This will increase the perturbation capacity of the perturbation amount several times compared to traditional attack methods.
[0080] S14. The electronic device obtains a first recognition result obtained after the image model to be detected recognizes the original image sample, and obtains a second recognition result obtained after the image model to be detected recognizes the adversarial image.
[0081] Among them, the image model to be detected is different from the trained mainstream image classification model, and the user may modify the mainstream framework model to obtain the image model to be detected.
[0082] Among them, the first recognition result obtained after the image model to be detected recognizes the original image sample can be obtained locally, and the second recognition result obtained after the image model to be detected recognizes the adversarial image can be obtained locally, or the first recognition result obtained after the image model to be detected recognizes the original image sample can be obtained on the user-end device, and the second recognition result obtained after the image model to be detected recognizes the adversarial image can be obtained on the user-end device.
[0083] Optionally, before step S14, the method further includes:
[0084] Obtaining an image model to be detected that needs to be subjected to model detection from a user terminal device;
[0085] Install the image model to be detected;
[0086] The original image sample and the adversarial image are respectively input into the image model to be detected to obtain a first recognition result of the original image sample and a second recognition result of the adversarial image.
[0087] In this optional implementation, it is necessary to obtain the image model to be detected that needs to be model detected from the user-end device, and install the image model to be detected on the electronic device, and then directly input the original image sample and the adversarial image into the image model to be detected on the electronic device, respectively, to obtain the first recognition result of the original image sample and the second recognition result of the adversarial image. The entire recognition process is performed on the electronic device, and the user-end device does not need to do any processing, thereby saving resource consumption of the user-end device and saving user time.
[0088] Optionally, after using the mainstream image classification model to perform an adversarial attack on the original image sample based on a momentum-based gradient iteration algorithm to obtain an adversarial image, the method further includes:
[0089] A recognition request carrying the original image sample and the adversarial image is sent to a user-end device, wherein the user-end device is installed with an image model to be detected, and the image model to be detected on the user-end device recognizes the original image sample to obtain a first recognition result, and recognizes the adversarial image to obtain a second recognition result.
[0090] In this optional implementation, it is not necessary to obtain the model to be detected on the user side, that is, it is not necessary to install the model to be detected on the electronic device. It is only necessary for the user side to provide an API interface (Application Programming Interface). The electronic device can send a recognition request carrying the original image sample and the adversarial image to the user-side device through the API interface. After the user-side device receives the recognition request, it can use the image model to be detected to recognize the original image sample and the adversarial image, and obtain a first recognition result for the original image sample and a second recognition result for the adversarial image. Finally, the user-side device can return the first recognition result for the original image sample and the second recognition result for the adversarial image to the electronic device through the API interface. The electronic device can make a judgment based on the first recognition result and the second recognition result.
[0091] The original image samples may come from a public channel, such as the Internet, or from a user-end device.
[0092] In this optional implementation, there is no need to actively obtain details such as the specific model used by the user-end device and the user's innovative technology in applying the model, so that the customer model technology can be kept confidential. At the same time, security issues of the customer model can also be detected, thereby providing guidance on improving the customer model and protecting user safety.
[0093] Among them, the user terminal device is an electronic device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions. Its hardware includes but is not limited to microprocessors, application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), digital signal processors (DSPs), embedded devices, etc., such as personal computers, tablet computers, personal digital assistants, etc.
[0094] Among them, an electronic device is an electronic device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions. Its hardware includes but is not limited to microprocessors, application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), digital signal processors (DSPs), embedded devices, etc., such as personal computers, tablet computers, personal digital assistants, etc.
[0095] S15. The electronic device determines whether the first recognition result is consistent with the second recognition result. If they are consistent, step S16 is executed; if not, the process ends.
[0096] Among them, assuming that the original image sample and the adversarial sample are for the recognition of face pictures, the first recognition result obtained after the image model to be detected recognizes the original image sample is that there is a face in the original image sample, and the second recognition result obtained after the image model to be detected recognizes the adversarial image, because the adversarial image is an image with added disturbance, the second recognition result may be that there is a face in the adversarial image, or that there is no face in the adversarial image.
[0097] S16. The electronic device determines that the recognition of the adversarial image by the image model to be detected is successful.
[0098] Among them, if the first recognition result is consistent with the second recognition result, it indicates that the image model to be detected successfully and correctly recognizes the adversarial image.
[0099] As an optional implementation, the method further includes:
[0100] If the first recognition result is inconsistent with the second recognition result, it is determined that the image model to be detected is misjudged;
[0101] Counting the number of misjudgments of the image model to be detected;
[0102] Calculating the accuracy of the image model to be detected based on the number and the total number of the original image samples;
[0103] The security level of the image model to be detected is determined according to the accuracy rate.
[0104] Among them, if the first recognition result is inconsistent with the second recognition result, it indicates that the image model to be detected has misjudged the adversarial image, and it also means that the perturbation of the original image sample has successfully interfered with the recognition result of the image model to be detected, and it further indicates that the image model to be detected cannot defend against such adversarial images, indicating that the image model to be detected can be easily attacked successfully and has poor security.
[0105] If there are too many misjudgments, it will reflect that the security of the image model to be detected has a big problem. Therefore, it is also necessary to count the number of misjudgments of the image model to be detected, and calculate the accuracy of the image model to be detected based on the number and the total number of the original image samples, wherein the total number of the original image samples is the same as the total number of the adversarial images.
[0106] Different application scenarios have different standards for the image model to be detected, and the security level can be set according to different application scenarios. Different security levels represent the level of security performance of the image model to be detected.
[0107] For example, based on 1,000 or more tested images, if the accuracy of the image model to be detected drops by 10% in the perturbed images, the image model to be detected has a minor security issue; if the accuracy of the image model to be detected drops by 20% in the perturbed images, the image model to be detected has a moderate security issue; if the accuracy of the image model to be detected drops by 30% or more in the perturbed images, the image model to be detected has a serious security issue.
[0108] exist Figure 1 In the described method flow, an original image sample can be obtained, and the original image sample can be input into a trained mainstream image classification model. The mainstream image classification model is used to perform an adversarial attack on the original image sample based on a momentum-based gradient iteration algorithm to obtain an adversarial image. Further, a first recognition result obtained after the image model to be detected recognizes the original image sample can be obtained, and a second recognition result obtained after the image model to be detected recognizes the adversarial image can be obtained, and it is determined whether the first recognition result is consistent with the second recognition result. If the first recognition result is consistent with the second recognition result, it is determined that the image model to be detected successfully recognizes the adversarial image. It can be seen that in the present invention, an adversarial image can be generated by performing an adversarial attack on the original image sample through a trained mainstream image classification model, and then the image model to be detected can be tested through the adversarial image. In the above manner, the security performance of the image model to be detected can be detected, which is convenient for subsequent improvement of the image model to be detected according to the detection results, and the anti-interference ability of the image model to be detected can be improved.
[0109] The above is only a specific implementation of the present invention, but the protection scope of the present invention is not limited thereto. For ordinary technicians in this field, improvements can be made without departing from the creative concept of the present invention, but these all belong to the protection scope of the present invention.
[0110] Figure 2 It is a functional module diagram of a preferred embodiment of an image model detection device disclosed in the present invention.
[0111] In some embodiments, the image model detection device is run in an electronic device. The image model detection device may include a plurality of functional modules composed of program code segments. The program code of each program segment in the image model detection device may be stored in a memory and executed by at least one processor to perform Figure 1 Some or all of the steps in the described image model detection method.
[0112] In this embodiment, the image model detection device can be divided into multiple functional modules according to the functions it performs. The functional modules may include: a first acquisition module 201, an input module 202, a generation module 203, a second acquisition module 204, a judgment module 205 and a determination module 206. The module referred to in the present invention refers to a series of computer program segments that can be executed by at least one processor and can complete fixed functions, which are stored in a memory. The functions of each module will be described in detail in subsequent embodiments.
[0113] The first acquisition module 201 is used to acquire original image samples.
[0114] If the original image sample is common and universal, the original image sample can be obtained from the network through web crawling technology. If the original image sample is not easy to obtain through public channels, the original image sample can be obtained from the user's terminal device, that is, the original image sample is provided by the user, not locally. The original image sample is a clean sample without any disturbance.
[0115] The input module 202 is used to input the original image sample into the trained mainstream image classification model.
[0116] Among them, after training the mainstream image classification model, it is also necessary to attack the mainstream image classification model, such as white box attack or black box attack.
[0117] The generation module 203 is used to use the mainstream image classification model and the momentum-based gradient iteration algorithm to perform an adversarial attack on the original image sample to obtain an adversarial image.
[0118] Among them, the white-box model adopts white-box attack, and for white-box attack, a momentum-based gradient iteration algorithm is adopted.
[0119] Specifically, the use of the mainstream image classification model and the momentum-based gradient iteration algorithm to perform an adversarial attack on the original image sample to obtain the adversarial image includes:
[0120] Using the mainstream image classification model, the perturbation amount is calculated based on the momentum-based gradient iteration algorithm;
[0121] Performing convolution smoothing processing on the disturbance amount;
[0122] The processed disturbance amount is added to the original image to obtain an adversarial image.
[0123] The formula of the momentum-based gradient iteration algorithm is as follows:
[0124]
[0125] x′ t+1 = x′ t +∈·clip [-10,10] g t+1
[0126] Among them, g refers to the disturbance amount, g t is the perturbation amount at the tth iteration, μ is the momentum coefficient used to control the noise of the change, J θ (x′ t , y) means x′ t ,y is input to the model function J θ (x, y) and calculate the cross entropy to get l, where l refers to the cross entropy loss value between the output result of the second-to-last fully connected layer of the mainstream image classification model and the category of the original image sample. The solution is to find the change in the gradient direction of each pixel divided by the variance of its perturbation, which is used to calculate the perturbation amount, x′ t+1 It refers to the result of adding the t-th iterative perturbation to the original image sample, ∈ refers to the perturbation coefficient, which is used to control the difference between the perturbed image and the original image sample, clip [-10,10] g t+1 Used to t+1 Clipped to the range [-10,10].
[0127] In order to make the subsequent adversarial images better attack the black box model and enhance the perturbation ability of the image to simulate the real attack scenario, after the perturbation amount is calculated, it is also necessary to perform convolution smoothing on the perturbation amount. Specifically, a randomly generated 4x4 Gaussian convolution kernel is used to smooth the g t Performing convolution without changing its dimensionality makes the perturbation smooth and thus more transferable.
[0128] Among them, the number of iterations can be tested and set in advance based on multiple experiments. Usually, the number of iterations is between 100 and 200. This will increase the perturbation capacity of the perturbation amount several times compared to traditional attack methods.
[0129] The second acquisition module 204 is used to obtain a first recognition result obtained after the image model to be detected recognizes the original image sample, and to obtain a second recognition result obtained after the image model to be detected recognizes the adversarial image.
[0130] Among them, the image model to be detected is different from the trained mainstream image classification model, and the user may modify the mainstream framework model to obtain the image model to be detected.
[0131] Among them, the first recognition result obtained after the image model to be detected recognizes the original image sample can be obtained locally, and the second recognition result obtained after the image model to be detected recognizes the adversarial image can be obtained locally, or the first recognition result obtained after the image model to be detected recognizes the original image sample can be obtained on the user-end device, and the second recognition result obtained after the image model to be detected recognizes the adversarial image can be obtained on the user-end device.
[0132] The judgment module 205 is used to judge whether the first recognition result is consistent with the second recognition result.
[0133] Among them, assuming that the original image sample and the adversarial sample are for the recognition of face pictures, the first recognition result obtained after the image model to be detected recognizes the original image sample is that there is a face in the original image sample, and the second recognition result obtained after the image model to be detected recognizes the adversarial image, because the adversarial image is an image with added disturbance, the second recognition result may be that there is a face in the adversarial image, or that there is no face in the adversarial image.
[0134] The determination module 206 is used to determine that the recognition of the adversarial image by the image model to be detected is successful if the first recognition result is consistent with the second recognition result.
[0135] Among them, if the first recognition result is consistent with the second recognition result, it indicates that the image model to be detected successfully and correctly recognizes the adversarial image.
[0136] exist Figure 2In the described image model detection device, an original image sample can be obtained, and the original image sample can be input into a trained mainstream image classification model. The mainstream image classification model can be used to perform an adversarial attack on the original image sample based on a momentum-based gradient iteration algorithm to obtain an adversarial image. Furthermore, a first recognition result obtained after the image model to be detected recognizes the original image sample can be obtained, and a second recognition result obtained after the image model to be detected recognizes the adversarial image can be obtained, and it can be determined whether the first recognition result is consistent with the second recognition result. If the first recognition result is consistent with the second recognition result, it is determined that the image model to be detected successfully recognizes the adversarial image. It can be seen that in the present invention, an adversarial image can be generated by performing an adversarial attack on the original image sample through a trained mainstream image classification model, and then the image model to be detected can be tested through the adversarial image. In the above manner, the security performance of the image model to be detected can be detected, so that the image model to be detected can be improved according to the detection results, thereby improving the anti-interference ability of the image model to be detected.
[0137] Figure 3 The electronic device 3 includes a memory 31, at least one processor 32, a computer program 33 stored in the memory 31 and executable on the at least one processor 32, and at least one communication bus 34.
[0138] Those skilled in the art will understand that Figure 3 The schematic diagram shown is merely an example of the electronic device 3 and does not constitute a limitation on the electronic device 3. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the electronic device 3 may also include input and output devices, network access devices, etc.
[0139] The at least one processor 32 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The processor 32 may be a microprocessor or any conventional processor, etc. The processor 32 is the control center of the electronic device 3, and uses various interfaces and lines to connect various parts of the entire electronic device 3.
[0140] The memory 31 can be used to store the computer program 33 and / or modules / units. The processor 32 implements various functions of the electronic device 3 by running or executing the computer program and / or modules / units stored in the memory 31 and calling the data stored in the memory 31. The memory 31 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data (such as audio data) created according to the use of the electronic device 3, etc. In addition, the memory 31 can include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other non-volatile solid-state storage devices.
[0141] Combination Figure 1 , the memory 31 in the electronic device 3 stores a plurality of instructions to implement an image model detection method, and the processor 32 can execute the plurality of instructions to implement:
[0142] Get the original image sample;
[0143] Inputting the original image sample into a trained mainstream image classification model;
[0144] Using the mainstream image classification model and the momentum-based gradient iteration algorithm, an adversarial attack is performed on the original image sample to obtain an adversarial image;
[0145] Obtaining a first recognition result obtained after the image model to be detected recognizes the original image sample, and obtaining a second recognition result obtained after the image model to be detected recognizes the adversarial image;
[0146] Determining whether the first recognition result is consistent with the second recognition result;
[0147] If the first recognition result is consistent with the second recognition result, it is determined that the recognition of the adversarial image by the image model to be detected is successful.
[0148] Specifically, the specific implementation method of the processor 32 for the above instructions can refer to Figure 1 The description of the relevant steps in the corresponding embodiments will not be repeated here.
[0149] exist Figure 3 In the described electronic device 3, an original image sample can be obtained, and the original image sample can be input into a trained mainstream image classification model. The mainstream image classification model can be used to perform an adversarial attack on the original image sample based on a momentum-based gradient iteration algorithm to obtain an adversarial image. Furthermore, a first recognition result obtained after the image model to be detected recognizes the original image sample can be obtained, and a second recognition result obtained after the image model to be detected recognizes the adversarial image can be obtained, and it can be determined whether the first recognition result is consistent with the second recognition result. If the first recognition result is consistent with the second recognition result, it is determined that the image model to be detected successfully recognizes the adversarial image. It can be seen that in the present invention, an adversarial image can be generated by performing an adversarial attack on the original image sample through a trained mainstream image classification model, and then the image model to be detected can be tested through the adversarial image. In the above manner, the security performance of the image model to be detected can be detected, so that the image model to be detected can be improved according to the detection results, thereby improving the anti-interference ability of the image model to be detected.
[0150] If the module / unit integrated in the electronic device 3 is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the process in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device that can carry the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory and read-only memory (ROM, Read-Only Memory).
[0151] In the several embodiments provided by the present invention, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only illustrative, for example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation.
[0152] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0153] In addition, each functional module in each embodiment of the present invention may be integrated into one processing unit, each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional modules.
[0154] It is obvious to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit or essential features of the present invention. Therefore, from any point of view, the embodiments should be regarded as exemplary and non-restrictive, and the scope of the present invention is defined by the appended claims rather than the above description, and it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention. Any accompanying figure mark in the claims should not be regarded as limiting the claims involved. In addition, it is obvious that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices stated in the system claim may also be implemented by one unit or device through software or hardware. The second and other words are used to indicate names, and do not indicate any particular order.
[0155] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present invention.
Claims
1. An image model detection method, characterized in that: The method comprises: Get the original image sample; Inputting the original image sample into a trained mainstream image classification model; Using the mainstream image classification model and the momentum-based gradient iteration algorithm, the original image sample is subjected to an adversarial attack to obtain an adversarial image, including: using the mainstream image classification model and the momentum-based gradient iteration algorithm to calculate the perturbation amount; performing convolution smoothing processing on the perturbation amount; adding the processed perturbation amount to the original image to obtain the adversarial image; wherein the formula of the momentum-based gradient iteration algorithm is as follows: x′ t+1 =x′ t +∈·clip [-10,10] g t+1 Among them, g refers to the disturbance amount, g t is the perturbation amount at the tth iteration, μ is the momentum coefficient used to control the noise of the change, J θ (x′ t , y) means x′ t ,y is input to the model function J θ (x, y) and calculate the cross entropy to get l, where l refers to the cross entropy loss value between the output result of the second-to-last fully connected layer of the mainstream image classification model and the category of the original image sample. The solution is to find the change in the gradient direction of each pixel divided by the variance of its perturbation, which is used to calculate the perturbation amount, x′ t+1 It refers to the result of adding the t-th iterative perturbation to the original image sample, ∈ refers to the perturbation coefficient, which is used to control the difference between the perturbed image and the original image sample, clip [-10,10] g t+1 Used to t+1 Clip to the range [-10,10]; Obtaining a first recognition result obtained after the image model to be detected recognizes the original image sample, and obtaining a second recognition result obtained after the image model to be detected recognizes the adversarial image; Determining whether the first recognition result is consistent with the second recognition result; If the first recognition result is consistent with the second recognition result, it is determined that the recognition of the adversarial image by the image model to be detected is successful.
2. The method according to claim 1, characterized in that Before obtaining the first recognition result obtained after the image model to be detected recognizes the original image sample, and obtaining the second recognition result obtained after the image model to be detected recognizes the adversarial image, the method further includes: Obtaining an image model to be detected that needs to be subjected to model detection from a user terminal device; Install the image model to be detected; The original image sample and the adversarial image are respectively input into the image model to be detected.
3. The method according to claim 1, characterized in that After using the mainstream image classification model and the momentum-based gradient iteration algorithm to perform an adversarial attack on the original image sample to obtain the adversarial image, the method further includes: A recognition request carrying the original image sample and the adversarial image is sent to a user-end device, wherein the user-end device is installed with an image model to be detected, and the image model to be detected on the user-end device recognizes the original image sample to obtain a first recognition result, and recognizes the adversarial image to obtain a second recognition result.
4. The method according to any one of claims 1 to 3, characterized in that The method further comprises: If the first recognition result is inconsistent with the second recognition result, it is determined that the image model to be detected is misjudged; Counting the number of misjudgments of the image model to be detected; Calculating the accuracy of the image model to be detected based on the number and the total number of the original image samples; The security level of the image model to be detected is determined according to the accuracy rate.
5. The method according to any one of claims 1 to 3, characterized in that Before obtaining the original image sample, the method further includes: Obtain training samples from a user terminal device that needs to perform model testing; Extracting sample features of the training samples; The sample features are input into an open source model framework for training to obtain a trained mainstream image classification model.
6. The method according to any one of claims 1 to 3, characterized in that After obtaining the original image sample, the method further includes: Performing image enhancement processing on the original image sample; The original image sample after image enhancement processing is input into the trained mainstream image classification model.
7. An image model detection device for implementing the image model detection method according to claim 1, characterized in that: The device comprises: A first acquisition module, used for acquiring original image samples; An input module, used for inputting the original image samples into a trained mainstream image classification model; A generating module, configured to use the mainstream image classification model and a momentum-based gradient iteration algorithm to perform an adversarial attack on the original image sample to obtain an adversarial image; A second acquisition module is used to obtain a first recognition result obtained after the image model to be detected recognizes the original image sample, and to obtain a second recognition result obtained after the image model to be detected recognizes the adversarial image; A judging module, used to judge whether the first recognition result is consistent with the second recognition result; A determination module is used to determine that the recognition of the adversarial image by the image model to be detected is successful if the first recognition result is consistent with the second recognition result.
8. An electronic device, characterized in that: The electronic device comprises a processor and a memory, wherein the processor is configured to execute a computer program stored in the memory to implement the image model detection method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores at least one instruction, and when the at least one instruction is executed by a processor, the image model detection method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Image significance detection method based on confrontation network
CN106296692A
Image recognition attack method based on algorithm confrontational attack
CN109492582A
