Training method and image detection method, device, electronic device, and storage medium

Through the joint training method of generative adversarial networks, the image generation and discrimination models are optimized, the difficult problem of false image recognition is solved, and efficient detection and recognition of false images is achieved.

CN116152593BActive Publication Date: 2025-09-19MASHANG CONSUMER FINANCE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211551262.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-05
Publication Date
2025-09-19
Estimated Expiration
2042-12-05

AI Technical Summary

Technical Problem

Existing technologies make it difficult to effectively identify and detect false images of certificates, contracts, business licenses, etc., which adversely affects social life and production activities.

Method used

A generative adversarial network training method is adopted to jointly train the image generation model and the image discrimination model to optimize the parameters of the target image generation model and the discrimination model, thereby improving the robustness of the image generation model and the recognition accuracy of the image discrimination model.

Benefits of technology

It improves the detection and recognition of false images, enhances the discrimination accuracy of the image discrimination model and the authenticity of the image generation model, and promotes the rapid convergence of image recognition.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116152593B_ABST
    Figure CN116152593B_ABST
Patent Text Reader

Abstract

The present disclosure provides a training method and an image detection method, device, electronic device, and storage medium, including: inputting a first false image sample and a random noise image into an image generation model to obtain a second false image sample; performing model training on the image generation model based on a first loss error between the second false image sample and the first false image sample to obtain a target image generation model; inputting a real image sample into the target image generation model to obtain a third false image sample; inputting the real image sample and the third false image sample into an image discrimination model in sequence to perform image discrimination to obtain corresponding true and false discrimination results; performing model training on the image discrimination model based on a second loss error between the true and false discrimination results and sample labels; during the model training of the image discrimination model, updating the model parameters of the target image generation model based on the third loss error between the true and false discrimination results of the third false image sample and the corresponding sample labels.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer vision technology, and in particular to a training method for a generative adversarial network, an image detection method, a training device, an image detection device, an electronic device, and a computer-readable storage medium. Background Art

[0002] In recent years, with the development of image processing and editing technologies, fake images of certificates, contracts, business licenses, and other documents have become rampant, adversely impacting social life and production activities. These images are often created using Photoshop (Photoshop).

[0003] Therefore, how to detect and identify false images is a technical problem that needs to be solved urgently. Summary of the Invention

[0004] The present disclosure provides a training method for a generative adversarial network, an image detection method, a training device, an image detection device, an electronic device, and a computer-readable storage medium, which can be used to detect and identify false images.

[0005] In a first aspect, the disclosure provides a training method for a generative adversarial network, wherein the generative adversarial network includes an image generation model and an image discrimination model. The training method for the generative adversarial network includes:

[0006] Obtaining a first false image sample and a corresponding random noise image corresponding to the real image sample;

[0007] Inputting the first false image sample and the random noise image into the image generation model to generate a first image, thereby obtaining a second false image sample;

[0008] Performing model training on the image generation model according to a first loss error between the second false image sample and the first false image sample to obtain a target image generation model;

[0009] Inputting the real image sample into the target image generation model to generate a second image to obtain a third false image sample;

[0010] The real image sample and the third false image sample are respectively used as training image samples, and are sequentially input into the image discrimination model for image discrimination, to obtain a true or false discrimination result corresponding to each training image sample;

[0011] The image discrimination model is trained based on a second loss error between a true or false discrimination result corresponding to the training image sample and a sample label corresponding to the training image sample to obtain a target image discrimination model; wherein, when the training image sample is a real image sample, the sample label corresponding to the training image sample is a real image sample label, and when the training image sample is a third false image sample, the sample label corresponding to the training image sample is a false image sample label;

[0012] During model training of the image discrimination model, the model parameters of the target image generation model are updated based on the third loss error between the true and false discrimination result corresponding to the third false image sample as the training image sample and the sample label corresponding to the third false image sample.

[0013] It can be seen that in the embodiment of the present disclosure, after the image generation model is trained using the first false image to obtain the target image generation model, the image discrimination model is trained using the real image samples and the false image samples generated by the target image generation model to obtain the target image discrimination model. At the same time, during the training of the image discrimination model, the model parameters of the target image generation model are fine-tuned using the discrimination results of the false image samples by the image discrimination model. By separately training the image generation model and the image discrimination model in the generative adversarial network, and fine-tuning the parameters of the target image generation model during the training of the image discrimination model, the performance of the target image generation model is further optimized, which is conducive to the generation of a robust target image generation model, improves the robustness of the target image generation model, makes the false image samples generated by the target image generation model closer to the real image samples, improves the authenticity of the images generated by the target image generation model, and thus makes the true and false discrimination results of the false image samples generated by the target image generation model by the image discrimination model closer to the true and false discrimination results of the real image samples, thereby improving the image recognition effect of the image discrimination model. In addition, since fine-tuning the parameters of the target image generation model during the training process of the image discrimination model can effectively improve the authenticity of the images generated by the target image generation model, thereby improving the image recognition effect of the image discrimination model, it is beneficial to accelerate the convergence of the loss of the image discrimination model.

[0014] In a second aspect, an embodiment of the present disclosure provides an image detection method, the image detection method comprising:

[0015] Obtain the image to be detected;

[0016] Inputting the image to be detected into a preset target image discrimination model to obtain an image discrimination result, wherein the image discrimination result is used to evaluate whether the image to be detected is a real image;

[0017] The target image discrimination model is trained according to the above-mentioned generative adversarial network training method.

[0018] It can be seen that in the embodiment of the present disclosure, since the target image discrimination model is obtained by training using the above-mentioned training method, the image recognition effect of the target image discrimination model can be effectively improved. Therefore, by performing image discrimination on the image to be detected through the target image discrimination model, the discrimination accuracy of the image to be detected can be effectively improved.

[0019] In a third aspect, an embodiment of the present disclosure provides a training device for a generative adversarial network, wherein the generative adversarial network includes an image generation model and an image discrimination model, and the training device includes:

[0020] A first acquiring unit, configured to acquire a first false image sample and a corresponding random noise image corresponding to the real image sample;

[0021] A first training unit is configured to: input the first false image sample and the random noise image into the image generation model to perform first image generation to obtain a second false image sample; and perform model training on the image generation model based on a first loss error between the second false image sample and the first false image sample to obtain a target image generation model;

[0022] The first acquisition unit is further configured to input the real image sample into the target image generation model to generate a second image, thereby obtaining a third false image sample;

[0023] The second training unit is configured to: use the real image sample and the third false image sample as training image samples, respectively, and input them into the image discrimination model in sequence for image discrimination to obtain a true or false discrimination result corresponding to each training image sample; perform model training on the image discrimination model based on a second loss error between the true or false discrimination result corresponding to the training image sample and the sample label corresponding to the training image sample to obtain a target image discrimination model; wherein, when the training image sample is a real image sample, the sample label corresponding to the training image sample is a real image sample label, and when the training image sample is a third false image sample, the sample label corresponding to the training image sample is a false image sample label;

[0024] A fine-tuning unit is used to update the model parameters of the target image generation model according to a third loss error between the true and false discrimination result corresponding to the third false image sample as the training image sample and the sample label corresponding to the third false image sample during the process of model training of the image discrimination model.

[0025] In a fourth aspect, an embodiment of the present disclosure provides an image detection device, comprising:

[0026] A second acquisition unit, configured to acquire an image to be detected;

[0027] A prediction unit, configured to input the image to be detected into a preset target image discrimination model to obtain an image discrimination result, wherein the image discrimination result is used to evaluate whether the image to be detected is a real image;

[0028] The target image discrimination model is trained according to the above-mentioned generative adversarial network training method.

[0029] In a fifth aspect, the present disclosure provides an electronic device comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores one or more computer programs executable by the at least one processor, and one or more of the computer programs are executed by the at least one processor so that the at least one processor can execute the training method or image detection method described in any of the above aspects.

[0030] In a sixth aspect, the present disclosure provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the training method or image detection method described in any of the above aspects.

[0031] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present disclosure, nor are they intended to limit the scope of the present disclosure. Other features of the present disclosure will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] The accompanying drawings are used to provide a further understanding of the present disclosure and constitute a part of the specification. Together with the embodiments of the present disclosure, they are used to explain the present disclosure and do not constitute a limitation of the present disclosure. The above and other features and advantages will become more apparent to those skilled in the art by describing detailed example embodiments with reference to the accompanying drawings. In the accompanying drawings:

[0033] Figure 1 A flowchart of a method for training an image generation model provided in an embodiment of the present disclosure;

[0034] Figure 2 A flowchart of a method for obtaining a first false image sample corresponding to a real image sample;

[0035] Figure 3 A flowchart of a method for generating a second false image sample for an image generation model;

[0036] Figure 4 A schematic diagram of the model structure of an image generation model;

[0037] Figure 5 for Figure 1 A flowchart of a specific implementation of step S13;

[0038] Figure 6 A flowchart of a method for obtaining true and false discrimination results of training image samples;

[0039] Figure 7 for Figure 1 A flowchart of a specific implementation of step S16;

[0040] Figure 8 A schematic diagram of a flow chart of an image detection method provided in an embodiment of the present disclosure;

[0041] Figure 9 A block diagram of a training device for a generative adversarial network provided in an embodiment of the present disclosure;

[0042] Figure 10 A block diagram of an image detection device provided in an embodiment of the present disclosure;

[0043] Figure 11 A block diagram of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0044] To enable those skilled in the art to better understand the technical solutions of the present disclosure, exemplary embodiments of the present disclosure are described below in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding. These details should be considered merely exemplary. Therefore, those skilled in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0045] In the absence of conflict, the various embodiments of the present disclosure and the various features therein may be combined with each other.

[0046] As used herein, the term "and / or" includes any and all combinations of one or more of the associated listed items.

[0047] The terms used herein are only used to describe specific embodiments and are not intended to limit the present disclosure. As used herein, the singular forms "a" and "the" are also intended to include the plural forms, unless the context clearly indicates otherwise. It will also be understood that when the terms "comprising" and / or "made of" are used in this specification, the presence of the features, wholes, steps, operations, elements and / or components is specified, but the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or groups thereof is not excluded. Similar words such as "connected" or "connected" are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect.

[0048] Unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art. It will also be understood that terms such as those defined in commonly used dictionaries should be interpreted as having a meaning consistent with their meaning in the context of the relevant art and the present disclosure, and will not be interpreted as having an idealized or overly formal meaning unless expressly defined as such herein.

[0049] The embodiments of the present disclosure provide a method for training an image generation model, which can be used to train a target image generation model. The false images generated by the target image generation model can be used to assist in training an image discrimination model, thereby obtaining a target image discrimination model. The target image discrimination model can be used to detect images and realize the recognition of false images.

[0050] The embodiments of the present disclosure provide a method for training an image discrimination model, which can be used to train a target image discrimination model. The target image discrimination model can be used to detect and identify false images.

[0051] The disclosed embodiments provide a method for training a generative adversarial network, which includes an image generation model and an image discrimination model. The training method can be used to train a target image generation model and a target image discrimination model. The target image discrimination model can be used to detect images and recognize false images.

[0052] The embodiment of the present disclosure provides an image detection method, which uses the above-mentioned training method to train a target image discrimination model to detect images, thereby realizing the detection and identification of false images.

[0053] Any training method or image detection method of the embodiments of the present disclosure can be performed by an electronic device. Wherein, the electronic device can be a terminal device, and the terminal device can be, for example, a vehicle-mounted device, a user equipment (User Equipment, UE), a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (Personal Digital Assistant, PDA), a handheld device, a computing device, a vehicle-mounted device, a wearable device, etc. The electronic device can be a server, and the server can be an independent physical server, a server cluster, or a cloud server capable of cloud computing. The training method or image detection method can be implemented by a processor in an electronic device calling computer-readable program instructions stored in a memory.

[0054] Figure 1 A flow chart of a training method for a generative adversarial network provided in an embodiment of the present disclosure, wherein the generative adversarial network (GAN) includes an image generation model and an image discrimination model, Figure 1 The training method of the generative adversarial network includes: steps S11 to S17.

[0055] Step S11: Obtain a first false image sample and a corresponding random noise image corresponding to the real image sample.

[0056] The real image sample is a genuine image that has not been forged or tampered with in any way, and may be, for example, a genuine ID image, contract image, business license image, facial image, license plate image, etc. In some embodiments, the first false image sample may be a false image obtained by processing the real image sample using an image editing tool such as automatic Photoshop, and the random noise image is a randomly generated noise image corresponding to the real image sample. The image size of the first false image sample and the image size of the random noise image are both consistent with the size of the real image sample.

[0057] It should be noted that in the embodiments of the present disclosure, the acquisition of image sample data involving user personal information is obtained with the user's prior authorization and confirmation, complies with the provisions of relevant laws and regulations, and does not violate public order and good morals.

[0058] In some embodiments, each real image sample can generate a corresponding first false image sample. In some embodiments, each real image sample can generate multiple first false image samples, thereby expanding the model training samples. In some embodiments, each real image sample can generate a corresponding random noise image, with different real image samples corresponding to different random noise images, to enrich the diversity of model training samples.

[0059] Step S12: Input the first false image sample and the random noise image into the image generation model to generate the first image, thereby obtaining a second false image sample.

[0060] The first false image sample and the random noise image are input into an initial image generation model, and the image generation model performs a first image generation process on the first false image sample and the random noise image to obtain a second false image sample. The first image generation process includes performing image feature fusion and sampling on the first false image sample and the random noise image to obtain the second false image sample.

[0061] Step S13: Perform model training on the image generation model according to the first loss error between the second false image sample and the first false image sample to obtain a target image generation model.

[0062] The image generation model is trained using the first loss error between the second false image sample and the first false image sample to update the model parameters of the image generation model until the loss error of the model reaches convergence or the number of training rounds reaches a round threshold, thereby training to obtain the target image generation model.

[0063] The first loss error is calculated based on the feature vector of the second false image sample and the feature vector of the first false image sample by using a preset first loss function. For example, the preset first loss function is a mean squared error (MSE) loss function.

[0064] In the embodiment of the present disclosure, the image generation model is trained based on the loss error between the false image samples generated by the model and the false image samples obtained by PSing the real image samples through the image editing tool, and the false image samples obtained by PSing the real image samples through the image editing tool are used as the optimization target of the false image samples generated by the model, so that the false image samples generated by the image generation model are closer to the real PS effect of the image in real life; in the model training, the false image samples obtained by PSing the real image samples through the image editing tool are input as the supervision signal, that is, the target of the false image samples expected to be output by the model, and the loss error between the false image samples generated by the model and the input false image samples is used to optimize the model through supervised learning, thereby accelerating the convergence of the model to obtain the target image generation model. In the application, the false image samples generated by the target image generation model can be used to assist in the training of the image discrimination model to obtain the target image discrimination model, so as to use the target image discrimination model to realize the detection and recognition of false images.

[0065] Step S14: input the real image sample into the target image generation model to generate a second image, thereby obtaining a third false image sample.

[0066] After the image generation model is trained using the image generation model training method in steps S12 and S13 to obtain a target image generation model, the real image sample is input into the target image generation model for a second image generation process to obtain a third false image sample corresponding to the real image sample. The second image generation process includes performing feature fusion and sampling processing on the input real image sample and noise to obtain the third false image sample.

[0067] Among them, the real image sample used in step S14 and the real image sample used in the training method of the above-mentioned image generation model can be the same real image sample or different real image samples, and the embodiment of the present disclosure does not impose any special restrictions on this.

[0068] Step S15: The real image sample and the third false image sample are respectively used as training image samples, and are sequentially input into the image discrimination model for image discrimination to obtain true and false discrimination results corresponding to the training image samples.

[0069] It can be understood that the training image sample is a real image sample or a third false image sample. In step S15, each training image sample is sequentially input into the image discrimination model for image discrimination processing to obtain a true or false discrimination result corresponding to the training image sample. If the currently input training image sample is a real image sample, the true or false discrimination result corresponding to the real image sample is obtained. If the currently input training image sample is the third false image sample, the true or false discrimination result corresponding to the third false image sample is obtained. The true or false discrimination result is the result of the image discrimination model predicting whether the input training image sample is a real image or a false image, including information characterizing whether the input training image sample is a real image or a false image, which can be used to evaluate whether the input training image sample is a real image.

[0070] Step S16: Perform model training on the image discrimination model based on the second loss error between the true and false discrimination results corresponding to the training image samples and the sample labels corresponding to the training image samples to obtain a target image discrimination model.

[0071] When the training image sample is a real image sample, the sample label corresponding to the training image sample is the real image sample label; when the training image sample is a third false image sample, the sample label corresponding to the training image sample is the false image sample label.

[0072] According to the true and false discrimination results of the training image samples and the sample labels corresponding to the training image samples, the second loss error of the image discrimination model is calculated, and the image discrimination model is trained based on the second loss error to update the model parameters of the image generation model until the loss error of the model reaches convergence or the number of training rounds reaches the round threshold, thereby training the target image discrimination model.

[0073] The second loss error is calculated based on the true and false discrimination results of the training image samples and the sample labels corresponding to the training image samples through a preset second loss function. For example, the second loss error is a cross entropy loss function.

[0074] In the disclosed embodiments, each training image sample has a corresponding sample label. The sample label is pre-labeled information used to characterize whether the training image sample is a real image or a false image. The labeling method may be manual labeling. When the training image sample is a real image sample, the corresponding sample label is information that characterizes the training image sample as a real image; when the training image sample is a third false image sample, the corresponding sample label is information that characterizes the training image sample as a false image. For example, the sample label of the third false image sample can be represented by "0," and the sample label of the real image sample can be represented by "1."

[0075] Step S17: During the model training of the image discrimination model, the model parameters of the target image generation model are updated according to the third loss error between the true and false discrimination result corresponding to the third false image sample as the training image sample and the sample label corresponding to the third false image sample.

[0076] Among them, the third loss error is calculated based on the true and false discrimination result corresponding to the third false image sample and the sample label corresponding to the third false image sample through a preset third loss function. For example, the preset third loss function is a logarithmic loss function.

[0077] When the input training image sample is a third false image sample, during the model training process of the image discrimination model, the third loss error is calculated based on the true and false discrimination result of the third false image sample and the sample label corresponding to the third false image sample, and the model parameters of the target image generation model are fine-tuned and updated based on the third loss error.

[0078] In an embodiment of the present disclosure, in the process of using the third false image sample generated by the target image generation model to assist in training the image discrimination model, the model parameters of the target image generation model are further optimized based on the true and false discrimination result of the third false image sample generated by the target image generation model by the image discrimination model and the loss error between the sample labels of the third false image sample, thereby robustifying the generation of the target image generation model, improving the robustness of the target image generation model, making the false image samples generated by the target image generation model closer to the real image samples, and making the true and false discrimination result of the target image discrimination model for the false image samples generated by the target image generation model closer to the true and false discrimination result of the real image samples, thereby improving the image recognition effect of the target image discrimination model.

[0079] According to the technical solution of the training method of the generative adversarial network provided by the embodiment of the present disclosure, after the image generation model is trained using the first false image to obtain the target image generation model, the image discrimination model is trained using the real image samples and the false image samples generated by the target image generation model to obtain the target image discrimination model. At the same time, in the process of training the image discrimination model, the model parameters of the target image generation model are fine-tuned using the discrimination results of the false image samples by the image discrimination model. By training the image generation model and the image discrimination model in the generative adversarial network separately, and fine-tuning the parameters of the target image generation model during the training of the image discrimination model, the performance of the target image generation model is further optimized, which is conducive to the generation of a robust target image generation model, improving the robustness of the target image generation model, making the false image samples generated by the target image generation model closer to the real image samples, and improving the authenticity of the images generated by the target image generation model. As a result, the true and false discrimination results of the image discrimination model for the false image samples generated by the target image generation model are closer to the true and false discrimination results for the real image samples, thereby improving the image recognition effect of the image discrimination model, that is, it is conducive to improving the recognition accuracy of the image discrimination model. In addition, since fine-tuning the parameters of the target image generation model during the training of the image discrimination model can effectively improve the authenticity of the images generated by the target image generation model, thereby improving the image recognition effect of the image discrimination model, it is conducive to accelerating the convergence of the loss of the image discrimination model.

[0080] Figure 2 FIG. 1 is a flow chart of a method for obtaining a first false image sample corresponding to a real image sample. In some embodiments, an image editing tool such as automatic PS can be used to automatically obtain the first false image sample corresponding to the real image sample. Figure 2 In the above step S11, obtaining a first false image sample corresponding to the real image sample may further include:

[0081] Step S111: Detect target content areas on real image samples.

[0082] In some embodiments, the real image sample has text content, and the target content area is the area containing the text content. In step S111, text content detection is performed on the real image sample by calling a text detection program interface, so as to use a text detection frame to identify the area containing the text content in the real image sample. The area corresponding to the text detection frame is the target content area. The text detection program interface can be, for example, an OCR (Optical Character Recognition) program interface.

[0083] Step S112: Generate a corresponding mask according to the position coordinates of the target content area.

[0084] In some embodiments, a corresponding mask is generated according to the position coordinates of the target content area detected by the text detection frame, so as to perform mask processing on the target content area by using the mask.

[0085] The mask is a selected image, graphic, or object that is used to block the image to be processed (in whole or in part) to control the image processing area or processing process. In some embodiments, image processing tools such as OpenCV can be used to generate a corresponding mask in the target content area based on the position coordinates of the target content area. OpenCV is a cross-platform computer vision and machine learning software library.

[0086] Step S113: Erasing the target content within the mask, and generating false content in the erased area to obtain a first false image sample corresponding to the real image sample.

[0087] In some embodiments, a preset image content erasing tool can be used to erase the target content (such as text content) in the mask. The preset image content erasing tool may include an Inpaint tool or a Mosaic tool. The Inpaint tool is an image watermark removal tool, and the Mosaic tool is an image processing method.

[0088] After erasing the target content within the erasure mask, false content is generated in the erased area, and the false content is attached to the target content area, thereby generating a first false image sample corresponding to the real image sample. The size of the false content is the same as the size of the target content area.

[0089] Automatic PS processing of the real image sample is achieved through the above-mentioned steps S111 to S113, so that one or more first false image samples corresponding to the real image sample can be automatically generated for training the image generation model.

[0090] Figure 3 A flow chart of a method for generating a second false image sample by an image generation model, in some embodiments, referring to Figure 3 In the above step S12, inputting the first false image sample and the random noise image into the image generation model to generate a first image to obtain a second false image sample may further include:

[0091] Step S121 : performing feature extraction on the first false image sample and the random noise image respectively to obtain a first feature map corresponding to the first false image sample and a second feature map corresponding to the random noise image.

[0092] Step S122: Fusing the first feature map and the second feature map to obtain a fused feature map.

[0093] Step S123: downsample the fused feature map to obtain a downsampled feature map.

[0094] Step S124: upsample the downsampled feature map to obtain an upsampled feature map.

[0095] Step S125: Generate a second false image sample according to the upsampled feature map.

[0096] Figure 4 FIG is a schematic diagram of a model structure of an image generation model. In some embodiments, the image generation model can be constructed based on a convolutional neural network (CNN), such as Figure 4 As shown, the image generation model includes at least: a feature extraction module, a feature fusion module, a feature sampling module and a generation module.

[0097] The feature extraction module is configured to perform feature extraction on the first false image sample and the random noise image, respectively, to obtain a first feature map corresponding to the first false image sample and a second feature map corresponding to the random noise image. That is, in step S121, the first false image sample and the random noise image are input into the feature extraction module for feature extraction, thereby extracting a first feature map corresponding to the first false image sample and a second feature map corresponding to the random noise image, respectively. The feature extraction module may be composed of a convolutional layer.

[0098] The feature fusion module is configured to perform feature fusion processing on the first feature map corresponding to the first false image sample and the second feature map corresponding to the random noise image to obtain a fused feature map. That is, in step S122 above, the first feature map and the second feature map are input into the feature fusion module for feature fusion processing to obtain a fused feature map. For example, if the resolution of the first feature map and the second feature map are both 112*112*26, the first feature map and the second feature map are fused according to the image channel to obtain a fused feature map with a resolution of 112*112*52. The feature fusion module can be composed of convolutional layers.

[0099] The feature sampling module may include an upsampling module and a downsampling module. The downsampling module is used to downsample the fused feature map to obtain a downsampled feature map. That is, in the above step S123, the fused feature map is input into the downsampling module for downsampling to obtain a downsampled feature map. Exemplarily, the resolution of the fused feature map is 112*112*52. After downsampling, a downsampled feature map with a resolution of 28*28*208 is obtained. The downsampling module may be composed of two network blocks, each of which may include a convolutional layer and a pooling layer. The convolutional layer is used to extract features, and the pooling layer is used to downsample the feature map.

[0100] The upsampling module is used to upsample the downsampled feature map to obtain an upsampled feature map. That is, in the above step S124, the downsampled feature map is input into the upsampling module for upsampling processing to obtain an upsampled feature map. Exemplarily, the resolution of the downsampled feature map is 28*28*208. After upsampling processing, an upsampled feature map with a resolution of 224*224*3 is obtained. The upsampling module can be composed of two network blocks, each of which includes a deconvolution layer.

[0101] In some embodiments, the feature sampling module may be implemented by sampling a feature pyramid, that is, performing the downsampling and upsampling through a feature pyramid.

[0102] The generation module is used to generate a second false image sample based on the upsampled feature map, that is, in step S125, the upsampled feature map is input into the generation module to generate the second false image sample. The generation module can be composed of a fully connected layer.

[0103] In some embodiments, as Figure 4 As shown, the image generation model is a dual-channel image generation model with two input channels. The first false image sample is input through the first input channel, and the random noise image is input through the second input channel. The first false image sample and the random noise image can be simultaneously input into the image generation model through the first input channel and the second input channel for processing.

[0104] In some embodiments, as Figure 4 As shown, the above-mentioned feature extraction module can further include a first feature extraction module corresponding to the first input channel, and a second feature extraction module corresponding to the second input channel, wherein the first feature extraction module is used to perform feature extraction on the first false image sample to obtain a first feature map, and the second feature extraction module is used to perform feature extraction on the random noise image to obtain a second feature map.

[0105] It should be noted that the embodiments of the present disclosure do not impose any special restrictions on the network structure of the image generation model, and an image generation model for generating images can be constructed based on a convolutional neural network.

[0106] Figure 5 for Figure 1 A flow chart of a specific implementation of step S13 in FIG. 1 is shown in FIG. 1 . In some embodiments, as shown in FIG. 1 , Figure 5 As shown, in step S13, according to the first loss error between the second false image sample and the first false image sample, the image generation model is trained to obtain the target image generation model, which may further include:

[0107] Step S131: Based on a preset first loss function, obtain a first loss error between the second false image sample and the first false image sample.

[0108] The first loss function may be a mean square error loss function, and the first loss function includes:

[0109]

[0110] Where n represents the number of the first false image samples in the current batch, y i Represents the feature vector corresponding to the first false image sample of i, y′ i represents the feature vector corresponding to the i-th second false image sample, and L1 represents the first loss error.

[0111] Step S132: Based on the first loss error, update the model parameters of the image generation model using a gradient descent algorithm.

[0112] Based on the first loss error, back propagation is performed using a gradient descent algorithm to update model parameters of the image generation model. The gradient descent algorithm may include a stochastic gradient descent (SGD) algorithm.

[0113] Step S133: When the first loss error reaches convergence or the number of training rounds reaches the round threshold, the target image generation model is trained.

[0114] During the training process, when the first loss error reaches convergence or the number of training rounds reaches the round threshold, the model parameters that are optimal for the output results of the corresponding model in the iterative training process are determined to obtain the target image generation model.

[0115] Figure 6 A flowchart of a method for obtaining true and false discrimination results of training image samples is shown in FIG. Figure 6 In step S15, obtaining the true and false discrimination result of the training image sample may further include:

[0116] Step S151: Divide the third feature map corresponding to the training image sample into blocks to obtain multiple first feature blocks.

[0117] After feature extraction is performed on the training image sample to obtain the third feature map, the third feature map is subjected to feature map blocking processing to obtain k*k first feature patches, where k is an integer greater than 1. For example, assuming that the feature map size of the training image sample is 224*224, the feature map of the training image sample is divided into 7*7 feature patches.

[0118] In actual scenarios, PS traces of an image often only exist in a few parts of the image. By dividing the image feature map into blocks, it is easy to accurately locate the position of PS in the image, thereby facilitating the identification of false images.

[0119] Step S152: Randomly crop the first feature block to obtain a corresponding second feature block.

[0120] For example, assuming that the feature map size of the training image sample is 224*224, the feature map of the training image sample is divided into 7*7 feature blocks (patches). In step S222, each first feature block is randomly cropped to normalize the size of each first feature block to 28*28, thereby obtaining a second feature block with a corresponding size of 28*28.

[0121] Step S153: Combine the multiple second feature blocks to obtain a fourth feature map.

[0122] In some embodiments, before splicing and combining multiple second feature blocks, multiple convolution kernels are used to perform convolution processing on the multiple second feature blocks, where each convolution kernel processes one second feature block, and then the multiple second feature blocks after convolution processing are spliced ​​according to channels to obtain a fourth feature map.

[0123] For example, assuming that after processing the above steps S221 and S222, 7*7 second feature blocks of size 28*28 are obtained, then 7*7 convolution kernels are used to perform convolution processing on the 7*7 second feature blocks respectively, and the 7*7 second feature blocks after convolution processing are spliced ​​and combined according to channels to obtain a fourth feature map of size 196*196.

[0124] Step S154: Obtain the true or false discrimination score corresponding to the training image sample according to the fourth feature map and the preset attention score matrix.

[0125] In some embodiments, the step of obtaining a true / false discrimination score corresponding to a training image sample based on the fourth feature map and a preset attention score matrix includes: obtaining a convolution processing result of the fourth feature map and the preset attention score matrix; and performing a convolution processing operation on the convolution processing result using weight parameters of an output layer of an image discrimination model to obtain a true / false discrimination score corresponding to the training image sample. Specifically, the fourth feature map is convolved with the preset attention score matrix to obtain a corresponding convolution processing result, and the weight parameters of the output layer of the image discrimination model are further convolved with the convolution processing result to obtain a true / false discrimination score corresponding to the training image sample.

[0126] In some embodiments, based on a preset true-false discrimination score formula, the true-false discrimination score corresponding to the training image sample is obtained according to the fourth feature map and a preset attention score matrix.

[0127] Among them, the true and false discrimination score formula includes: p=w*{a(fn;)*fn}, wherein fn represents the fourth feature map, a(·) represents the attention score matrix, the size of the attention score matrix is ​​the same as the size of the fourth feature map, for example, the size of the fourth feature map is 196*196, then the size of the attention score matrix is ​​196*196, represents the matrix parameters to be learned of the attention score matrix, w represents the weight parameter of the output layer of the image discrimination model, a(fn;)*fn represents the convolution processing result of the fourth feature map and the preset attention score matrix, w*{a(fn;)*fn} represents the further convolution processing result of the weight parameter of the output layer of the image discrimination model and the convolution processing result, p represents the true and false discrimination score, and the true and false discrimination score can represent the probability that the predicted training image sample is a real image.

[0128] Specifically, in the last layer of the image discrimination model, i.e., the output layer, the fourth feature map is processed using the true and false discrimination score formula to obtain the true and false discrimination score corresponding to the training image sample.

[0129] Step S155: Obtain the true or false discrimination result of the training image sample according to the true or false discrimination score corresponding to the training image sample.

[0130] In some embodiments, a discrimination threshold can be set. In step S155, when the true and false discrimination score corresponding to the training image sample is greater than or equal to the discrimination threshold, the true and false discrimination result of the training image sample is a result that characterizes the training image sample as a real image; when the true and false discrimination score corresponding to the training image sample is less than the discrimination threshold, the true and false discrimination result of the training image sample is a result that characterizes the training image sample as a false image.

[0131] In some embodiments, the output layer of the image discrimination model is a fully connected layer, which implements binary classification output of the image samples input to the model, that is, the true and false discrimination result output is a result that represents the input image sample as a real image, or a result that represents the input image sample as a false image.

[0132] In some embodiments, the image discrimination model can be built based on the residual neural network ResNet50 model architecture.

[0133] Figure 7 for Figure 1 A flow chart of a specific implementation of step S16 in FIG. 1 is shown in FIG. 1 . In some embodiments, as shown in FIG. 1 , Figure 7 As shown, in step S16, the image discrimination model is trained according to the second loss error between the true and false discrimination result corresponding to the training image sample and the sample label corresponding to the training image sample to obtain the target image discrimination model, which may further include:

[0134] Step S161: Based on a preset second loss function, a second loss error is obtained according to the true and false discrimination results of the training image samples and the sample labels corresponding to the training image samples.

[0135] The second loss function may be a cross entropy loss function, and the second loss function includes:

[0136] L2=m*log(p)+(1-m)log(1-p)

[0137] Among them, m represents the sample label of the training image sample, p represents the true and false discrimination result of the training image sample, and L2 represents the second loss error.

[0138] In some embodiments, when the input training image sample is a real image sample, m=1; when the input training image sample is a false image sample, m=0.

[0139] Step S162: Based on the second loss error, use the gradient descent algorithm to update the model parameters of the image discrimination model and the matrix parameters of the attention score matrix to obtain the target image discrimination model.

[0140] Based on the second loss error, back propagation is performed using a gradient descent algorithm to update model parameters of the image discrimination model and simultaneously update matrix parameters of the attention score matrix. The gradient descent algorithm may include a stochastic gradient descent (SGD) algorithm.

[0141] During the training process, when the second loss error reaches convergence or the training round reaches the round threshold, the model parameters and attention score matrix that are optimal for the output results of the corresponding model during the iterative training process are determined, thereby obtaining the target image discrimination model.

[0142] In some embodiments, when the input image sample is a false image sample, in the deep features of the image, the receptive field corresponding to a channel of the feature map of the image in the input image sample can include the PS part, and the attention score matrix can be used to assign different weights to various parts of the feature map, thereby distinguishing important areas in the image, and generating and updating the attention score matrix through modeling, so as to be able to more rationally explore the key parts on the feature map, thereby assigning higher weights to them, so as to improve the accuracy of identifying the PS part in the image, thereby improving the accuracy of identifying false images, and helping to improve the impact of non-critical parts of image features on the recognition effect. In actual applications, when using the trained target image discrimination model for image detection, the target image discrimination model uses the learned attention score matrix to process the key parts of the input image features, thereby accurately and efficiently obtaining the detection and recognition results of the image, improving the recognition efficiency and accuracy, and improving the impact of non-critical parts of the image features on the recognition effect.

[0143] In some embodiments, in step S17, during model training of the image discrimination model, model parameters of the target image generation model are updated based on a third loss error between the true / false discrimination result of the third false image sample and the sample label corresponding to the third false image sample, including: obtaining the third loss error based on the true / false discrimination result of the third false image sample and the corresponding sample label based on a preset third loss function; and updating the model parameters of the target image generation model using a gradient descent algorithm based on the third loss error. The gradient descent algorithm may be a stochastic gradient descent algorithm.

[0144] The third loss function may be a logarithmic loss function, and the third loss function includes:

[0145] L3=s*log(D(G(x,norm)))

[0146] Among them, G(·) represents the third false image sample, D(·) represents the true and false discrimination result of the third false image sample, s represents the sample label corresponding to the third false image sample, and L3 represents the third loss error.

[0147] Figure 8 A flow chart of an image detection method provided in an embodiment of the present disclosure, referring to Figure 8 , the image detection method includes:

[0148] Step S41: Acquire an image to be detected.

[0149] The present disclosure does not impose any special restrictions on the method of obtaining the image to be detected. For example, the image to be detected can be received by an electronic device through a human-computer interaction interface, an application, an interface, a camera device, etc.

[0150] Step S42: input the image to be detected into a preset target image discrimination model to obtain an image discrimination result, which is used to evaluate whether the image to be detected is a real image.

[0151] The target image discrimination model is trained using the image discrimination model training method or the generative adversarial network training method described in the above embodiments. The target image discrimination model can be integrated into an electronic device, which uses the target image discrimination model to perform image recognition and detection processing on an image to be detected input by a user, thereby obtaining a corresponding image detection result.

[0152] In the embodiment of the present disclosure, the trained target image discrimination model can be applied to various scenarios related to image detection tasks to achieve the required image detection function. For example, face recognition scenarios, intelligent license plate recognition scenarios, intelligent document recognition scenarios, intelligent contract recognition scenarios, etc. Correspondingly, the above-mentioned image detection method can be applied to products corresponding to these scenarios, such as face recognition systems, intelligent license plate recognition systems, intelligent document recognition systems, and intelligent contract recognition systems. Taking the face recognition system as an example, after receiving the face image to be detected input by the user, the face recognition system can first use the target image discrimination model pre-trained by the training method of the embodiment of the present disclosure to perform false face image detection on the face image to be detected input by the user. When the detection result is a real face image, the next step can be performed, such as face comparison and other operations. When the detection result is a false face image, it can be determined that the face recognition fails.

[0153] In the embodiment of the present disclosure, since the target image discrimination model is obtained by training using the above-mentioned training method, the image recognition effect of the target image discrimination model can be effectively improved. Therefore, by performing image discrimination on the image to be detected through the target image discrimination model, the discrimination accuracy of the image to be detected can be effectively improved.

[0154] It is understood that the above-mentioned various method embodiments mentioned in this disclosure can be combined with each other to form combined embodiments without violating the principle logic. Due to space limitations, this disclosure will not go into details. It is understood by those skilled in the art that in the above-mentioned methods of specific implementation, the specific execution order of each step should be determined by its function and possible internal logic.

[0155] In addition, the present disclosure also provides a training device for a generative adversarial network, an image detection device, an electronic device and a computer-readable storage medium. The above-mentioned training device for a generative adversarial network is used to implement any one of the training methods for a generative adversarial network provided in the present disclosure, and the above-mentioned image detection device is used to implement any one of the image detection methods provided in the present disclosure. The above-mentioned electronic device and computer-readable storage medium can both be used to implement any one of the training methods or image detection methods provided in the present disclosure. The corresponding technical solutions and descriptions are referred to the corresponding records in the method section and will not be repeated here.

[0156] Figure 9 A block diagram of a training device for a generative adversarial network provided in an embodiment of the present disclosure.

[0157] Reference Figure 9 , an embodiment of the present disclosure provides a training device 700 for a generative adversarial network, wherein the generative adversarial network includes an image generation model and an image discrimination model, and the training device 700 for the generative adversarial network includes: a first acquisition unit 701, a first training unit 702, a second training unit 703 and a fine-tuning unit 704.

[0158] The first acquiring unit 701 is used to acquire a first false image sample and a corresponding random noise image corresponding to the real image sample.

[0159] The first training unit 702 is used to: input the first false image sample and the random noise image into the image generation model to generate the first image, thereby obtaining the second false image sample; and perform model training on the image generation model based on the first loss error between the second false image sample and the first false image sample to obtain the target image generation model.

[0160] The first acquisition unit 701 is further configured to input the real image sample into the target image generation model to generate a second image, and obtain a corresponding third false image sample.

[0161] The second training unit 703 is used to: use the real image sample and the third false image sample as training image samples, respectively, and input them into the image discrimination model in sequence for image discrimination to obtain true and false discrimination results corresponding to the training image samples; perform model training on the image discrimination model according to the second loss error between the true and false discrimination results corresponding to the training image samples and the sample labels corresponding to the training image samples to obtain a target image discrimination model; wherein, when the training image sample is a real image sample, the sample label corresponding to the training image sample is the real image sample label, and when the training image sample is the third false image sample, the sample label corresponding to the training image sample is the false image sample label.

[0162] The fine-tuning unit 704 is used to update the model parameters of the target image generation model according to the third loss error between the true and false discrimination result corresponding to the third false image sample as the training image sample and the sample label corresponding to the third false image sample during the model training of the image discrimination model.

[0163] The generative adversarial network training device 700 provided in the embodiment of the present disclosure is used to implement the generative adversarial network training method provided in any of the above embodiments. For specific related descriptions, please refer to the description of the generative adversarial network training method in any of the above embodiments, which will not be repeated here.

[0164] Figure 10 A block diagram of an image detection device provided in an embodiment of the present disclosure.

[0165] Reference Figure 10 , an embodiment of the present disclosure provides an image detection device 800 , which includes: a second acquisition unit 801 and a prediction unit 802 .

[0166] The second acquisition unit 801 is used to acquire the image to be detected; the prediction unit 802 is used to input the image to be detected into a preset target image discrimination model to obtain an image discrimination result, which is used to evaluate whether the image to be detected is a real image;

[0167] Among them, the target image discrimination model is trained according to the above-mentioned image discrimination model training method or the generative adversarial network training method.

[0168] The image detection device 800 provided in the embodiment of the present disclosure is used to implement the image detection method provided in any of the above embodiments. For specific related descriptions, please refer to the description of the image detection method in any of the above embodiments, which will not be repeated here.

[0169] Figure 11 A block diagram of an electronic device provided in an embodiment of the present disclosure.

[0170] Reference Figure 11 An embodiment of the present disclosure provides an electronic device 900, which includes: at least one processor 901; at least one memory 902, and one or more I / O interfaces 903 connected between the processor 901 and the memory 902; wherein the memory 902 stores one or more computer programs that can be executed by the at least one processor 901, and the one or more computer programs are executed by the at least one processor 901 so that the at least one processor 901 can execute the above-mentioned generative adversarial network training method or image detection method.

[0171] The present disclosure also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the aforementioned generative adversarial network training method or image detection method. The computer-readable storage medium may be volatile or non-volatile.

[0172] An embodiment of the present disclosure also provides a computer program product, including a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the above-mentioned generative adversarial network training method or image detection method.

[0173] It will be understood by those skilled in the art that all or some of the steps, systems, and functional modules / units in the methods disclosed above may be implemented as software, firmware, hardware, and appropriate combinations thereof. In a hardware implementation, the division between the functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed by several physical components in cooperation. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or may be implemented as hardware, or may be implemented as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable storage medium, which may include a computer storage medium (or non-transitory medium) and a communication medium (or temporary medium).

[0174] As is well known to those skilled in the art, the term computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information (such as computer-readable program instructions, data structures, program modules or other data). Computer storage media includes, but is not limited to, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), static random access memory (SRAM), flash memory or other memory technology, portable compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical disc storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store the desired information and can be accessed by a computer. In addition, as is well known to those skilled in the art, communication media typically contains computer-readable program instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.

[0175] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions to be stored in the computer-readable storage medium in each computing / processing device.

[0176] The computer program instructions for performing the operations of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Smalltalk, C++, and conventional procedural programming languages ​​such as "C" language or similar programming languages. Computer-readable program instructions may be executed entirely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., utilizing an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be personalized by utilizing the state information of the computer-readable program instructions. The electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the present disclosure.

[0177] The computer program product described herein may be implemented in hardware, software, or a combination thereof. In one embodiment, the computer program product is implemented as a computer storage medium. In another embodiment, the computer program product is implemented as a software product, such as a software development kit (SDK).

[0178] Various aspects of the present disclosure are described herein with reference to flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the present disclosure. It should be understood that each block of the flowcharts and / or block diagrams, and combinations of blocks in the flowcharts and / or block diagrams, can be implemented by computer-readable program instructions.

[0179] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device is generated that implements the functions / actions specified in one or more blocks in the flowchart and / or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium, where these instructions cause the computer, programmable data processing device, and / or other device to operate in a specific manner. Thus, the computer-readable medium storing the instructions comprises an article of manufacture that includes instructions for implementing various aspects of the functions / actions specified in one or more blocks in the flowchart and / or block diagram.

[0180] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operational steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more blocks in the flowchart and / or block diagram.

[0181] The flow charts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the systems, methods and computer program products according to multiple embodiments of the present disclosure. In this regard, each box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and the part of the module, program segment or instruction contains one or more executable instructions for realizing the prescribed logical function. In some alternative implementations, the functions marked in the box can also occur in a sequence different from that marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented by a dedicated hardware-based system that performs the prescribed function or action, or can be implemented by a combination of dedicated hardware and computer instructions.

[0182] Example embodiments have been disclosed herein, and although specific terms are employed, they are used and should be interpreted only in a general illustrative sense and not for purposes of limitation. In some instances, it will be apparent to those skilled in the art that, unless otherwise expressly indicated, features, characteristics, and / or elements described in conjunction with a particular embodiment may be used alone or in combination with features, characteristics, and / or elements described in conjunction with other embodiments. Therefore, it will be understood by those skilled in the art that various changes in form and detail may be made without departing from the scope of the present disclosure as set forth in the appended claims.

Claims

1. A training method for a generative adversarial network, characterized in that: The generative adversarial network includes an image generation model and an image discrimination model, and the training method includes: Obtaining a first false image sample and a corresponding random noise image corresponding to the real image sample; Inputting the first false image sample and the random noise image into the image generation model to generate a first image, thereby obtaining a second false image sample; Performing model training on the image generation model according to a first loss error between the second false image sample and the first false image sample to obtain a target image generation model; Inputting the real image sample into the target image generation model to generate a second image to obtain a third false image sample; The real image sample and the third false image sample are respectively used as training image samples, and are sequentially input into the image discrimination model for image discrimination to obtain true and false discrimination results corresponding to the training image samples; The image discrimination model is trained based on a second loss error between a true or false discrimination result corresponding to the training image sample and a sample label corresponding to the training image sample to obtain a target image discrimination model; wherein, when the training image sample is a real image sample, the sample label corresponding to the training image sample is a real image sample label, and when the training image sample is a third false image sample, the sample label corresponding to the training image sample is a false image sample label; During model training of the image discrimination model, the model parameters of the target image generation model are updated based on the third loss error between the true and false discrimination result corresponding to the third false image sample as the training image sample and the sample label corresponding to the third false image sample.

2. The training method according to claim 1, characterized in that The step of obtaining a first false image sample corresponding to the real image sample includes: Performing target content area detection on the real image sample; Generate a corresponding mask according to the position coordinates of the target content area; The target content in the mask is erased, and false content is generated in the erased area to obtain a first false image sample corresponding to the real image sample.

3. The training method according to claim 1, characterized in that The method of generating the first image includes: Performing feature extraction on the first false image sample and the random noise image respectively to obtain a first feature map corresponding to the first false image sample and a second feature map corresponding to the random noise image; Performing feature fusion on the first feature map and the second feature map to obtain a fused feature map; Downsampling the fused feature map to obtain a downsampled feature map; Upsampling the downsampled feature map to obtain an upsampled feature map; The second false image sample is generated according to the upsampled feature map.

4. The training method according to claim 1, characterized in that The step of performing image discrimination on the training image samples to obtain true and false discrimination results corresponding to the training image samples includes: Performing block processing on the third feature map corresponding to the training image sample to obtain a plurality of first feature blocks; Randomly trimming the multiple first feature blocks respectively to obtain multiple second feature blocks; Splicing and combining the plurality of second feature blocks to obtain a fourth feature map; Obtaining a true / false discrimination score corresponding to the training image sample according to the fourth feature map and a preset attention score matrix; According to the true and false discrimination scores corresponding to the training image samples, the true and false discrimination results of the training image samples are obtained.

5. The training method according to claim 4, characterized in that The step of obtaining the true and false discrimination scores corresponding to the training image samples according to the fourth feature map and the preset attention score matrix includes: Obtaining a convolution result of the fourth feature map and a preset attention score matrix; The convolution processing result is subjected to a convolution processing operation using the weight parameters of the output layer of the image discrimination model to obtain a true or false discrimination score corresponding to the training image sample.

6. The training method according to claim 4, characterized in that: The step of training the image discrimination model based on the true and false discrimination result of the training image sample and the second loss error between the sample labels corresponding to the training image sample to obtain the target image discrimination model includes: Based on a preset loss function, obtaining the second loss error according to the true and false discrimination results of the training image samples and the sample labels corresponding to the training image samples; Based on the second loss error, the model parameters of the image discrimination model and the matrix parameters of the attention score matrix are updated using a gradient descent algorithm to obtain the target image discrimination model.

7. An image detection method, characterized in that: include: Obtain the image to be detected; Inputting the image to be detected into a preset target image discrimination model to obtain an image discrimination result, wherein the image discrimination result is used to evaluate whether the image to be detected is a real image; The target image discrimination model is obtained by training according to the training method according to any one of claims 1-6.

8. A training device for a generative adversarial network, characterized in that: The generative adversarial network includes an image generation model and an image discrimination model, and the training device includes: A first acquiring unit, configured to acquire a first false image sample and a corresponding random noise image corresponding to the real image sample; A first training unit is configured to: input the first false image sample and the random noise image into the image generation model to perform first image generation to obtain a second false image sample; and perform model training on the image generation model based on a first loss error between the second false image sample and the first false image sample to obtain a target image generation model; The first acquisition unit is further configured to input the real image sample into the target image generation model to generate a second image, thereby obtaining a third false image sample; The second training unit is configured to: use the real image sample and the third false image sample as training image samples, respectively, and input them into the image discrimination model in sequence to perform image discrimination, thereby obtaining true and false discrimination results corresponding to the training image samples; perform model training on the image discrimination model based on a second loss error between the true and false discrimination results corresponding to the training image samples and the sample labels corresponding to the training image samples, thereby obtaining a target image discrimination model; wherein, when the training image sample is a real image sample, the sample label corresponding to the training image sample is a real image sample label, and when the training image sample is a third false image sample, the sample label corresponding to the training image sample is a false image sample label; A fine-tuning unit is used to update the model parameters of the target image generation model according to a third loss error between the true and false discrimination result corresponding to the third false image sample as the training image sample and the sample label corresponding to the third false image sample during the process of model training of the image discrimination model.

9. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores one or more computer programs that can be executed by the at least one processor, and the one or more computer programs are executed by the at least one processor so that the at least one processor can execute the training method according to any one of claims 1 to 6 or the image detection method according to claim 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, it implements the training method according to any one of claims 1 to 6 or the image detection method according to claim 7.

Citation Information

Patent Citations

  • Generative adversarial network training method and device and image enhancement method and device

    CN110991636A

  • Image tampering recognition model training method and device and image tampering recognition method and device

    CN111368342A