Image detection method and device based on adversarial generation, equipment and medium
By generating an adversarial network to generate fake image samples and combining the image feature extraction module with self-attention mechanism, the problem of insufficient detection accuracy of high simulation and forged areas in the prior art is solved, and high-precision recognition and robust detection of fake areas in the image is achieved.
Patent Information
- Application Number
- CN202510684078.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-26
- Publication Date
- 2025-08-29
AI Technical Summary
The existing image forgery detection methods lack adversarial generation and global feature modeling, resulting in insufficient detection accuracy and limited generalization capabilities for high simulation forgery areas.
By generating fake image samples from the adversarial network, an image feature extraction module containing a self-attention mechanism is built, and a forged area recognition module is used to compare the global feature differences, a forged probability map is generated, and a joint loss function is constructed based on the discriminator output of the generated adversarial network, and the parameters of the generator, feature extraction module and forged area recognition module are optimized.
It improves the detection accuracy of local forged areas in the image and the robustness of complex forged samples, and meets the needs of automated discrimination of image content authenticity in high-security scenarios such as finance and medical care.
Smart Images

Figure CN120564015A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to an image detection method, apparatus, device and storage medium based on adversarial generation. Background Art
[0002] In the fintech sector, verifying the authenticity of user identity documents remains a critical component of ensuring business security and compliance in scenarios such as credit approval, account opening verification, and high-risk transaction monitoring. Especially with the increasing popularity of remote services and mobile applications, banks and financial institutions often rely on users to proactively upload image-based documents such as ID cards, driver's licenses, and facial photos for identity verification. However, due to the uncontrollable data collection sources and the open nature of upload channels, the risk of malicious image forgery increases significantly. Current mainstream methods often use traditional image classification networks or local feature-based detection techniques. However, these methods lack accuracy and generalization when used against deepfakes such as generative adversarial networks (GANs), especially when accurately detecting subtle forgery traces embedded in images. This poses a real risk to financial businesses of identity theft and fraudulent activity that cannot be promptly intercepted. While manual review mechanisms can mitigate misidentification to some extent, they struggle to ensure efficiency and reliability when dealing with large amounts of image data.
[0003] In the healthcare business, electronic medical records, medical imaging data, and image information related to online consultations are gradually being introduced into automated processing processes. For example, pathological photos and examination images uploaded by users have become important inputs for remote diagnosis and auxiliary judgment. However, since medical images usually contain complex textures and structural information that is highly dependent on the accuracy of details, once forged images are mixed in, it is very easy to mislead the diagnostic results and even cause misjudgment. In existing technologies, image content review mostly relies on static rule filtering or shallow network models for image screening, but these methods often lack sufficient perception and resolution when processing forged images, especially medical images generated based on deep synthesis technology, and it is difficult to meet the business requirements of high accuracy and security compliance.
[0004] In the field of image security analysis, although some forgery detection technologies based on deep neural networks have been proposed, such as methods that use convolutional neural networks (CNNs) to extract image features and then classify them as genuine, these methods often exhibit blind spots when dealing with complex structural or minimally identifiable image forgeries. Furthermore, existing detection models often focus on overall image discrimination and lack the precise perception and location of localized forged areas. This makes the models susceptible to interference from factors such as image resolution and compression loss, resulting in unstable detection results and limited generalization capabilities, making them difficult to adapt to the real-world business needs of multi-source, multi-modal image content review. Summary of the Invention
[0005] The main purpose of the present invention is to provide an image detection method, device, equipment and storage medium based on adversarial generation, aiming to solve the technical problems of existing image forgery detection methods that lack the coordinated optimization of adversarial generation and global feature modeling, resulting in insufficient detection accuracy of highly simulated forged areas and limited generalization ability.
[0006] To achieve the above objectives, the present invention provides an image detection method based on adversarial generation, comprising:
[0007] Based on the real image samples, generating fake image samples through a generative adversarial network, and mixing the fake image samples with the real image samples to form a training dataset;
[0008] Constructing an image feature extraction module including a self-attention mechanism, performing global feature modeling on the images in the training dataset through the image feature extraction module to generate a global feature map;
[0009] Based on the global feature map, a forged region identification module is used to compare the global feature differences between the real image and the forged image to generate a forgery probability map;
[0010] Generating a detection loss value through the forgery probability map, and constructing a joint loss function in combination with the adversarial loss value output by the discriminator of the generative adversarial network;
[0011] Performing backpropagation optimization on the generator parameters of the generative adversarial network, the model parameters of the image feature extraction module, and the model parameters of the forged region identification module based on the joint loss function to obtain a forgery detection model;
[0012] The image to be detected is processed by the forgery detection model to determine forgery information in the image to be detected.
[0013] Furthermore, to achieve the above-mentioned object, the present invention provides an image detection device based on adversarial generation, comprising:
[0014] A generative adversarial module is configured to generate forged image samples based on real image samples through a generative adversarial network, and mix the forged image samples with real image samples to form a training dataset;
[0015] An image feature extraction module is used to construct an image feature extraction module including a self-attention mechanism, and perform global feature modeling on the images in the training dataset through the image feature extraction module to generate a global feature map;
[0016] a forged region identification module, configured to generate a forged probability map by comparing global feature differences between the real image and the forged image based on the global feature map;
[0017] A joint loss construction module, configured to generate a detection loss value using the forgery probability map and construct a joint loss function in combination with the adversarial loss value output by the discriminator of the generative adversarial network;
[0018] a parameter optimization module, configured to perform back-propagation optimization on the generator parameters of the generative adversarial network, the model parameters of the image feature extraction module, and the model parameters of the forged region identification module based on the joint loss function to obtain a forgery detection model;
[0019] The forgery detection model processing module is used to process the image to be detected by using the forgery detection model to determine the forgery information in the image to be detected.
[0020] Furthermore, to achieve the above-mentioned purpose, the present invention also provides a computer device, which includes a memory, a processor, and an adversarial generation-based image detection program stored in the memory and runnable on the processor. When the adversarial generation-based image detection program is executed by the processor, the steps of the adversarial generation-based image detection method as described above are implemented.
[0021] Furthermore, to achieve the above-mentioned purpose, the present invention also provides a computer-readable storage medium, on which is stored an image detection program based on adversarial generation, and when the image detection program based on adversarial generation is executed by a processor, the steps of the image detection method based on adversarial generation as described above are implemented.
[0022] Beneficial effects: The present invention relates to the field of artificial intelligence technology and can be applied to business scenarios such as financial technology and medical health. It discloses an image detection method, device, equipment and medium based on adversarial generation, including: generating forged image samples based on real image samples, and mixing and constructing a training data set; constructing an image feature extraction module containing a self-attention mechanism to perform global feature modeling on the training image; using a forged region identification module to compare the global feature differences between the real image and the forged image to generate a forged probability map; constructing a joint loss function based on the forged probability map and the discriminator output; using the joint loss function to optimize the parameters of the generator, the image feature extraction module and the forged region identification module to obtain a forged detection model; processing the image to be detected through the forged detection model to identify the forged information in the image. The present invention generates high-quality forged samples through a generative adversarial network, combines the image feature extraction module containing a self-attention mechanism to achieve global feature modeling, and performs difference analysis through a forged region identification module to construct a joint optimization objective function, thereby improving the model's detection accuracy for local forged areas in the image and the robustness of complex forged samples, meeting the demand for automated discrimination of the authenticity of image content in high-security scenarios such as finance and medical care. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The present invention will be further described below with reference to the accompanying drawings and embodiments, in which:
[0024] Figure 1 A schematic diagram of an application environment of an image detection method based on adversarial generation in an embodiment of the present invention;
[0025] Figure 2 This is a flow chart of an embodiment of an image detection method based on adversarial generation according to the present invention;
[0026] Figure 3 Schematic diagram of functional modules of a preferred embodiment of an image detection device based on adversarial generation according to the present invention;
[0027] Figure 4 A schematic diagram of the structure of a computer device according to an embodiment of the present invention;
[0028] Figure 5 FIG. 2 is another structural diagram of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0029] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0030] The image detection method based on adversarial generation provided by the embodiment of the present invention can be applied in the following fields: Figure 1 In an application environment, the user terminal communicates with the server terminal through a network. The server terminal can generate forged image samples based on real image samples through the user terminal and mix them to construct a training data set; construct an image feature extraction module containing a self-attention mechanism to perform global feature modeling on the training image; use the forged region identification module to compare the global feature differences between the real image and the forged image to generate a forged probability map; construct a joint loss function based on the forged probability map and the discriminator output; use the joint loss function to optimize the parameters of the generator, image feature extraction module and forged region identification module to obtain a forged detection model; process the image to be detected through the forged detection model to identify forged information in the image. The present invention generates high-quality forged samples through a generative adversarial network, combines the image feature extraction module containing a self-attention mechanism to achieve global feature modeling, and performs difference analysis through the forged region identification module to construct a joint optimization objective function, thereby improving the model's detection accuracy for local forged regions in the image and the robustness of complex forged samples, meeting the needs of automated discrimination of image content authenticity in high-security scenarios such as finance and medical care. The user terminal can be, but is not limited to, various personal computers, laptops, smartphones, tablets and portable wearable devices. The server terminal can be implemented as an independent server or a server cluster consisting of multiple servers. The present invention is described in detail below through specific examples.
[0031] See also Figure 2 , Figure 2 This is a flowchart of an embodiment of an image detection method based on adversarial generation provided by the present invention. It should be noted that although a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than that shown here.
[0032] like Figure 2 As shown, the image detection method based on adversarial generation proposed in the present invention includes the following steps:
[0033] S10, generating forged image samples based on the real image samples through a generative adversarial network, and mixing the forged image samples with the real image samples to form a training dataset;
[0034] In this embodiment, real image samples are obtained. Their data sources may include documents submitted by users in real business scenarios, facial photos, medical images, scanned medical records, or other data images collected by trusted collection terminals. In financial scenarios, these can be ID photos uploaded during account opening, while in healthcare scenarios, they can be medical scans collected by in-house imaging equipment in hospitals. Real image samples should be clearly labeled, have stable image quality, and be formatted uniformly to support subsequent image generation and differential learning modeling.
[0035] Real image samples are fed into a generative adversarial network for training. The key is that the generator module must be able to simulate the structural and texture features of real images while exploring generative paths with forged properties in the latent space. To achieve this, a high-dimensional random noise vector is combined with the real image sample as input. The noise vector can be generated using a standard normal distribution or a uniform distribution, and its dimension should be related to the image resolution and feature dimension. For example, for a 512×512 image, the noise dimension can be set to 128 or 256 to cover sufficient semantic variation. The generator network structure can choose to use a U-Net-based upsampling path or the Token Decoder module in the Transformer architecture to enhance the contextual consistency of the generated image and the expressiveness of local forged features.
[0036] Generated forged image samples should contain multiple types of forged features, such as content modification, splicing manipulation, position cropping, and texture replacement. By designing different training loss constraints and discriminator feedback mechanisms, the generator is forced to learn the forged distribution in these image spaces. Forged images should not only be generated visually, but also possess semantic features that are highly similar to real images but differ in key areas, thereby improving the discriminative ability of subsequent forged region detection models.
[0037] After the image is generated, it needs to be mixed with the original real image samples to construct a training dataset. The mixing strategy can dynamically adjust the mixing ratio of real and forged images based on image category, sampling probability or quality index. The mixing ratio is not a fixed setting. For example, real images can be used as the main ones in the early stage of training (for example, 80% real images, 20% forged images) to ensure the stability of the basic recognition ability of the model; and the proportion of forged images can be gradually increased in the middle and late stages of training to enhance the sensitivity of the model to forged samples. The training dataset formed after mixing needs to ensure the balance of sample distribution, label accuracy and batch loading capabilities. The data can be input in batches through a distributed reader or data augmentation pipeline, and combined with online data augmentation operations to maintain diversity, such as random cropping, rotation, color perturbation and other methods.
[0038] In actual deployment, generative adversarial networks with different architectures can be used to generate forged images. For example, the convolutional neural network-based DCGAN architecture can be used to quickly implement basic image simulation. Alternatively, the StyleGAN family of networks can be used to generate high-resolution, detail-rich image samples to enhance the model's ability to identify fine-grained forgeries. In terms of noise design, conditional vectors can be introduced for label guidance, allowing forged images to have specific attribute differences. For example, this can be used to simulate tissue images of different locations in medical scenarios, or to simulate ID card images under different document types or lighting conditions in financial scenarios.
[0039] To improve the detection of forged images, reinforcement learning can be used to guide the generator in producing more challenging images. By maximizing the discriminator's error rate through a reward function, the generator is optimized towards making forgeries unrecognizable, thereby constructing a more generalizable training dataset for the detection model. Furthermore, a multi-scale supervision mechanism can be introduced to fuse and label forged and real images at different spatial resolutions, making the training data better suited to the multi-scale feature extraction structure of subsequent modules.
[0040] The proportion control during the mixing process can also be linked to the number of model training rounds to achieve dynamic adjustment. For example, a proportion adjustment function can be designed to adaptively increase the weight of forged images based on training accuracy or loss reduction rate. This can increase the influence of forged samples as the model stabilizes, thereby improving the ability to detect edge forged areas.
[0041] Example: In the healthcare sector, this can be used to verify the authenticity of pathology images or CT scans. When users submit remote image data for diagnostic pre-screening or registration verification, the model can be trained by fusing real medical images with synthetically forged images in the training dataset to build discriminative capabilities. This allows the model to identify and intercept images containing inconsistent anatomical structures or tampered labels, effectively preventing medical fraud or misleading data input.
[0042] In the field of financial technology business, especially when submitting image materials for key links such as loans, account opening, and claims settlement, images such as ID cards and scanned copies of bank statements uploaded by users can be input into the system. Relying on the detection model constructed by a large number of forged image samples introduced in the training phase, it automatically identifies images that may have been photoshopped, synthesized, and spliced, reducing manual review costs and improving the accuracy of image compliance reviews, thereby enhancing the risk control capabilities and transaction security levels of financial businesses.
[0043] This embodiment constructs a training dataset containing both real images and high-quality forged images, enabling the model to simultaneously learn the feature distribution of real images and the detailed differences between forged images during the training phase, improving its ability to identify fine-grained tampered areas. Furthermore, the forged images are dynamically generated by the generator, resulting in a high degree of diversity and unpredictability. This eliminates the risk of overfitting associated with traditional static forged samples, thereby improving the generalization and robustness of the entire forgery detection system.
[0044] S20, constructing an image feature extraction module including a self-attention mechanism, performing global feature modeling on the images in the training dataset through the image feature extraction module to generate a global feature map;
[0045] In this embodiment, the image feature extraction module is the core structure of the model for encoding image semantic information, and its main task is to map the input image from the pixel space to the feature space representing the global semantic relationship. This module introduces a self-attention mechanism to solve the limitations of the traditional convolutional neural network structure in long-distance dependency modeling. In terms of construction, the encoding module in the Vision Transformer (ViT) architecture can be adopted, in which the input image is divided into a sequence of image blocks of a fixed size, and each image block is linearly projected in the dimension and converted into a vector representation to form an initial feature vector sequence. The vector dimension is usually set to 128, 256 or higher to adapt to the needs of complex image information expression.
[0046] To preserve the spatial structure of the image, the spatial position information of the image block needs to be encoded as a position embedding vector and superimposed with the feature vector. The position encoding vector can be a fixed vector constructed using sine and cosine functions, or a learnable position embedding obtained through training, allowing the model to preserve the spatial constraints in the two-dimensional image when processing a sequence of image blocks. The feature sequence with the position embedding is input into a multi-layer self-attention module, which includes vector representations of the query, key, and value. The self-attention module calculates the weighted dependencies between all image blocks through the attention mechanism, thereby explicitly modeling the contextual information of distant image regions.
[0047] The generation of the association weight matrix is based on an attention scoring function, typically using a dot-product attention calculation. The features output by each attention layer incorporate contextual information from the entire image. This multi-layered attention structure gradually strengthens the global information interaction between image patches, improving the integrity and accuracy of image feature representation. The feature sequences output by all attention layers are ultimately merged or reshaped into a two-dimensional representation as a global feature map for downstream forgery region detection or image classification modules.
[0048] In specific implementations, a fixed-size image block approach can be used to divide the input image into equal-sized blocks. For example, a 224×224 input image can be divided into 16×16 blocks, for a total of 196 blocks, each 14×14 in size. Each block is then expanded using a linear mapping function to transform it into a vector of dimension D. This is combined to form a feature matrix consisting of 196 D-dimensional feature vectors. To further enhance the semantic fusion between image blocks, a multi-head attention mechanism can be employed. This involves concurrently computing attention representations from multiple subspaces within the same attention layer and concatenating them to enhance representational diversity. Following each self-attention layer, a feedforward neural network (FFN) module is connected to perform nonlinear transformations. Residual connections and layer normalization are used to improve training stability and feature distribution balance. This module can also integrate a convolutional pre-processing network to extract edge features and texture distribution through shallow convolutions before the input image is partitioned, allowing the Transformer layer to focus more on mid- and high-level semantic structures. In addition, the position encoding method can also use relative position offset encoding to adapt to changes in dynamic structures in the image, making it more suitable for problems such as deformation or perspective offset in medical images and ID images.
[0049] Example: In Fintech business scenarios, ID images uploaded by users may contain corner modifications, image splicing, or forged seals. By inputting this image into the image feature extraction module, the model can use the attention mechanism to detect inconsistencies between edge regions and central text areas, automatically capture abnormal information expressions, and form a clearly structured global feature map, providing a foundation for subsequent identification of forged areas.
[0050] In healthcare scenarios, X-rays or CT images uploaded by users may contain artifacts or occlusions of critical lesion areas. This module models the global relationship between organ structure and boundaries in images. It can detect artifact-caused features such as structural continuity interruptions, texture inconsistencies, or blurred boundaries. This helps downstream recognition modules more effectively locate potential artifact areas, improving the compliance review capabilities and diagnostic credibility of medical images.
[0051] By introducing a self-attention mechanism into the image feature extraction module, this embodiment enables the model to explicitly model the long-range dependencies between regions in the image, addressing the limitations of traditional convolutional structures in capturing long-range information. At the same time, the multi-head attention structure enhances the model's ability to express the semantic details of image blocks, making it easier to focus on abnormally changing regions in the image during training. This global feature map generated using a sequential modeling approach provides the subsequent forged region identification module with a structurally complete, contextually consistent, and detailed image representation, thereby improving the overall accuracy and stability of the image forgery detection system.
[0052] S30, based on the global feature map, using a forged region identification module to compare global feature differences between the real image and the forged image to generate a forgery probability map;
[0053] In this embodiment, the forged region identification module generates a forgery probability map based on the difference between the global feature maps of the real and forged images. This map depicts the distribution of forgery probability across image regions. The global feature map, an abstract semantic representation of the image in high-dimensional space, is a tensor representation derived from modeling by the image feature extraction module. It encompasses spatial layout, texture details, and contextual semantics.
[0054] From a modeling perspective, generating independent global feature maps for real and fake images allows for comparison of their feature representation capabilities at multiple scales. Feature maps of varying spatial resolutions can represent information at different semantic levels. For example, high-resolution layers favor texture and edge representations, while low-resolution layers emphasize structure and regional semantics. Therefore, extracting multi-level feature maps is essential. This can be achieved by selecting representations from different layers within the Transformer or by constructing additional feature pyramids to achieve hierarchical spatial resolution.
[0055] The extracted multi-resolution feature maps are fused along the channel dimension to preserve the complementarity of multi-layer information. The channel concatenation operation stacks multi-scale feature tensors along the channel dimension to form an enhanced feature map, enabling subsequent analysis modules to perceive both fine-grained and global semantic differences.
[0056] During the difference analysis phase, the similarity analysis mechanism within the forged region identification module can be used to measure the semantic deviation between the real and forged images. Specifically, the cosine similarity matrix between the two enhanced feature maps is calculated to measure the angular similarity of vectors at each spatial location, further generating a spatial difference response map. The closer the difference response matrix is to 0, the greater the local difference in the image, and the more likely that the region is a forgery.
[0057] To ensure a standardized feature representation of the response map, it needs to be normalized, mapping all difference values to a preset probability interval, such as [0, 1], for use in subsequent classification or thresholding modules. Furthermore, to facilitate visualization and alignment with the original image, the normalized response map should be upsampled to the original resolution of the images in the training dataset using a bilinear interpolation algorithm. The output tensor is the forgery probability map.
[0058] The numerical value corresponding to each pixel position in the forgery probability map represents the likelihood that the model will identify that location as a forged region. This map can be used as the forgery region localization result and as a pixel-level supervisory signal for constructing the loss function, guiding the model to learn the spatial distribution of forged regions.
[0059] In practical implementation, real and fake images are processed by the same image feature extraction module, which outputs respective global feature maps, denoted as F_real and F_fake. By constructing specific output channel combinations from the feature extraction layers—for example, extracting the outputs of the 6th, 9th, and final layers from the Transformer's intermediate layers—these represent features at different receptive fields and semantic levels, respectively. These features are then upsampled and aligned to the same channel dimension, and concatenated to produce enhanced feature maps T_real and T_fake. A point-to-point cosine similarity analysis module is then constructed to subtract T_real from T_fake along their spatial dimensions and normalize them. The cosine angle difference between each corresponding spatial position vector is calculated to generate a spatial difference response matrix, M_diff. Each value in the matrix represents the degree of semantic difference at that position. To improve the numerical stability of the response matrix, normalization is performed, such as using a min-max normalization function to map M_diff to a range between 0 and 1. The normalized result constitutes the normalized difference map. This image is then fed into the interpolation module for bilinear interpolation, restoring its resolution to the original size of the images in the training dataset (e.g., 224×224, 512×512, etc.), and outputting a forgery probability map P_forgery. This forgery probability map can be fed into subsequent modules to generate pixel-level losses, or directly extract forged region masks by setting a threshold (e.g., 0.5) for applications such as forged region localization or image auditing.
[0060] Example: In a FinTech business scenario, user-submitted ID photos may contain partial replacements, such as altered headshots or altered birth dates. Through the aforementioned forged region identification process, the model can identify inconsistencies in the global feature representation between the headshot region and other image regions, generate a forgery probability map, highlight the altered areas, and block the business accordingly.
[0061] In healthcare scenarios, medical imaging records, such as MRI images, can be partially modified during cross-institutional transmission, such as by masking or adding lesion locations. By detecting consistency deviations in the semantics of internal image structures, this technology can efficiently detect potential pixel-level forgeries, assisting image reviewers in quickly verifying image authenticity and ensuring the integrity and credibility of diagnostic and treatment information.
[0062] This embodiment effectively captures subtle differences in semantic expression between different image regions by performing a multi-scale, multi-channel fusion comparison of global feature maps of real and forged images. Furthermore, by generating a difference response map using cosine similarity calculation, the model's sensitivity to localized forgeries is enhanced, particularly for low-level forgery techniques such as edge stitching and texture transfer. Normalization and resolution restoration ensure the numerical rationality and spatial correspondence of the forgery probability map, enabling high-precision forged region identification.
[0063] S40, generating a detection loss value through the forgery probability map, and constructing a joint loss function in combination with the adversarial loss value output by the discriminator of the generative adversarial network;
[0064] In this embodiment, the forgery probability map is an important intermediate representation used by the model to measure the likelihood of forgery in an image region. Its value is typically a normalized probability distribution, reflecting the forgery confidence of each pixel. In order for the model to accurately locate and identify tampered or generated areas in the image, a supervision mechanism based on the forgery probability map is required. Specifically, a detection loss value is constructed using the forgery probability map, guiding the model to focus on the accurate representation of forged areas during training.
[0065] The key to constructing a detection loss is to perform a pixel-by-pixel approximation of the forgery probability map. Typically, a pixel-level loss function such as log-likelihood loss, cross-entropy loss, or Dice loss is used to compare the forgery probability map with annotated true forgery masks, thereby measuring the error between the model's prediction and the true distribution of the forged region. The goal of the detection loss is to make the model more sensitive to localized forgeries and capture the forgery characteristics of spatially detailed forgeries.
[0066] The discriminator in a generative adversarial network is responsible for determining the authenticity of an image. Its output, an adversarial loss, measures the distinguishability of the generated image from the real image at the overall structural and texture levels. This adversarial loss typically takes the form of binary cross entropy or LSGAN loss. By minimizing the probability that a forged image will be misclassified as real, it guides the generator to produce more deceptive images.
[0067] To balance the pixel-level accuracy of the detection task with the overall realism requirements of the adversarial task, a joint loss function is constructed to integrate the detection loss and the adversarial loss into a unified training objective function. During this integration process, weighted coefficients for the detection loss and the adversarial loss are introduced to regulate the emphasis on the two sub-objectives at different stages. The weighted coefficients can be static preset values or dynamic functions that change over training rounds, such as exponential decay or linear growth, to achieve a gradual transition from focusing on initial stability in adversarial training to fine-tuning the detection task.
[0068] The final form of the joint loss function is usually a linear combination of two weighted sub-losses, whose goal is to simultaneously optimize the accuracy of local image forgery recognition and the authenticity of the overall image quality, thereby obtaining a detection capability that is highly robust to detailed forgery areas.
[0069] In practice, the model compares the forgery probability map with the corresponding forgery label mask at each training round. The forgery prediction error for each pixel is calculated using the log-likelihood function. The losses for all pixels are summed and averaged to obtain the detection loss. This loss reflects the model's ability to detect forgeries under the current parameters. Simultaneously, the generated image is input to the discriminator, and the probability score of the output image being judged as real is calculated based on the difference with the true label. An image-level adversarial loss is calculated based on the difference between the two loss terms and the true label. To prevent the large difference in the numerical scale of the two loss terms from affecting the gradient propagation process, weighting coefficients α and β are set for each loss term. Initially, α can be set small and β large to stabilize the initial game between the generator and discriminator. As training progresses, α can be gradually increased to improve the focus on forgery detection. The joint loss function can be expressed as: L_total = α*L_detection + β*L_adversarial.
[0070] Where L_detection represents the pixel-level forged area detection loss, L_adversarial represents the discriminator adversarial loss, and α and β are dynamically adjusted weighting factors.
[0071] The joint loss is used as the target signal input into the optimization module for back propagation, guiding the generator, feature extraction module, and forged region recognition module to jointly adjust parameters to achieve the training goal of improving the overall detection capability of the model.
[0072] Example: In a fintech business scenario, a bank's review platform needs to detect whether ID or bank card images uploaded by users are forged. A joint loss function guides the model to learn the local features of different forgery types (such as text manipulation and photo pasting) and the overall sense of reality, enabling the system to automatically identify partially tampered images and improve business risk control capabilities.
[0073] In healthcare scenarios, the model can be used to identify maliciously modified medical images, such as CT images with forged tumor shadows or MRI scans with the removal of critical lesions. By detecting loss, it can capture small regional anomalies, while using countermeasures to maintain overall image consistency. This automatically identifies risky images without requiring extensive manual review, ensuring the security and credibility of diagnostic data.
[0074] This embodiment uses a pixel-level detection loss, generated by comparing the forgery probability map with the true labels, and constructs a joint loss function with the adversarial loss output by the discriminator. This function simultaneously optimizes the model's ability to identify local forged regions and understand global image authenticity. This joint loss function allows the model to focus not only on overall authenticity in high-quality forged images, but also on the precise location of forged regions. This significantly improves detection accuracy and generalization, while maintaining high robustness across different forgery types, distributions, and interference backgrounds.
[0075] S50, performing backpropagation optimization on the generator parameters of the generative adversarial network, the model parameters of the image feature extraction module, and the model parameters of the forged region identification module based on the joint loss function to obtain a forgery detection model;
[0076] In this embodiment, the joint loss function consists of two core components: a detection loss, used to measure the accuracy of forged region detection, derived from the model's pixel-by-pixel comparison of the forged probability map with the true forged mask; and an adversarial loss, used to guide the generator in producing more realistic images, derived from the discriminator's binary classification judgment of image authenticity. This loss function integrates these two components through a weighted strategy to form a unified optimization objective. Its fundamental purpose is to enable the forged region recognition module to enhance its ability to detect local anomalies while enabling the generative adversarial network to maintain the authenticity of the overall image structure and style.
[0077] The effect of the joint loss function on model parameters is achieved through an automatic differentiation mechanism. After forward propagation, automatic differentiation reversely calculates the gradient direction and gradient magnitude of each trainable parameter based on the loss function. The generator parameters of the generative adversarial network primarily control the quality of forged image generation. The model parameters of the image feature extraction module determine the model's ability to model spatial structure and texture, while the model parameters of the forged region identification module are responsible for mapping global features to the probability distribution of forged regions. Together, these three provide the foundation for the model's ability to identify forged regions.
[0078] After the gradient information is calculated by the automatic differentiation module, it is passed to the modules where the parameters are located. To avoid problems such as gradient explosion and oscillation during training, a gradient clipping strategy can be used to set an upper limit on the gradient amplitude. The parameters of the generator and the forged region identification module are particularly critical in this step, as the former is sensitive to image quality, while the latter highly relies on gradient stability for local classification output.
[0079] Optimization is performed by the adaptive optimization module, which uses algorithms such as Adam, RMSProp, or AdaBelief to dynamically adjust the learning rate, momentum factor, and parameter update direction during each training round, ensuring effective convergence of each module's parameters under a unified loss target. Training is concluded and a forgery detection model is output by continuously performing loss calculation, gradient backpropagation, and parameter updates until the joint loss value stabilizes over multiple rounds.
[0080] In the final model structure, the image feature extraction module and the forged area identification module contain optimized parameter configurations, and have the ability to automatically identify and locate forged information in real images during the deployment phase. Although the generator participates in training, its parameters will not be used in the deployment phase and only exist as a training auxiliary component.
[0081] In actual implementation, the training process begins with initializing the parameters of each module and constructing a joint loss function as the training objective. When using the PyTorch framework, the autograd module can be called to automatically generate gradient maps and perform backpropagation on all parameters in the generator, image feature extraction module, and forged region detection module. To prevent excessive gradients from affecting convergence, parameter gradients can be clipped using torch.nn.utils.clip_grad_norm_. The Adam optimizer can be used, with different learning rates set for each module (for example, 1e-4 for the generator and 5e-5 for the image feature extraction and forged region detection modules) to ensure that different modules converge according to different dynamic balances. Each training round performs forward propagation to obtain the joint loss, backpropagation to calculate the gradients, and parameter updates. This process is repeated until the loss curve converges or the training epoch limit is reached. Finally, the parameters of the image feature extraction and forged region detection modules are saved as part of the forged region detection model during the inference phase.
[0082] Example: In a fintech business scenario, users upload identification photos for account opening or authentication. The system can use this forgery detection model to process the image content and automatically identify forgeries such as document substitution and photo synthesis. During the training phase, the model, optimized using the joint loss, can not only determine the authenticity of the entire image but also accurately locate local forgeries, providing stronger technical support for automated risk control.
[0083] In healthcare scenarios, the model can be used to verify the credibility of radiology images, preventing malicious tampering with patient lesions or misdiagnosis data from entering the system. During training, the optimized image feature extraction module and recognition module work together to enhance the model's sensitivity to local image changes and its ability to determine the consistency of the overall structure, providing security for intelligent assisted diagnosis.
[0084] This embodiment integrates the generator parameters, image feature extraction module parameters, and forged region identification module parameters into the optimization path of a joint loss function, establishing a clear balance between image authenticity and forged region separability as the training objective of the entire model. This fully structured, participatory optimization mechanism significantly improves the detection model's adaptability to complex forged patterns and effectively avoids information disjunction between local feature recognition and global texture modeling.
[0085] S60: Process the image to be detected by using the forgery detection model to determine forgery information in the image to be detected.
[0086] In this embodiment, the image to be detected refers to an image input submitted by a user in actual business operations, whose source is uncertain. Its data structure maintains the same format as the image used in the training phase to ensure compatibility of the inference process. The forgery detection model is a model instance obtained through joint loss function optimization during the training phase. It contains an optimized image feature extraction module and a forged region identification module, capable of identifying and probabilistically mapping anomalous regions in the input image.
[0087] First, the image to be detected must be passed into the inference interface as the model's input tensor. Preprocessing involves unifying the size, normalizing the data range, and adjusting the channel order to ensure it meets the model's input requirements. The image feature extraction module uses multi-layer linear transformations, a self-attention mechanism, and positional encoding to output a global feature map that captures spatial context, providing rich structural and texture representations for subsequent modules.
[0088] This global feature map is then fed into the forged region identification module, which compares the feature representation at each location in the image with the true distribution learned during training. Specifically, a similarity mapping network, a feedforward discriminant structure, and a convolutional classification head are employed to independently predict the forgery probability for each location in the image, outputting an initial forgery probability map. This map reflects the confidence level of each pixel in the image that it is a forged region.
[0089] The forgery probability map can be further optimized for spatial continuity through morphological filtering, edge smoothing, and region merging to improve the ability to fit the boundaries of forged regions. Finally, binarization is performed based on the classification threshold, mapping the probability map into a binary mask. The spatial coordinate information contained in the mask can be further extracted to locate and output the forged regions in the image.
[0090] In actual deployment, this process is executed by an inference engine, such as by loading a model using TensorRT or ONNX Runtime. The image to be inspected is fed into the system via the image input interface. It first undergoes resizing and pixel normalization, for example, to a uniform size of 224×224 and compressing the pixel range to the [0, 1] range. The image feature extraction module is implemented based on a Transformer architecture. The forward computation includes patch embedding, positional encoding stacking, and a multi-head self-attention mechanism. Through stacked layers, it models the global receptive field and outputs a high-dimensional feature tensor that preserves spatial layout. This tensor is input to the forged region identification module, which can make predictions based on a convolutional classifier or a fully connected discriminant architecture, outputting a probability map with the same dimensionality as the input image. To improve visual continuity, the probability map is processed through an opening operation to remove noise and restored to the original size using bilinear interpolation. A forgery probability threshold of 0.5 is set, and each pixel is judged as forged, forming a final forgery mask. The system can further convert this mask into rectangular coordinate information or a set of keypoints to support subsequent intervention by the review system.
[0091] Example: In a financial business scenario, a user uploads a photo of their ID card through mobile banking. After receiving the image, the system automatically extracts global image features and identifies suspicious areas using a forgery detection model. If a high-confidence forgery area exists in the probability map, the corresponding coordinates are output for reference by the backend review system to prevent others from impersonating the user and completing high-risk operations.
[0092] In medical and health scenarios, when hospitals upload patient images for remote consultation, the system can automatically identify forged information, locate suspected tampered areas in image files, help identify whether there are image post-processing operations, prevent the risk of misdiagnosis, and protect the integrity and traceability of medical data.
[0093] This embodiment combines an optimized image feature extraction module and a forged region identification module to form a complete forgery detection model, enabling the system to possess strong forged information recognition capabilities when processing unknown images. This process automatically locates the precise location of forged regions within an image without relying on external databases or manual intervention, avoiding misjudgments based solely on overall image scoring and improving the model's robustness and detail perception in the presence of complex image interference.
[0094] The present invention relates to the field of artificial intelligence technology and can be applied to business scenarios such as financial technology and healthcare. Disclosed are a method, apparatus, device, and medium for image detection based on adversarial generation, comprising: generating forged image samples based on real image samples and constructing a training dataset through hybridization; constructing an image feature extraction module including a self-attention mechanism to perform global feature modeling on the training images; using a forged region identification module to compare the global feature differences between real and forged images to generate a forgery probability map; constructing a joint loss function based on the forgery probability map and the discriminator output; using the joint loss function to optimize the parameters of the generator, image feature extraction module, and forged region identification module to obtain a forgery detection model; and processing the image to be detected using the forgery detection model to identify forged information in the image. The present invention generates high-quality forged samples using a generative adversarial network, combines an image feature extraction module including a self-attention mechanism to achieve global feature modeling, and performs difference analysis using a forged region identification module to construct a joint optimization objective function. This improves the model's detection accuracy for local forged regions in images and its robustness to complex forged samples, meeting the demand for automated authenticity verification of image content in high-security scenarios such as finance and healthcare.
[0095] In one embodiment, the above step S10 includes:
[0096] S101, inputting a random noise vector and a real image sample into the generator of the generative adversarial network to generate an initial forged image sample;
[0097] S102, performing pixel-level feature matching analysis on the initial forged image sample using the discriminator of the generative adversarial network to generate an authenticity score matrix;
[0098] S103, dividing the authenticity score matrix into a plurality of image blocks, and determining an average score value of each image block;
[0099] S104, retaining image blocks whose average score values are within the threshold range according to a preset screening threshold range to generate a valid image block set;
[0100] S105, performing image reconstruction on the valid image block set to generate a valid forged image sample;
[0101] S106 , performing a normalization process on the valid forged image samples, and mixing the processed valid forged image samples with real image samples according to a preset ratio to generate a training data set.
[0102] In this embodiment, a high-quality training dataset must be constructed before model training to enable the forgery detection model to identify potential image manipulation. First, forged image samples are generated based on real image samples. These real image samples typically come from standard photography, authentication systems, or images verified after manual review. Their quality and authenticity form the basis for training. By inputting a random noise vector along with the real image samples into the generator of a generative adversarial network, images similar in style and content to the real images but containing certain forged features can be simulated, serving as the initial forged image samples.
[0103] To ensure that these initial forged image samples are meaningful and representative, they must be screened for validity. First, the discriminator in the generative adversarial network performs pixel-level feature matching analysis, scoring the authenticity of the forged image across the entire image, and generating an authenticity score matrix that reflects the authenticity distribution of each image region. This matrix is then partitioned into multiple image blocks using spatial partitioning, and the average score is calculated for each block to assess the degree of forgery in the local image.
[0104] To eliminate areas with severe distortion or failed attempts to generate artifacts, these scores are filtered according to a preset threshold range, retaining only image blocks with average scores within that range. These blocks constitute a valid set of image blocks, demonstrating high visual usability and representativeness of artifact characteristics. Next, these valid image blocks are stitched together through an image reconstruction process to form a new, complete image, which is then output as a valid artifact image sample.
[0105] Ultimately, in order to ensure the consistency of the training data and the modeling performance, these effective forged image samples need to be standardized and normalized, including color balancing, pixel value normalization to a specific interval, channel alignment and other operations, and mixed with real image samples in a set proportion to form a training data set that can be used for subsequent feature modeling and discriminant training.
[0106] In practice, the random noise vector can be drawn from a normal or uniform distribution, and its dimensionality is determined by the generator architecture. The noise vector is concatenated with the selected real image and fed into a generator based on a convolutional or Transformer architecture, outputting an initial forged image sample. The discriminator processes the generated image using multiple layers of convolution or a discriminant scoring module, outputting a matrix of authenticity scores consistent with the image resolution. Blocking can be performed using a sliding window or a fixed grid, for example, with each 32×32 pixel block being a single block. The pixel scores within the corresponding area are averaged. A screening threshold can be set, for example, to [0.3, 0.7] to exclude areas with excessively low and high scores, ensuring that the forged image blocks are both distracting and realistic. Selected image blocks are reconstructed using an image stitching algorithm, such as maintaining the original block arrangement or performing structural alignment. Normalization involves scaling the image pixel values to [0, 1] or [-1, 1] and adjusting the image size and channel order to align with the model training criteria. The mixing ratio can be set to, for example, 1:1, meaning each batch contains an equal number of real images and forged images, improving the model's ability to generalize learning of forged features.
[0107] This embodiment uses a generator to construct valid image samples with forgery characteristics during the training phase, and combines these with real images to form a mixed training dataset. This enables the forgery detection model to establish a clear feature boundary between real and forged images. This training strategy not only improves the model's sensitivity to changes in local details but also significantly enhances its ability to detect unknown forged samples. The valid image block screening and reconstruction mechanism further ensures the quality of the training samples, preventing noise or invalid forgeries from affecting the model's learning performance.
[0108] In one embodiment, the above step S20 includes:
[0109] S201, dividing the images in the training data set into a grid-like image block sequence;
[0110] S202, converting the image blocks in the grid-like image block sequence into initial feature vectors through a linear projection layer to form an initial feature vector sequence;
[0111] S203, inserting a position encoding vector into the initial feature vector sequence to generate a spatial perception feature sequence;
[0112] S204, determining a correlation weight matrix between any two feature vectors in the spatial perception feature sequence through a multi-layer self-attention module;
[0113] S205 , performing weighted fusion on the spatial perception feature sequence according to the association weight matrix to generate a global feature map.
[0114] In this embodiment, to improve the model's ability to identify forged detail areas in images, it is necessary to construct an image feature extraction module with global modeling capabilities and introduce a self-attention mechanism into this module to capture long-range dependencies between image blocks. The image is first processed into a grid-like sequence of image blocks. This involves dividing the input image into multiple sub-regions of uniform size at a fixed resolution. Each image block not only contains its pixel information but also retains its original two-dimensional spatial position within the entire image for subsequent position encoding.
[0115] Each image patch is treated as an independent input unit and transformed into an initial feature vector through a linear projection layer, thus forming a complete sequence of initial feature vectors. This linear projection operation is implemented based on a trainable parameter matrix and can compress the original pixel representation of the image patch while preserving the underlying semantic structure.
[0116] To enable the model to perceive the spatial positional relationships of image patches, each initial feature vector must be imbued with corresponding positional information. A set of positional encoding vectors is inserted into the feature vector sequence to generate a feature sequence capable of perceiving spatial structure. This positional encoding can be implemented using sine and cosine functions, or the optimal positional representation can be dynamically learned using learnable parameters.
[0117] Next, a module consisting of multiple self-attention layers is used to model this sequence of spatially perceptual features. Within each self-attention module, the similarity between any two feature vectors is calculated to form a correlation weight matrix, which is used to measure the global correlation between image patches. This correlation weight matrix not only considers content similarity but also incorporates positional information to guide attention allocation, thereby adapting to cross-region correlations in complex image structures.
[0118] Finally, a weighted fusion operation is performed on all feature vectors based on the aforementioned association weights, enabling the representation of each image patch to incorporate global contextual semantics. The fused feature sequence is reconstructed and mapped into a two-dimensional structure, outputting a global feature map for subsequent processing. This feature map has a resolution aligned with the original image structure and preserves contextual information and fine-grained forgery cues.
[0119] In practice, the input image resolution can be set to 224×224. After being divided into 16×16 image blocks, each block is 14×14 pixels in size. Each image block is flattened into a vector using a flatten operation and then mapped to an initial feature vector of length 768 through a linear layer. All feature vectors are arranged in sequence and inserted into the corresponding positional encoding vector before being passed to a three-layer Transformer Encoder. Each layer contains a multi-head self-attention mechanism and a feedforward network structure. The self-attention module uses the QKV trilinear transformation to generate the attention matrix, which is normalized using the softmax function before feature aggregation. The output fused feature sequence is reconstructed into a two-dimensional feature map with a size of 14×14×768 or upsampled to the original image resolution for use in subsequent modules. Positional encoding uses either fixed sinusoidal encoding or learnable embeddings, both of which support backpropagation training.
[0120] This embodiment divides the image into structured blocks and integrates a self-attention mechanism, enabling the model to perceive semantic associations across regions in the image during learning, thereby improving its ability to jointly model global structure and local perturbations. The context aggregation process guided by the association weight matrix not only enhances the robustness of feature representation but also improves the perception of low-intensity forged areas, thereby enhancing the overall detection model's accuracy in identifying fine-grained forged information.
[0121] In one embodiment, the above step S30 includes:
[0122] S301, extracting feature maps of different spatial resolutions from the global feature map;
[0123] S302, performing a channel splicing operation on the feature maps with different spatial resolutions to generate an enhanced feature map;
[0124] S303, comparing the enhanced feature map of the real image with the enhanced feature map of the forged image by the cosine similarity analysis module in the forged region identification module to generate a difference response matrix;
[0125] S304, performing normalization processing on the difference response matrix to generate a normalized difference map;
[0126] S305 , upsampling the normalized difference map to the original resolution of the images in the training dataset using a bilinear interpolation method to generate a forgery probability map.
[0127] In this embodiment, in order to improve the spatial positioning capability of the forged area, it is necessary to perform semantic difference analysis operations across image samples based on the constructed global feature map. First, feature representations of multiple scales are extracted from the global feature map. These feature maps of different spatial resolutions can be obtained by selecting the hierarchical outputs of different depths in the image feature extraction module. Feature maps of different resolutions have different receptive fields and information densities, which can capture semantic contours at low resolution and depict local details at high resolution, thereby providing multi-level contextual support for subsequent difference analysis.
[0128] In order to integrate the rich information structure of features at all scales, all feature maps of different spatial resolutions are spliced according to the channel dimension to construct an enhanced feature map. The splicing operation can be completed by the tensor splicing function, so that the final enhanced feature map contains more dimensional information expression capabilities while maintaining the original spatial distribution. Figure 1 The images are sent one by one to the cosine similarity analysis module in the forged region identification module for comparison. This module is used to calculate the cosine value of the angle between the feature vectors at each corresponding position, thereby measuring the similarity of the feature expression of the two images in the same region.
[0129] Cosine similarity analysis generates a difference response matrix, where each position value reflects the degree of feature difference between the corresponding region in the real image and the forged image. Because the difference response matrix may have inconsistent values, it requires normalization to keep all values within a fixed range, typically between 0 and 1. Normalization can be performed using linear scaling of minimum and maximum values or standard deviation normalization to ensure that the output features have a uniform dimension, facilitating integration with subsequent operational modules.
[0130] The normalized difference map maintains the same spatial resolution as the enhanced feature map. To align it with the original training image, it is upsampled to the original training image resolution using bilinear interpolation. In this operation, the value of each pixel position is obtained by taking the weighted average of the four adjacent sampling points, ensuring smooth image boundaries and structural continuity during the upscaling process. The final output forgery probability map aligns with the spatial dimensions of the input image and provides pixel-by-pixel forgery probability estimation, providing a precise positioning basis for subsequent forgery region detection or segmentation modules.
[0131] In the specific implementation process, the global feature map can be derived from the Transformer output results of different layers of the image feature extraction module. The outputs of the last three layers can be spatially downsampled to a resolution of 1 / 4, 1 / 8, and 1 / 16 of the original image size, respectively. The feature maps at the three scales are spliced in the channel direction to construct an enhanced feature map with the total number of channels. For each pair of real and forged image samples, the enhanced feature map is extracted and sent to the cosine similarity analysis module. The difference response matrix is generated by calculating the cosine similarity pixel by pixel. After the min-max normalization operation, the matrix is resized to the original image size of 224×224 using the bilinear interpolation function in PyTorch to form the final forgery probability map output. During deployment, it can also support efficient interpolation modules based on engines such as TensorRT to ensure efficient image resizing during the inference phase.
[0132] This embodiment significantly improves the model's ability to identify complex forgeries, such as structural misalignment and boundary forgeries, by concatenating multi-scale feature maps and then performing inter-image feature comparison. Cosine similarity, a dimensionless measure of semantic similarity, is suitable for capturing subtle differences between deep features. The forgery probability map generated through normalization and bilinear interpolation is not only spatially consistent with the input image but also possesses high semantic resolution, helping subsequent forgery localization and trusted region screening modules further optimize detection performance.
[0133] In one embodiment, the above step S40 includes:
[0134] S401, performing log-likelihood analysis on the forgery probability of each pixel in the forgery probability map to generate a pixel-level detection loss value;
[0135] S402, performing authenticity classification on the generated image through the discriminator of the generative adversarial network, and outputting an image-level adversarial loss value;
[0136] S403, determining a detection loss weighting coefficient and an adversarial loss weighting coefficient based on an exponential decay strategy of a current training round;
[0137] S404, performing weighted processing on the pixel-level detection loss value according to the detection loss weighting coefficient to generate a weighted detection loss value;
[0138] S405, performing weighted processing on the image-level adversarial loss value according to the adversarial loss weighting coefficient to generate a weighted adversarial loss value;
[0139] S406: Linearly superimpose the weighted detection loss value and the weighted adversarial loss value to generate a joint training loss function.
[0140] In this embodiment, in order to make the forgery detection model more optimizable, it is necessary to fuse the forgery probability map with the adversarial training signal to generate a joint training loss function that can be used for gradient propagation. First, the loss value of the forgery probability map is calculated. Each pixel value in the forgery probability map represents the probability that the position is judged to be forged, and the pixel value range is usually between 0 and 1. These probability values are subjected to pixel-by-pixel log-likelihood analysis with the true annotation values (such as binary masks) to measure the consistency between the predicted forgery probability and the true forgery area, and obtain the pixel-level detection loss value. This loss value retains the spatial position information and can effectively guide the feature extraction module and the forgery area identification module to optimize when discriminating boundary features through the back propagation process.
[0141] Meanwhile, during training, the GAN's discriminator receives the generator's output image and a real image. It classifies the image as real or fake based on its overall structural features or texture distribution. Its output is a authenticity score for each image. This score is then matched with the image label to calculate an image-level adversarial loss, which reflects whether the generator has successfully "tricked" the discriminator at the overall image level.
[0142] Because pixel-level detection and image-level authenticity judgment focus on different dimensions, separate loss weighting is required. Taking into account the dynamic nature of training, an exponential decay strategy is introduced. The weighting coefficients of the two losses are controlled by the current number of training rounds. In the early stages of training, the adversarial loss is weighted higher to encourage the generator to learn the overall structural regularities. Later, the weight of the detection loss is gradually increased to optimize the localization of detailed forgeries. This exponential decay strategy can be achieved by nonlinearly mapping the training rounds using an exponential function.
[0143] The detection loss and adversarial loss are weighted according to their respective weighting coefficients to generate a weighted detection loss and a weighted adversarial loss. These two are then linearly superimposed to form a joint training loss function. This allows the model to simultaneously optimize its ability to discriminate local forged regions and perceive global image authenticity under a unified objective, enhancing overall detection robustness.
[0144] In actual implementation, the detection loss value can use loss functions such as Binary Cross Entropy or Focal Loss that are suitable for binary classification pixel annotation, and perform loss calculation on each pixel in the forgery probability map. The real forgery area mask can come from manual annotation or other annotation strategies. The adversarial loss value can use Wasserstein loss or Binary Cross Entropy loss in the original GAN to calculate the degree of match between the discriminator output and the image label. In the exponential decay strategy of the weighted coefficient, the detection loss weight can use the function form α(t) = 1-exp(-λ·t), and the adversarial loss weight is 1-α(t), where t is the number of training rounds and λ is a hyperparameter that controls the decay rate. The above two weighted values are applied to the two sub-losses and then linearly superimposed. Finally, they are input into the optimizer as an overall loss term for the gradient backpropagation of the model parameters.
[0145] This embodiment combines local pixel-level forgery discrimination with overall image discrimination results to construct a unified loss function. This fully integrates information feedback from both microscopic and macroscopic dimensions during training, enhancing the model's overall ability to identify complex forged structures. An exponential decay strategy is introduced to dynamically adjust the loss weights, allowing the model to focus on structural learning and detail optimization at different training stages. This improves the adaptability and robustness of the final model in practical detection tasks and avoids overfitting to a single type of forgery signature.
[0146] In one embodiment, the above step S50 includes:
[0147] S501, determining, by an automatic differentiation module, the gradient direction and gradient magnitude of the joint loss function with respect to the generator parameters of the generative adversarial network, the model parameters of the image feature extraction module, and the model parameters of the forged region identification module;
[0148] S502, performing threshold constraints on the gradient amplitudes of the generator parameters and the model parameters of the forged region identification module respectively through a gradient clipping module to generate a modified generator gradient and a modified identification module gradient;
[0149] S503, updating, by an adaptive optimization module, the generator parameters of the generative adversarial network, the model parameters of the image feature extraction module, and the model parameters of the forged region identification module according to the corrected generator gradient, the gradient amplitude of the image feature extraction module, and the corrected identification module gradient;
[0150] S504 , repeatedly performing a gradient determination operation, a gradient correction operation, and a parameter update operation until the joint loss function converges, and outputting a forgery detection model including an optimized image feature extraction module and an optimized forgery region identification module.
[0151] In this embodiment, to build a forgery detection model with end-to-end training capabilities, the model parameters of the generator, image feature extraction module, and forged region identification module are uniformly optimized using a joint loss function. This process first uses an automatic differentiation mechanism to calculate the gradient direction and gradient magnitude of the joint loss function with respect to the three parameters. The automatic differentiation module is typically implemented using a directed computation graph, which captures the dependency paths between all model parameters and the loss, achieving high-precision chain differentiation.
[0152] To prevent gradient explosion or unstable oscillation during training, threshold constraints are introduced on the gradient amplitudes of the generator parameters and the forged region identification module after the gradient calculation is completed. Specifically, the gradient clipping module uses the L2 norm constraint to scale any gradient vectors exceeding the set threshold to a safe range, thereby generating corrected generator gradients and corrected identification module gradients. This correction operation can significantly improve the numerical stability of the training process, which is particularly critical in adversarial training.
[0153] Subsequently, an adaptive optimization module is used to synchronously update the three parameter types. For the generator and forged region identification modules, weight adjustments are performed using the corrected gradient values. For the image feature extraction module, the gradients are directly optimized without clipping. This optimization module utilizes adaptive learning rate optimization algorithms such as Adam or RMSprop, enabling dynamic parameter updates to adapt to changes in gradient distribution during different training stages.
[0154] The entire training process involves repeated gradient determination, gradient correction, and parameter updates, using an iterative optimization strategy to ensure the joint loss function converges continuously until it reaches a stable optimal state. The final forgery detection model includes an optimized image feature extraction module and forged region identification module, eliminating the generator structure required during the training phase, making it easier to deploy and use for inference.
[0155] During the training of an image forgery detection model, determining whether the model has converged is a crucial criterion for ensuring training effectiveness and avoiding overfitting. Generally, convergence means that the model's joint loss function stabilizes with increasing training epochs, and its decline gradually decreases over a certain number of consecutive training cycles, ultimately fluctuating within a small constant range. For example, a consistent decline in the joint loss value over five consecutive training epochs can be used as a criterion for loss function convergence. Furthermore, in a multi-module joint training architecture, not only does the overall loss function need to be stable, but the gradient updates of the sub-modules must also be stable. In practice, monitoring the L2 norm of the gradients of each parameter in the model can be used to ensure that they consistently decrease and saturate. If they fluctuate within a certain range or remain close to zero for a long period, the parameter gradients can be considered to have converged. Furthermore, the stability of performance metrics such as forgery detection accuracy, recall, or F1 score on the validation set is also an important indicator of convergence. If the model's metrics on the validation set do not show significant improvement over multiple training epochs, it can be considered converged. For the joint training structure that includes the generator, image feature extraction module, and forged region identification module, it is also important to note whether the discriminator output is oversaturated. For example, if the classification results are continuously output close to 0 or 1, it may indicate that the game between the generator and the discriminator has reached a state of equilibrium. In actual deployment, the early stopping mechanism can be set by combining the loss convergence threshold, the stability of the validation set performance, and the gradient change trend. If the validation set performance indicator does not improve after ten consecutive rounds of training, it can trigger early stopping of training.
[0156] In specific implementations, the automatic differentiation module can be built based on the backpropagation mechanism in deep learning frameworks. After recording the forward propagation path in the computation graph, the system automatically calculates the partial derivatives of the joint loss function with respect to the parameters of each module. The gradient clipping module allows for independent maximum gradient norm thresholds for the generator and recognition modules, such as 5.0 or 10.0. This can be set dynamically based on model scale and training data distribution. Clipping can be performed using either constant threshold clipping or dynamic clipping based on a sliding average. The initial learning rate, momentum parameter, and decay strategy used in the adaptive optimization module can be customized for each module. For example, the initial learning rate of the generator can be lower than that of the recognition module to maintain adversarial balance. In multiple iterations, the gradient calculation, clipping, and parameter update processes are fully executed in each round. The convergence criterion for the loss function can be set as stable loss on the validation set or as a preset upper limit on the number of iterations. Once the model converges, the generator is no longer used during inference, and the forgery detection model consists solely of the image feature extraction module and the forged region identification module, thereby improving inference efficiency and deployment adaptability.
[0157] This embodiment uses a joint optimization mechanism to unify the training objectives of the generator, image feature extraction module, and forged region identification module into a joint loss function. This enables feature sharing and gradient synergy across multiple modules during training, improving the overall performance of the detection model. Automatic differentiation ensures the accuracy of gradient calculations, while gradient clipping enhances the stability of model training. Adaptive optimization further improves parameter convergence efficiency, resulting in a forgery detection model that achieves optimal structural rationality and robust performance, adapting to the practical needs of complex image forgery scenarios.
[0158] In one embodiment, the above step S60 includes:
[0159] S601, receiving the input image to be detected;
[0160] S602, extracting a global feature map of the image to be detected by an image feature extraction module in the forgery detection model;
[0161] S603, performing classification analysis on the global feature map by the forgery region identification module in the forgery detection model to generate an initial forgery probability map;
[0162] S604, performing a morphological post-processing operation on the initial forgery probability map to generate an optimized forgery probability map;
[0163] S605 : Determine coordinate information of a forged region in the image to be detected according to the optimized forgery probability map and a preset classification threshold.
[0164] In this embodiment, when the forgery detection model completes training and enters the inference phase, it first receives input image data. This input can come from an image acquisition device, a local upload, or a remote transmission interface, and can be in JPEG, PNG, BMP, or other supported image formats. The received image, serving as the image to be detected, is then fed into the model's internal image feature extraction module. This module, a structure acquired during the training process, possesses global modeling capabilities and uses a self-attention mechanism to encode features of spatial regions in the image and extract structured representations, forming a feature map that contains the image's global semantics and texture. This feature map is then fed into the forgery region identification module, which includes a comparison mechanism and a forgery classifier. Based on the previously learned difference distribution between real and forged images, it converts the global feature map into an initial forgery probability map. This map represents the probability that each pixel or region in the image is predicted to be forged.
[0165] To improve the spatial consistency and boundary smoothness of the forgery probability map, morphological post-processing operations are performed on the initial forgery probability map. These operations include erosion, dilation, opening, or closing, among other image space operations. The goal is to remove noise, fill holes, and enhance the coherence of structural regions, making the final output forged regions more accurate and coherent. The resulting image is the optimized forgery probability map. Finally, by comparing it with a preset classification threshold, regions with probability values above the threshold are labeled as forgeries. The coordinates of the forgery regions are mapped to their spatial positions in the image and are typically output as pixel coordinates, bounding boxes, or masks for subsequent processing, alerts, or manual review.
[0166] Various configurations can be used to adapt to the detection needs of different scenarios. For example, in mobile deployments, the image feature extraction module can be compressed into a lightweight ViT structure to reduce computational overhead, while limiting the resolution of the forgery probability map to improve processing speed. In the forgery region identification module, a discriminator based on convolutional attention fusion can be selected to adapt to input images with weak edge features and subtle texture variations in some scenarios. The kernel size and operation type of morphological post-processing operations can also be adjusted based on image content. For low-resolution document scans, a smaller convolution kernel and closing operations can be used to smooth edges; for high-resolution facial images, opening operations and multiple rounds of erosion and dilation can be used to enhance edge clarity. Furthermore, the classification threshold can be dynamically adjusted based on business risk tolerance. For example, in a bank account opening system, a lower threshold can be used to improve recall, while in health record image review, a higher threshold can be used to reduce false positives. Forgery region coordinate information can be directly output as a mask for rendering and display, or as structured data for integration into risk control processes.
[0167] Example: In financial services, such as remote bank account opening, users are required to upload photos of their ID cards, both front and back, and holding them for identity verification. The system first collects a large number of real ID card image samples as a training basis. Using a generative adversarial network, the system constructs multiple forged image samples, including visual forgeries such as splicing a real face onto another ID card or imitating font watermarks. When constructing the training dataset, the generated images are filtered by a discriminator, retaining only those with authenticity scores within a specified confidence interval. This improves the deceptiveness and distributional plausibility of the training samples. The training data is processed by the image feature extraction module, which uses a self-attention mechanism to model global image information, extract spatial semantic features, and generate a feature map. After comparing the feature maps of the real and forged images, the forged region identification module generates a forgery probability map based on multi-scale enhanced features and cosine similarity. The forgery probability map is then upsampled to restore the image to the original ID resolution. During training, the forgery probability map and the discriminator output are used to construct the detection loss and adversarial loss, respectively. The weighting of the two is dynamically adjusted based on the number of training rounds, forming a joint loss function. Ultimately, the forgery detection model completed training using backpropagation optimization. After deployment, when a user uploads an ID card image, the system uses the forgery detection model to extract image features and generate a forgery probability map. Morphological processing is then used to improve the spatial consistency of forged areas in the image. A threshold of 0.5 is then used to define the region boundaries. Finally, the coordinates of suspected forgeries in the image are output, which the risk control system can use to trigger a secondary review or as a basis for customer service notifications. This mechanism significantly improves the ability to identify forgeries such as AI-powered face-swapping and image splicing, reducing the risk of account fraud caused by lax review of forged materials.
[0168] During remote diagnosis and online medical insurance claims, patients are required to upload critical medical documentation such as pathology reports, imaging scans, and handwritten medical instructions. Considering that image forgeries could mask medical conditions, exaggerate diagnoses, or alter medical records, the medical system has deployed an image forgery detection model to mitigate the risk of image fraud. The system first trains a generative adversarial network using a large number of real medical record images. Forged images are generated by adding lesion locations, rewriting diagnoses, and inserting non-standard annotations. Typical blocks within the generated images are selected to construct a training dataset. The image feature extraction module performs spatial modeling to capture latent forgery features such as grayscale variations, structural defects, and contrast inconsistencies. A difference map is constructed between the real and forged images, which is normalized and upsampled to the original medical image size to generate a high-precision forgery probability map. During the training phase, a joint loss function is used to optimize the generator, image feature extraction module, and forged region identification module. The model is able to distinguish between normal text noise and manual manipulation. Once operational, the system automatically detects forgeries on uploaded medical images. If it detects obvious signs of localized tampering (e.g., changes to medical insurance amounts or altered QR codes) in an image, it locates the corresponding forged areas and annotates them on the platform's backend as a basis for review, allowing for manual review by reviewing doctors or insurance claims auditors. This effectively improves the efficiency of online medical imaging material review and ensures the credibility of diagnosis and treatment data. It is particularly applicable to key processes such as remote medical review, electronic medical record archiving verification, and consistency checks on medical insurance image materials, helping to enhance the security boundaries and service quality of online diagnosis and treatment systems.
[0169] Through the above steps, this embodiment achieves an automated detection process from image input to forged region output, demonstrating excellent generalization and detail perception capabilities. The forgery detection model fully leverages the differential features extracted during the training phase, rapidly processing the input image during the inference phase and outputting forged region information with spatial localization accuracy. The introduction of morphological operations enhances the continuity of forged region boundaries and the interpretability of confidence maps. The classification threshold mechanism enables flexible configuration of the system based on business risk, achieving a balance between real-time performance and stability while maintaining accuracy.
[0170] In one embodiment, an image detection device based on adversarial generation is provided, and the image detection device based on adversarial generation corresponds one-to-one to the image detection method based on adversarial generation in the above embodiment. Figure 3 , Figure 3 This is a schematic diagram of the functional modules of a preferred embodiment of the adversarial generative image detection device of the present invention. These include a generative adversarial module 10, an image feature extraction module 20, a forged region identification module 30, a joint loss construction module 40, a parameter optimization module 50, and a forged detection model processing module 60. Each functional module is described in detail below:
[0171] A generative adversarial module 10 is configured to generate forged image samples based on real image samples through a generative adversarial network, and mix the forged image samples with real image samples to form a training dataset;
[0172] An image feature extraction module 20 is configured to construct an image feature extraction module including a self-attention mechanism, and perform global feature modeling on the images in the training dataset through the image feature extraction module to generate a global feature map;
[0173] a forged region identification module 30 for generating a forged probability map by comparing the global feature differences between the real image and the forged image through the forged region identification module based on the global feature map;
[0174] A joint loss construction module 40 is configured to generate a detection loss value using the forgery probability map and construct a joint loss function in combination with the adversarial loss value output by the discriminator of the generative adversarial network;
[0175] a parameter optimization module 50 for performing back-propagation optimization on the generator parameters of the generative adversarial network, the model parameters of the image feature extraction module, and the model parameters of the forged region identification module based on the joint loss function to obtain a forged detection model;
[0176] The forgery detection model processing module 60 is configured to process the image to be detected using the forgery detection model to determine forgery information in the image to be detected.
[0177] In one embodiment, the generation adversarial module 10 is specifically configured to:
[0178] Inputting a random noise vector and a real image sample into the generator of the generative adversarial network to generate an initial forged image sample;
[0179] Performing pixel-level feature matching analysis on the initial forged image sample using the discriminator of the generative adversarial network to generate an authenticity score matrix;
[0180] Dividing the authenticity score matrix into a plurality of image blocks and determining an average score value for each image block;
[0181] According to a preset screening threshold interval, image blocks whose average score values are within the threshold range are retained to generate a valid image block set;
[0182] Performing image reconstruction on the valid image block set to generate a valid forged image sample;
[0183] The effective forged image samples are normalized and mixed with real image samples according to a preset ratio to generate a training data set.
[0184] In one embodiment, the image feature extraction module 20 is specifically configured to:
[0185] Dividing the images in the training data set into a grid-like image block sequence;
[0186] Converting image blocks in the grid-like image block sequence into initial feature vectors through a linear projection layer to form an initial feature vector sequence;
[0187] Inserting a position encoding vector into the initial feature vector sequence to generate a spatial perception feature sequence;
[0188] Determining the association weight matrix between any two feature vectors in the spatial perception feature sequence through a multi-layer self-attention module;
[0189] The spatial perception feature sequence is weightedly fused according to the association weight matrix to generate a global feature map.
[0190] In one embodiment, the counterfeit area identification module 30 is specifically configured to:
[0191] Extracting feature maps of different spatial resolutions from the global feature map;
[0192] Performing a channel splicing operation on the feature maps with different spatial resolutions to generate an enhanced feature map;
[0193] Comparing the enhanced feature map of the real image with the enhanced feature map of the forged image using the cosine similarity analysis module in the forged region identification module to generate a difference response matrix;
[0194] performing normalization processing on the difference response matrix to generate a normalized difference map;
[0195] The normalized difference map is upsampled to the original resolution of the images in the training dataset using bilinear interpolation to generate a forgery probability map.
[0196] In one embodiment, the joint loss construction module 40 is specifically configured to:
[0197] Performing log-likelihood analysis on the forgery probability of each pixel in the forgery probability map to generate a pixel-level detection loss value;
[0198] Performing authenticity classification on the generated image through the discriminator of the generative adversarial network and outputting an image-level adversarial loss value;
[0199] Determine the detection loss weighting coefficient and the adversarial loss weighting coefficient based on the exponential decay strategy of the current training round;
[0200] Performing weighted processing on the pixel-level detection loss value according to the detection loss weighting coefficient to generate a weighted detection loss value;
[0201] Performing weighted processing on the image-level adversarial loss value according to the adversarial loss weighting coefficient to generate a weighted adversarial loss value;
[0202] The weighted detection loss value and the weighted adversarial loss value are linearly superimposed to generate a joint training loss function.
[0203] In one embodiment, the parameter optimization module 50 is specifically configured to:
[0204] Determining the gradient direction and gradient amplitude of the joint loss function on the generator parameters of the generative adversarial network, the model parameters of the image feature extraction module, and the model parameters of the forged region identification module respectively through an automatic differentiation module;
[0205] Performing threshold constraints on the gradient amplitudes of the generator parameters and the model parameters of the forged region identification module through a gradient clipping module to generate a modified generator gradient and a modified identification module gradient;
[0206] updating, by an adaptive optimization module, the generator parameters of the generative adversarial network, the model parameters of the image feature extraction module, and the model parameters of the forged region identification module according to the modified generator gradient, the gradient amplitude of the image feature extraction module, and the modified identification module gradient;
[0207] Repeating the gradient determination operation, the gradient correction operation, and the parameter update operation until the joint loss function converges, outputting a forgery detection model including an optimized image feature extraction module and an optimized forgery region identification module.
[0208] In one embodiment, the forgery detection model processing module 60 is specifically configured to:
[0209] receiving the input image to be detected;
[0210] Extracting a global feature map of the image to be detected by an image feature extraction module in the forgery detection model;
[0211] Performing classification analysis on the global feature map by using the forgery region recognition module in the forgery detection model to generate an initial forgery probability map;
[0212] performing a morphological post-processing operation on the initial forgery probability map to generate an optimized forgery probability map;
[0213] The coordinate information of the forged region in the image to be detected is determined according to the optimized forgery probability map and a preset classification threshold.
[0214] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 4 As shown. The computer device includes a processor, memory, network interface and database connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes non-volatile and / or volatile storage media and internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external user terminal via a network connection. When the computer program is executed by the processor, it realizes the functions or steps on the server side of an image detection method based on adversarial generation.
[0215] In one embodiment, a computer device is provided. The computer device may be a user terminal, and its internal structure diagram may be as follows: Figure 5 As shown. The computer device includes a processor, memory, network interface, display screen and input device connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external server via a network connection. When the computer program is executed by the processor, it realizes the functions or steps on the user side of an image detection method based on adversarial generation.
[0216] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the following steps are performed:
[0217] Based on the real image samples, generating fake image samples through a generative adversarial network, and mixing the fake image samples with the real image samples to form a training dataset;
[0218] Constructing an image feature extraction module including a self-attention mechanism, performing global feature modeling on the images in the training dataset through the image feature extraction module to generate a global feature map;
[0219] Based on the global feature map, a forged region identification module is used to compare the global feature differences between the real image and the forged image to generate a forgery probability map;
[0220] Generating a detection loss value through the forgery probability map, and constructing a joint loss function in combination with the adversarial loss value output by the discriminator of the generative adversarial network;
[0221] Performing backpropagation optimization on the generator parameters of the generative adversarial network, the model parameters of the image feature extraction module, and the model parameters of the forged region identification module based on the joint loss function to obtain a forgery detection model;
[0222] The image to be detected is processed by the forgery detection model to determine forgery information in the image to be detected.
[0223] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented:
[0224] Based on the real image samples, generating fake image samples through a generative adversarial network, and mixing the fake image samples with the real image samples to form a training dataset;
[0225] Constructing an image feature extraction module including a self-attention mechanism, performing global feature modeling on the images in the training dataset through the image feature extraction module to generate a global feature map;
[0226] Based on the global feature map, a forged region identification module is used to compare the global feature differences between the real image and the forged image to generate a forgery probability map;
[0227] Generating a detection loss value through the forgery probability map, and constructing a joint loss function in combination with the adversarial loss value output by the discriminator of the generative adversarial network;
[0228] Performing backpropagation optimization on the generator parameters of the generative adversarial network, the model parameters of the image feature extraction module, and the model parameters of the forged region identification module based on the joint loss function to obtain a forgery detection model;
[0229] The image to be detected is processed by the forgery detection model to determine forgery information in the image to be detected.
[0230] It should be noted that the above functions or steps that can be implemented by the computer-readable storage medium or computer device can be found in the relevant descriptions of the server side and the user side in the aforementioned method embodiment. To avoid repetition, they will not be described one by one here.
[0231] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0232] Those skilled in the art will clearly understand that for the sake of convenience and brevity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0233] It should be noted that if any software tools or components other than those of the Company appear in the embodiments of this application, they are merely for illustration and do not represent actual use. The above embodiments are intended only to illustrate the technical solutions of the present invention, not to limit them. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or replace some of the technical features therein with equivalents. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the scope of protection of the present invention.
Claims
1. An image detection method based on adversarial generation, characterized in that: The following steps are involved: Based on the real image samples, generating fake image samples through a generative adversarial network, and mixing the fake image samples with the real image samples to form a training dataset; Constructing an image feature extraction module including a self-attention mechanism, performing global feature modeling on the images in the training dataset through the image feature extraction module to generate a global feature map; Based on the global feature map, a forged region identification module is used to compare the global feature differences between the real image and the forged image to generate a forgery probability map; Generating a detection loss value through the forgery probability map, and constructing a joint loss function in combination with the adversarial loss value output by the discriminator of the generative adversarial network; Performing backpropagation optimization on the generator parameters of the generative adversarial network, the model parameters of the image feature extraction module, and the model parameters of the forged region identification module based on the joint loss function to obtain a forgery detection model; The image to be detected is processed by the forgery detection model to determine forgery information in the image to be detected.
2. The image detection method based on adversarial generation according to claim 1, characterized in that: Based on real image samples, forged image samples are generated by a generative adversarial network, and the forged image samples are mixed with real image samples to form a training dataset, including: Inputting a random noise vector and a real image sample into the generator of the generative adversarial network to generate an initial forged image sample; Performing pixel-level feature matching analysis on the initial forged image sample using the discriminator of the generative adversarial network to generate an authenticity score matrix; Dividing the authenticity score matrix into a plurality of image blocks and determining an average score value for each image block; According to a preset screening threshold interval, image blocks whose average score values are within the threshold range are retained to generate a valid image block set; Performing image reconstruction on the valid image block set to generate a valid forged image sample; The effective forged image samples are normalized and mixed with real image samples according to a preset ratio to generate a training data set.
3. The image detection method based on adversarial generation according to claim 1, characterized in that: Constructing an image feature extraction module including a self-attention mechanism, performing global feature modeling on the images in the training dataset through the image feature extraction module to generate a global feature map, including: Dividing the images in the training data set into a grid-like image block sequence; Converting image blocks in the grid-like image block sequence into initial feature vectors through a linear projection layer to form an initial feature vector sequence; Inserting a position encoding vector into the initial feature vector sequence to generate a spatial perception feature sequence; Determining the association weight matrix between any two feature vectors in the spatial perception feature sequence through a multi-layer self-attention module; The spatial perception feature sequence is weightedly fused according to the association weight matrix to generate a global feature map.
4. The image detection method based on adversarial generation according to claim 1, wherein: Based on the global feature map, a forged region identification module compares the global feature differences between the real image and the forged image to generate a forgery probability map, including: Extracting feature maps of different spatial resolutions from the global feature map; Performing a channel splicing operation on the feature maps with different spatial resolutions to generate an enhanced feature map; Comparing the enhanced feature map of the real image with the enhanced feature map of the forged image using the cosine similarity analysis module in the forged region identification module to generate a difference response matrix; performing normalization processing on the difference response matrix to generate a normalized difference map; The normalized difference map is upsampled to the original resolution of the images in the training dataset using bilinear interpolation to generate a forgery probability map.
5. The image detection method based on adversarial generation according to claim 1, wherein: The detection loss value is generated by the forgery probability map, and the adversarial loss value output by the discriminator of the generative adversarial network is combined to construct a joint loss function, including: Performing log-likelihood analysis on the forgery probability of each pixel in the forgery probability map to generate a pixel-level detection loss value; Performing authenticity classification on the generated image through the discriminator of the generative adversarial network and outputting an image-level adversarial loss value; Determine the detection loss weighting coefficient and the adversarial loss weighting coefficient based on the exponential decay strategy of the current training round; Performing weighted processing on the pixel-level detection loss value according to the detection loss weighting coefficient to generate a weighted detection loss value; Performing weighted processing on the image-level adversarial loss value according to the adversarial loss weighting coefficient to generate a weighted adversarial loss value; The weighted detection loss value and the weighted adversarial loss value are linearly superimposed to generate a joint training loss function.
6. The image detection method based on adversarial generation according to claim 1, wherein: Based on the joint loss function, back-propagation optimization is performed on the generator parameters of the generative adversarial network, the model parameters of the image feature extraction module, and the model parameters of the forged region identification module to obtain a forgery detection model, including: Determining the gradient direction and gradient amplitude of the joint loss function on the generator parameters of the generative adversarial network, the model parameters of the image feature extraction module, and the model parameters of the forged region identification module respectively through an automatic differentiation module; Performing threshold constraints on the gradient amplitudes of the generator parameters and the model parameters of the forged region identification module through a gradient clipping module to generate a modified generator gradient and a modified identification module gradient; updating, by an adaptive optimization module, the generator parameters of the generative adversarial network, the model parameters of the image feature extraction module, and the model parameters of the forged region identification module according to the modified generator gradient, the gradient amplitude of the image feature extraction module, and the modified identification module gradient; Repeating the gradient determination operation, the gradient correction operation, and the parameter update operation until the joint loss function converges, outputting a forgery detection model including an optimized image feature extraction module and an optimized forgery region identification module.
7. The image detection method based on adversarial generation according to claim 1, wherein: Processing the image to be detected by the forgery detection model to determine forgery information in the image to be detected includes: receiving the input image to be detected; Extracting a global feature map of the image to be detected by an image feature extraction module in the forgery detection model; Performing classification analysis on the global feature map by using the forgery region recognition module in the forgery detection model to generate an initial forgery probability map; performing a morphological post-processing operation on the initial forgery probability map to generate an optimized forgery probability map; The coordinate information of the forged region in the image to be detected is determined according to the optimized forgery probability map and a preset classification threshold.
8. An image detection device based on adversarial generation, characterized in that: The image detection device based on adversarial generation includes: A generative adversarial module is configured to generate forged image samples based on real image samples through a generative adversarial network, and mix the forged image samples with real image samples to form a training dataset; An image feature extraction module is used to construct an image feature extraction module including a self-attention mechanism, and perform global feature modeling on the images in the training dataset through the image feature extraction module to generate a global feature map; a forged region identification module, configured to generate a forged probability map by comparing global feature differences between the real image and the forged image based on the global feature map; A joint loss construction module, configured to generate a detection loss value using the forgery probability map and construct a joint loss function in combination with the adversarial loss value output by the discriminator of the generative adversarial network; a parameter optimization module, configured to perform back-propagation optimization on the generator parameters of the generative adversarial network, the model parameters of the image feature extraction module, and the model parameters of the forged region identification module based on the joint loss function to obtain a forgery detection model; The forgery detection model processing module is used to process the image to be detected by using the forgery detection model to determine the forgery information in the image to be detected.
9. A computer device, characterized in that: The computer device includes a memory, a processor, and an adversarial generation-based image detection program stored in the memory and capable of running on the processor. When the adversarial generation-based image detection program is executed by the processor, the steps of the adversarial generation-based image detection method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that The storage medium stores an image detection program based on adversarial generation, and when the image detection program based on adversarial generation is executed by the processor, the steps of the image detection method based on adversarial generation according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Image confrontation sample generation method and system based on joint loss function
CN115375966A
Double-branch face forgery detection method based on self-attention mechanism
CN115546864A
Forgery image detection method, device, equipment and medium
CN116580441A
Multi-class image forgery detection method, device, equipment and medium
CN119920017A
Cited By
Image classification model robustness enhancement method and system based on improved generative adversarial network
CN121010835A
Foreign certificate anti-counterfeiting feature detection method based on convolutional neural network model
CN121545025A
Foreign affairs certificate anti-counterfeiting feature detection method based on convolutional neural network model
CN121545025B
Medical image repeated detection method based on deep learning and multi-modal analysis
CN121545026A
A medical image repeated detection method based on deep learning and multi-modal analysis
CN121545026B