A camouflage target generation method based on a diffusion model and related devices
By using a diffusion model and attention fusion mechanism, camouflage targets are generated using the features of the detected target and background image, which solves the problem of limited generation in existing technologies and achieves high-quality camouflage target generation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-22
- Publication Date
- 2026-03-24
AI Technical Summary
Existing camouflage target generation techniques struggle to generate high-quality camouflage targets without additional background information, and existing methods require additional background knowledge or training datasets, which limits the generation results.
A camouflage target generation method based on a diffusion model is adopted. By using a pre-trained diffusion model and an attention fusion mechanism, the feature information of the detected target image and background image is used to generate a camouflage target, including an encoder module, an image inversion module, a Unet module, and a decoder module. The method combines direct attention fusion and indirect injection to perform multiple diffusions and content loss guidance.
It achieves the generation of high-quality camouflaged targets without additional background information, solving the problem of limited generation in existing technologies. It does not require additional training and has strong applicability and generation effect.
Smart Images

Figure CN119919522B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of image generation technology in computer vision, and specifically relates to a method and related apparatus for generating camouflaged targets based on a diffusion model. Background Technology
[0002] Camouflaged targets are those whose textures and features are so similar to their surroundings that they are indistinguishable to the human eye. Due to their difficulty in identification and segmentation, existing conventional target detection methods are ineffective, making research on camouflaged targets a complex problem in the field of computer vision.
[0003] Camouflage target detection is a research area in computer vision, aiming to detect and identify camouflaged targets in complex backgrounds. A major challenge in this field is the difficulty in constructing datasets. Interpretably, images of camouflaged targets are scarce, making the collection of large-scale images extremely difficult. Furthermore, most existing camouflage target datasets are based on natural images, primarily featuring camouflaged targets from wildlife, making it difficult to obtain images of camouflaged targets relevant to the target, resulting in a limited richness of existing datasets. Therefore, utilizing image generation and style transfer methods to generate camouflage targets is particularly important.
[0004] Camouflage target generation refers to the use of technical means to create targets that are highly similar to or can blend seamlessly into the background, in order to achieve the purpose of concealment and deception. Camouflage target generation differs from general target generation. It requires a high degree of consistency between the target and background features, and the ability to provide diversity and richness. Furthermore, since camouflage target generation serves camouflage target detection, it cannot completely integrate the target with the environment. Instead, the target needs to retain its own characteristics while being as similar as possible to the environmental information, thus enabling more effective training of the target detection network.
[0005] Currently, existing camouflage target generation techniques mainly fall into two branches. One branch involves fusing foreground and background images using image fusion methods, given both. This approach is primarily based on style loss and content loss techniques from the field of style transfer. Since the background information of the target location is already specified, the fusion method between the target and the background can achieve the fusion of the target and the corresponding background. However, in practical applications of camouflage target generation, it is often impossible to obtain the background information corresponding to the target region of the camouflage target, rendering this method unusable. The other branch involves using an inpainting model to match suitable images to the target, given only the target segmented by a mask. Since the features of the camouflaged target and the features of the background knowledge are very similar, the background information is also contained in the target, and the target information is also contained in the background. In camouflaged target detection, it is undesirable to generate some unrealistic artifacts or unwanted regions due to changes to the target. Moreover, the process of generating the background is always more difficult than the process of generating the target. Therefore, the "background knowledge retrieval" method is used to match appropriate background information for the target. However, this method also has its drawbacks, namely, the richness of the generated image depends on the diversity of the target. That is to say, when constructing the dataset, it is necessary to provide targets that have a certain degree of camouflage and considerable diversity. Such requirements are often difficult to achieve in practical applications. Summary of the Invention
[0006] The purpose of this invention is to provide a method and apparatus for generating camouflaged targets based on a diffusion model, in order to solve one or more of the aforementioned technical problems. The technical solution disclosed in this invention can convert a target into a camouflaged target using only an image without any additional prior knowledge (such as background knowledge), overcoming the limitations of existing generation methods in practical applications.
[0007] To achieve the above objectives, the present invention adopts the following technical solution:
[0008] In a first aspect, the present invention provides a method for generating camouflaged targets based on a diffusion model, comprising the following steps:
[0009] Acquire an image containing the target to be detected, and segment the image containing the target to be detected to obtain a target image and a background image;
[0010] Based on the image containing the target to be detected, the image of the detected target, and the background image, a pre-trained diffusion model is used for inference to obtain an image containing the disguised target;
[0011] The diffusion model includes:
[0012] The encoder module is used to input the image containing the target to be detected, the image of the target to be detected, and the background image, encode them, and output the initial state hidden variables;
[0013] The image inversion module is used to input the initial state latent variables, perform image inversion processing, and output the latent variables after image inversion.
[0014] The Unet module is used to input the inverted latent variables of the image and perform multiple diffusions based on a scheduler, outputting the diffused latent variables. The scheduler is used to predict the latent variables for the next stage based on time steps and noise. The Unet module includes an encoding layer and a decoding layer, both of which include the same number of Unet processing units. Each Unet processing unit includes a ResNet module with residual connections, an attention module, and a cross-attention module. The attention module in each Unet processing unit of the encoding layer employs a self-attention mechanism. The attention module in each Unet processing unit of the decoding layer employs a self-attention mechanism before a predetermined number of time steps, and then employs one or both of the following methods—direct attention fusion calculation and indirect attention injection—to inject the feature information of the latent variables of the background image into the target object in the image containing the target object.
[0015] The decoder module is used to input the diffused latent variables and decode them, outputting an image containing the camouflaged target.
[0016] A further improvement of the camouflage target generation method of the present invention is that,
[0017] The step of injecting the feature information of the latent variables of the background image into the target object of the image containing the target object by employing one or both of the attention direct fusion calculation method and the attention indirect injection method, specifically includes the following steps:
[0018] An attention fusion term is introduced into the self-attention calculation of the image containing the target to be detected. The query of the image containing the target to be detected, the key of the target image, and the value of the background image are used to perform attention calculation. The attention calculation result is added to the reconstruction process of the original image containing the target to be detected.
[0019] A mapping relationship is established between the image containing the target to be detected and the target region in the detected target image. The mapping relationship is an attention weight matrix established by the query of the image containing the target to be detected and the key of the detected target image. Using the mapping relationship, the value of the background image is directly injected into the image containing the target to be detected in the form of self-attention calculation.
[0020] A further improvement of the camouflage target generation method of the present invention is that,
[0021] The step of injecting the latent variable feature information of the background image into the target object in the image containing the target object by employing one or both of the attention direct fusion calculation method and the attention indirect injection method.
[0022] The direct attention fusion calculation method directly uses the Query of the image containing the target to be detected, the Key of the target image, and the value of the background image to perform self-attention calculation.
[0023] The indirect attention injection method involves injecting the key and value of the background image into the target image to be detected.
[0024] The complete reasoning process for the final three images is as follows:
[0025] ;
[0026] ;
[0027] ;
[0028] In the formula, These represent the query, key, and value of an image containing the target to be detected, respectively. These represent the query, key, and value of the target image to be detected, respectively. These represent the query, key, and value for the background image, respectively. This indicates the scaling dot product attention mechanism; This refers to the normalized exponential function; This represents scaling, with the size being the dimension of the key. and These represent the weights for indirect injection and direct injection, respectively.
[0029] A further improvement of the camouflage target generation method of the present invention is that,
[0030] In the step of multiple diffusion based on the scheduler, in each time step after a predetermined number of time steps, content-based loss guidance is performed after the latent variables of the image containing the target to be detected are updated.
[0031] The content-based loss guidance step involves setting the mode to allow gradient propagation and re-processing the latent variables of the image containing the target to be detected. Inputting the data into the Unet module yields the results. , utilizing the current Predicting latent variables at time t=0 ; hidden variables The image is input into the decoder module to obtain the reconstructed image at the current time step. Using reconstructed images and images containing the target to be detected Calculate the content loss of the background region Optimize using the calculated loss ;
[0032] The loss calculation expression is:
[0033] ;
[0034] ;
[0035] In the formula, The diffusion model is represented by the first... The hidden transformation of the step; These are hyperparameters predefined when training the diffusion model; It is a parameterized network for predicting noise; t represents the number of inference steps in the current diffusion model; This represents the time at step t. The corresponding implicit variables; It is the learning rate of gradient descent; This represents the downsampling operation; z refers to the latent variable containing the image of the target to be detected. This refers to pixel-level difference loss; The segmented image for the target.
[0036] A further improvement of the camouflage target generation method of the present invention is that,
[0037] The Unet module has a total of 16 Unet processing units. The resolution of each Unet processing unit increases with the depth of the Unet, the resolution of the latent variables first decreases and then increases, and the feature dimension of each pixel first increases and then decreases. The decoding layer of the Unet module is the part where the resolution increases and the number of feature dimensions of the pixels decreases.
[0038] A further improvement of the camouflage target generation method of the present invention is that,
[0039] In each of the Unet processing units of the decoding layer, the attention module employs a self-attention mechanism before a predetermined number of time steps, and then uses one or both of the following methods—direct attention fusion calculation and indirect attention injection—to inject the latent variable feature information of the background image into the target object in the image containing the target object.
[0040] In terms of time, in the steps after time step t=30, one or both of the attention direct fusion calculation method and attention indirect injection method are used to inject the feature information of the latent variables of the background image into the target to be detected in the image containing the target to be detected.
[0041] Spatially, in the Unet processing units after the 12th layer of the Unet module, one or both of the attention direct fusion calculation method and the attention indirect injection method are used to inject the feature information of the latent variables of the background image into the target to be detected in the image containing the target to be detected.
[0042] A further improvement of the camouflage target generation method of the present invention is that, in the image inversion module, when performing image inversion, the background image, the target image to be detected, and the latent variable corresponding to the target image to be detected are inverted to the latent variable corresponding to time t=30. Then, in the subsequent inference process, the latent variable at time t=30 is used as the initial state for the reverse denoising process.
[0043] A second aspect of the present invention provides a camouflage target generation system based on a diffusion model, comprising:
[0044] The data acquisition module is used to acquire an image containing the target to be detected, and to segment the image containing the target to be detected to obtain a target image and a background image;
[0045] The camouflage target generation module is used to obtain an image containing a camouflage target by inference using a pre-trained diffusion model based on the image containing the target to be detected, the image of the detected target, and the background image;
[0046] The diffusion model includes:
[0047] The encoder module is used to input the image containing the target to be detected, the image of the target to be detected, and the background image, encode them, and output the initial state hidden variables;
[0048] The image inversion module is used to input the initial state latent variables, perform image inversion processing, and output the latent variables after image inversion.
[0049] The Unet module is used to input the inverted latent variables of the image and perform multiple diffusions based on a scheduler, outputting the diffused latent variables. The scheduler is used to predict the latent variables for the next stage based on time steps and noise. The Unet module includes an encoding layer and a decoding layer, both of which include the same number of Unet processing units. Each Unet processing unit includes a ResNet module with residual connections, an attention module, and a cross-attention module. The attention module in each Unet processing unit of the encoding layer employs a self-attention mechanism. The attention module in each Unet processing unit of the decoding layer employs a self-attention mechanism before a predetermined number of time steps, and then employs one or both of the following methods—direct attention fusion calculation and indirect attention injection—to inject the feature information of the latent variables of the background image into the target object in the image containing the target object.
[0050] The decoder module is used to input the diffused latent variables and decode them, outputting an image containing the camouflaged target.
[0051] In a third aspect, the present invention provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, implements the camouflage target generation method based on a diffusion model as described in any one of the first aspects of the present invention.
[0052] In a fourth aspect, the present invention provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the camouflage target generation method based on a diffusion model as described in any one of the first aspects of the present invention.
[0053] Compared with the prior art, the present invention has the following beneficial effects:
[0054] This invention provides a method for generating camouflaged targets based on a diffusion model, specifically a scheme for generating camouflaged targets based on an attention fusion mechanism within a diffusion model. By constructing a dataset of the detected target image, background image, and image to be camouflaged, a pre-trained diffusion model is used for inference. During inference, the attention implementation mechanism is modified, ultimately achieving the goal of generating camouflaged targets without providing additional background information. This solves the limitations of existing technologies in generating camouflaged targets without additional background information. Specifically, the diffusion model generation network disclosed in this invention includes three stages. The first stage utilizes image inversion technology to invert the image into latent variables corresponding to the given number of steps. The second stage uses the latent variables for diffusion model inference. The attention module in the decoding layer of Unet includes attention fusion and attention injection mechanisms. In summary, existing camouflaged target generation schemes require background knowledge of the target region and training. This invention's method generates camouflaged targets without additional background knowledge or training. Based on a diffusion model framework, this invention effectively generates camouflaged targets by adjusting the attention mechanism during model inference. Furthermore, the module is simple, plug-and-play, and has few dependencies, making it highly applicable.
[0055] In a preferred embodiment of the present invention, the attention fusion mechanism establishes a mapping relationship between the generated image and the target image by calculating an attention weight matrix, and then uses this mapping relationship to inject background feature information into the generated image. The attention injection mechanism first directly injects background feature information into the target image, and then uses the reconstruction term of the generated image to inject the feature information into the generated image. Furthermore, the attention direct fusion calculation and attention indirect injection method set by the present invention can inject background feature information into the target, giving the target a camouflage effect.
[0056] In a preferred embodiment of the present invention, after the inference of Unet is completed, a content-based loss-guided approach is used to optimize the latent variables, guide the consistency between the background of the generated image and the background of the original image, and reduce the content loss between the generated image and the original image. Attached Figure Description
[0057] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0058] Figure 1 This is a flowchart illustrating a method for generating camouflaged targets based on a diffusion model, as described in an embodiment of the present invention.
[0059] Figure 2 This is a schematic diagram illustrating the principle of a camouflage target generation method based on a diffusion model in an embodiment of the present invention.
[0060] Figure 3 This is a schematic diagram of a camouflage target generation system based on a diffusion model in an embodiment of the present invention. Detailed Implementation
[0061] To make the objectives, technical solutions, and advantages of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention; obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments.
[0062] Based on the technical solutions disclosed in the embodiments of this invention, all other embodiments obtained by those skilled in the art without inventive effort are within the scope of protection of this invention. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products, or devices.
[0063] Please see Figure 1 and Figure 2 The present invention provides a method for generating camouflaged targets based on a diffusion model, comprising the following steps:
[0064] Step 1: Obtain an image containing the target to be detected, and segment the image containing the target to be detected to obtain the target image and the background image;
[0065] Step 2: Based on the image containing the target to be detected, the image of the detected target, and the background image, a pre-trained diffusion model is used for inference to obtain an image containing the disguised target;
[0066] The diffusion model includes:
[0067] The encoder module is used to input the image containing the target to be detected, the image of the target to be detected, and the background image, encode them, and output the initial state hidden variables;
[0068] The image inversion module is used to input the initial state latent variables, perform image inversion processing, and output the latent variables after image inversion.
[0069] The Unet module is used to input the inverted latent variables of the image and perform multiple diffusions based on a scheduler, outputting the diffused latent variables. The scheduler is used to predict the latent variables for the next stage based on time steps and noise. The Unet module includes an encoding layer and a decoding layer, both of which include the same number of Unet processing units. Each Unet processing unit includes a ResNet module with residual connections, an attention module, and a cross-attention module. The attention module in each Unet processing unit of the encoding layer employs a self-attention mechanism. The attention module in each Unet processing unit of the decoding layer employs a self-attention mechanism before a predetermined number of time steps, and then employs one or both of the following methods—direct attention fusion calculation and indirect attention injection—to inject the feature information of the latent variables of the background image into the target object in the image containing the target object.
[0070] The decoder module is used to input the diffused latent variables and decode them, outputting an image containing the camouflaged target.
[0071] This invention provides a method for generating camouflaged targets. The technical solution encodes the input image using an encoder module to extract key features and decodes the latent variables using a decoder module to generate camouflaged target images. This flexible encoding and decoding mechanism allows the model to adapt to different input and output requirements, improving the controllability and diversity of the generated results. Furthermore, the Unet module is the core of this technical solution. It employs a ResNet module with residual connections, an attention module, and a cross-attention module, improving the model's expressive power and generation quality. A scheduler predicts the latent variables for the next stage based on time steps and noise, achieving fine control over the generation process. Moreover, in the attention module of the decoding layer, a direct attention fusion calculation method and an indirect attention injection method are used to inject the latent variable feature information of the background image into the target image containing the target to be detected, achieving a natural fusion of the background and the camouflaged target, improving the realism and consistency of the generated images. The technical solution of this invention can not only be applied to camouflaged target generation but can also be extended to other image generation and editing tasks, such as image restoration and style transfer, and has potential application value in fields such as military camouflage and artistic creation.
[0072] To further explain, compared to traditional methods such as Generative Adversarial Networks (GANs), the diffusion model avoids problems such as pattern collapse, has a more stable training process, and generates higher quality images. By introducing the Unet module and an innovative background information fusion method, this technical solution further improves the controllability and diversity of the generated effects. Through a refined noise addition and removal process and an advanced Unet module design, the method of this invention can generate highly realistic and detailed camouflaged target images. Simultaneously, the innovative background information fusion method achieves a natural fusion of the background and the camouflaged target, improving the realism and consistency of the generated images.
[0073] In summary, the technical solution of this invention, based on a diffusion model, provides a method for generating camouflaged targets. It has advantages and significant progress in terms of high-quality generation results, flexible encoding and decoding mechanisms, advanced Unet module design, innovative background information fusion methods, and broad application prospects.
[0074] In a specific embodiment of the present invention, the process of generating a camouflaged target may include the following steps:
[0075] Step 1: Construct a soldier dataset for generating camouflage targets; for example, the collected images satisfy RGB three-channel encoding and include manually labeled results, with a dataset size of [size missing]. It is worth noting that the dataset does not have a spoofing effect; the collected images are sent to the computer that executes the algorithm.
[0076] Step 2: Construct a diffusion model capable of generating camouflaged targets; wherein the diffusion model is divided into three stages: image inversion stage, attention injection stage, and loss guidance stage; further, the diffusion model includes an encoder module for converting images into latent variables, a decoder module for converting latent variables into images, a Unet module for predicting noise, and a scheduler for predicting latent variables for the next stage based on time steps and noise.
[0077] Specifically, in the image inversion stage, the image containing the target to be detected is... Detect target image and background image The latent variables of the image are input as a batch into the encoder module of the diffusion model to obtain the representation of the latent variables. Then, the latent variables are inverted and used as input to the Unet module of the diffusion model to predict noise. Noise prediction and latent variable updates are performed according to the inverse DDIM (Denoising Diffusion Implicit Models) planner. The total number of steps is set to T, and the update steps are executed iteratively until t=T to t=0, at which point the result is obtained. Noise representation of latent variables at the initial time.
[0078] The denoising process of reverse DDIM is represented as follows:
[0079] ;
[0080] In the formula, express t Latent variables at time t; , , These are hyperparameters of the diffusion model; This indicates the output of Unet.
[0081] In the preferred technical solution, since the error increases with the number of reversal steps during the image reversal process, and considering that the subsequent attention reorganization mechanism and content loss-based guidance are used in steps after time step t=30, the latent variables at step t=30 are obtained by reversing the image. In the subsequent inference process, the latent variables at step t=30 are used as the initial state to start the reverse denoising process, which can significantly reduce image distortion and content quality degradation, and improve reconstruction quality.
[0082] In this embodiment of the invention, during the denoising inference step of the diffusion model, an attention reorganization mechanism is introduced in the inference process of the Unet module, and content-based loss guidance is performed after the latent variables are updated. In a specific exemplary preferred embodiment, the attention reorganization mechanism and content-based loss guidance are introduced in each step after time step t=30. Specifically, the latent variables are first used as input to the Unet module of the diffusion model. A single Unet processing unit in the Unet module contains a ResNet module, a Self-Attention module, and a Cross-Attention module. These three modules are linearly connected in sequence. The output of each module is added to the input as a residual and then injected into the next module as input. In a specific exemplary technical solution, there are 16 layers in the Unet module. The resolution of each layer increases with the depth of the Unet, the resolution of the latent variables first decreases and then increases, and the feature dimension of each pixel first increases and then decreases. In the decoding layer of the Unet module, that is, in the part where the resolution increases and the number of feature dimensions decreases, the latent variables have a clearer feature representation ability and contain more complete structural information. In the Self-Attention module of some layers of the decoding layer of the Unet module, an attention injection mechanism is used, which can include two parts.
[0083] The first part is in Add an attention fusion term to the self-attention calculation, that is, utilize... Query Key and The value is used for attention calculation, and the result is compared with the original value. The reconstruction process is added together. This part is achieved by establishing... and The mapping relationship of the target region, that is Query and The attention weight matrix is established using the key, and then this mapping relationship is used to directly... The value is injected into the form of self-attention computation. In the middle. It is worth noting that, The reconstruction process is set up in the following form, that is, from The goal of reconstruction in China, and from The background of reconstruction in China. After this is achieved, for... The changes made will be reflected in superior.
[0084] The second part uses an indirect attention injection method, that is, first the background... Key and value are injected into the target. Among them, because The reconstruction of the target part in the reconstruction item is achieved by... key-value injection into Among them, and Because the injected background features are already more similar to the background, it can indirectly... Feature information is injected first Then inject into The target area. Specifically, it uses Query and Key and The value Value is used for self-attention calculation.
[0085] The complete reasoning process for the final three images is as follows:
[0086]
[0087]
[0088] ;
[0089] In the formula, A query for an image containing the target to be detected, consisting of a key and a value. This represents a query for detecting a target image, consisting of a key and a value. This represents a query for the background image, consisting of a key and a value. "Attention" refers to the scaling dot product attention mechanism, and "softmax" refers to the normalized exponential function. This represents scaling, with the size being the dimension of the key. and These represent the weights for indirect injection and direct injection, respectively.
[0090] In a preferred embodiment of the present invention, the following technical solution is used: Background features are injected in the two methods described above. In the goal, to make The texture information of the target in the model is similar to that of the background. Furthermore, temporally, an attention reorganization mechanism is used in steps after time step t=30, and spatially, an attention reorganization mechanism is used in layers after layer 12 of Unet.
[0091] In a preferred embodiment of the present invention, to address the issue that the content of the spoofed image may differ significantly from the original image during the injection process, a content-based loss-guided approach is proposed. Specifically, after the update is completed at each time step, the model is set to a mode that allows gradient propagation, and then the latent variables are re-inputted. The results were obtained from Unet. Then utilize the current Predicting latent variables at time t=0 ;Will The image is input into the decoder to obtain the reconstructed image at the current time step. Then use the reconstructed image truth value Calculate the MSE loss of the background region Optimize using this loss The formula is shown below:
[0092] ;
[0093] ;
[0094] In the formula, The diffusion model is represented by the first... Hidden variables of the step; These are hyperparameters predefined when training the diffusion model; It is a parameterized network for predicting noise; t represents the number of inference steps in the current diffusion model; This represents the time at step t. The corresponding implicit variables; It is the learning rate of gradient descent; This represents the downsampling operation, and z refers to the latent variable containing the image of the target to be detected. This refers to pixel-level difference loss; The segmented image for the target.
[0095] After completing the set number of steps, the latent variables corresponding to the final result are obtained. The diffusion model is then used to decode the result, thus obtaining the final generated result.
[0096] In the technical solution of this invention, image generation technology based on a diffusion model is applied to the field of style transfer for camouflaged targets. An attention reorganization mechanism is proposed to inject background features into the target, and a content-based loss guidance technique is designed to improve the consistency of background content in camouflaged images. Based on these two techniques, a diffusion model for generating camouflaged targets is improved and designed. Further, the attention reorganization disclosed in this invention is based on self-attention computation, reconstructing the attention calculation method during inference, and introducing background features into the target in the form of associated attention calculations. No training is required; only a pre-trained diffusion model is needed for inference. This invention can solve the problem of insufficient datasets in the camouflaged target cognition domain and the problem of requiring additional background knowledge corresponding to the target region for computation in the camouflaged target generation domain. Furthermore, compared with traditional camouflaged target generation methods, it reduces the complexity of generation and improves the quality of generation.
[0097] In one specific embodiment of the present invention, the target dataset used contains a total of 1300 RGB color images of soldiers taken in real-world scenes, with an image size of [missing information]. Pixels; using manually labeled datasets, the regions of the target in each image are annotated, and the annotation results are represented by a binary image. Image In the preprocessing stage, it will first be scaled to... The image is then cropped to contain only the target based on the annotation results. and an image containing only the background .
[0098] In this embodiment of the invention, the diffusion model network parameters are initialized using a pre-trained StableDiffusion algorithm. The runtime environment is a computer with frameworks such as PyTorch, capable of reading a given image and completing the inference computation process of the model. In this embodiment, inferring an image on an L20 (48GB) GPU takes approximately one minute. Specific implementation steps include: obtaining the dependency library information required by the diffusion model and loading the pre-trained diffusion model, including Unet, encoder, decoder, text encoder, and scheduler; initializing the attention fusion module and the MSE-based loss guidance module, setting the weight of attention injection and the learning rate of the loss; then registering the attention fusion module into the diffusion model. Specifically, it iterates through all modules of the diffusion model, finds the self-attention module, and replaces it with the attention fusion module. It is worth noting that the attention fusion module has an internal counter to record the current layer and time step to determine the appropriate attention mechanism. The total inference steps of the diffusion model are set to 50. The attention reorganization mechanism and the MSE-based loss guidance mechanism begin at step 30, and the initial layer is layer 12. The pre-processed image is loaded. , , Set a batch as input, and then calculate the state of the hidden variable corresponding to step 30. The latent variables are used as input to the Unet of the diffusion model. The Unet with attention reorganization computes the noisy output, then updates the latent variables. The diffusion model is then set to allow gradient propagation, the noisy output is recomputed, the gradient is computed, and the latent variables are updated. After all time steps are completed, the decoder of the diffusion model is used to obtain the final generated result.
[0099] This invention discloses a method for generating camouflaged targets based on a diffusion model. This method utilizes the attention mechanism of the diffusion model to inject background features into the target, and uses a loss-guided approach to ensure that the background content of the image remains unchanged. This method converts non-camouflaged targets in an image into camouflaged targets without requiring the background corresponding to the target region, thus achieving training-free conversion. Furthermore, the modules are simple, require minimal dependencies, and possess strong applicability.
[0100] In a specific embodiment of the present invention, the target image to be detected that requires style transfer is obtained. The image has a size of (c, h, w), where c represents the number of channels, and h and w represent the height and width of the image, respectively. Then, data annotation techniques are used to obtain a segmented image of the target. The segmented image is binary; within its pixels, regions with a value of 1 represent the target, and regions with a value of 0 represent the background. The segmented image is used to preprocess the target image, resulting in an image containing only the target. and images containing only background All images are of the same size, (c, h, w).
[0101] ;
[0102] in, The operator represents positional multiplication.
[0103] Three representations of a camouflaged image were obtained. After processing all the datasets, each image was obtained as either an image containing only the target or an image containing only the background.
[0104] After obtaining the image, in order to apply the real image to the diffusion model, it is necessary to use the image inversion technique. The so-called image inversion technique refers to using the reverse diffusion model to predict the noise at each step of the real image, adding noise to the image until it becomes pure noise.
[0105]
[0106] In the formula, The diffusion model is represented by the first... Hidden variables of the step; , These are predefined hyperparameters used when training the diffusion model, added for different time steps. , The values are different; It is a parameterized network for predicting noise, implemented as a Unet in the diffusion model; , , As a batch input into the diffusion model, each image is preprocessed into a (3, 512, 512) image, and first the image is encoded into the latent space using an Encoder.
[0107]
[0108] in, The dimensions are (4, 64, 64).
[0109] Then, the latent variables encoded by the Encoder are image-inverted. After setting the number of steps to 50, pure noise that can be reconstructed into the corresponding image is obtained, until the inference becomes... .
[0110]
[0111] After obtaining the noise for the corresponding images, the noise from the three images is input as a batch into the diffusion model to begin the inference process. The standard denoising process for the diffusion model using the DDIM sampler is shown below:
[0112] ;
[0113] in, These are predefined hyperparameters. .
[0114] In the early stages of denoising, the image is very blurry and the structural information is not obvious. Adding noise at this time will lead to completely different results. Therefore, in the embodiment of the present invention, an attention injection mechanism is added in step 30.
[0115] In this embodiment of the invention, a noise predictor for a diffusion model It is a UNet architecture, with sixteen modules in a single UNet. Each module contains a cross-attention mechanism module, a self-attention mechanism module, and a ResNet. Some studies have shown that the self-attention module can control the generation of image feature information.
[0116] A standard self-attention process is as follows:
[0117] ;
[0118] Where Q represents Query; K represents Key; and V represents Value; This represents scaling, with a size of K dimensions.
[0119] In the inference process of the diffusion model, the implicit state representation of self-attention in Unet is obtained as follows: In the diffusion model, the implicit state is first expressed through a weight matrix. Convert to the corresponding query ,key ,value The implicit state has the shape (batch_size, seq_length, input_dim), where batch_size refers to the batch size of the input, seq_length refers to the length of the serialized input data, and input_dim refers to the dimension of the input.
[0120]
[0121]
[0122]
[0123] The original diffusion model's reasoning process involves calculating the attention for each image's implicit representation one by one.
[0124]
[0125]
[0126]
[0127] After the final inference is completed, the noise from the first inference is obtained. This noise is then fed into the scheduler corresponding to the diffusion model for calculation. After setting the number of iterations, the final result is obtained. This process is called the reconstruction process. Because no new information is introduced at this point, the noise obtained from the image inversion process is simply reconstructed into the original image.
[0128] In the multiple modules of UNet, the dimensionality of the modules in UNet sequentially decreases and then increases again. The process of decreasing the dimensionality of the modules is called the encoding layer of UNet, and the process of increasing the dimensionality of the modules is called the decoding layer of UNet. In the decoder part of UNet, the image contains more structural and feature information. Therefore, attention-related improvement mechanisms are added to the decoder part in the spatial dimension.
[0129] In terms of inference steps, we found that the structural and feature information of the image was not obvious from step 0 to step 25, while the feature information gradually began to emerge from step 25 to step 50. Therefore, in terms of time dimension, we chose to add attention-related improvement mechanisms starting from step 25. We found that utilizing... To reorganize attention The calculation process for attention can also be achieved. The reconstruction method is as follows:
[0130] ;
[0131] Because during the attention calculation process, the query s and keys Performing a dot product between the query and key, with tensors of shape (batch_size, seq_length, dk) and (batch_size, seq_length, dk) respectively, yields the attention weight matrix Sim. Sim's tensor shape is (batch_size, seq_length, seq_length). This matrix represents the attention weights for each query. Corresponding to key The attention weights are calculated. In this calculation process, even if the query and key are inferred from different images, the attention weight matrix Sim can still be obtained, thus enabling us to use... Query and The key and value, plus Query and The key and value. Reconstruct to obtain... .
[0132] In the technical solution of this invention embodiment, an attention reorganization mechanism is used to approximate the target features and background features. Because we can use... Query and We build an attention weight matrix using the key `Key`. If we then use the value `Value` for the final attention calculation, the target will be reconstructed. Here, `Value` represents the value when building from... arrive After the attention weight matrix is generated, the injected information is used; therefore, here we use The value of Value is used as the value of the weight matrix.
[0133] ;
[0134] In steps 25 through 50 of the diffusion model inference, in the decoder part of Unet, The reasoning process is set up as follows:
[0135] ;
[0136] in, This indicates the weight of the attention calculation item directly fused. The default value is 1. Increasing this weight can achieve a better camouflage effect, while decreasing this weight can retain more information about the target.
[0137] In the technical solution of this invention embodiment, an attention fusion mechanism is employed to inject background environmental features into the target. and In the process of reasoning, The corresponding key and value are injected into Among them, even using Query and Attention is calculated using the key and value. Then, the result is multiplied by a weight and added to... Within the reasoning part of attention.
[0138] The formula is as follows:
[0139] ;
[0140] in, Indicates the weight of indirect attention injection;
[0141] The complete reasoning process for the final three images is as follows:
[0142]
[0143]
[0144] ;
[0145] In the formula, These represent the query, key, and value of an image containing the target to be detected, respectively. These represent the query, key, and value of the target image to be detected, respectively. These represent the query, key, and value for the background image, respectively. This indicates the scaling dot product attention mechanism; This refers to the normalized exponential function; Represents scaling, with a dimension of size K; and These represent the weights for indirect injection and direct injection, respectively.
[0146] It's worth noting that during the inference process, both the target and background are obtained using masking. Their spatial locations do not overlap, meaning that methods based on traditional neural networks like VGG, which extract spatial relationships, cannot inject background feature information into the target. In the calculation of self-attention, we use... and to indicate The corresponding target area and background area, Pixels in other regions are represented by 0. In the calculation, only non-zero regions have high element values in the attention weight matrix. This is because regions with pixel values of 0 tend to have values close to 0 after being mapped to the query matrix. Furthermore, the attention mechanism calculates the relationship between each query and each key; during the calculation of the attention weight matrix... This calculation method allows us to inject attention even when the spatial locations between two images do not overlap.
[0147] In the technical solution provided by this invention, a loss-guided method based on MSE is used to achieve consistency between the content of the style-transferred image and the original image. Only the target content is changed, and the direction of change is limited to the direction of camouflage. During the reconstruction process of the diffusion model, we chose the DDIM Inversion method, which can invert the image into pure noise and then re-infer it into an image. However, during the inversion process, we cannot accurately reconstruct the image, which will significantly degrade the performance of our method. Furthermore, as the diffusion model infers, after using the aforementioned attention injection mechanism, discrepancies will arise between the image information and the reconstructed information. Therefore, we propose a content loss based on MSE to ensure the consistency of image information.
[0148] Specifically, the original image is called The reconstructed image is called An intuitive idea is that we can establish a Mean Squared Error (MSE) loss between the two as a guide to ensure that the generated image is similar to the original image content. Furthermore, after implementing an attention injection mechanism, we can achieve a good camouflage effect while maintaining a largely consistent background.
[0149] Given image The calculation method for MSE is as follows:
[0150] ;
[0151] However, two problems exist here. First, in the inference process of the diffusion model, the denoising results at each step... Both are noisy versions, and comparing the MSE with the noisy versions will yield inaccurate results. Second, when performing self-attention injection, we want the texture information of the target to change, that is, the target information to change in the direction of the camouflage. If a simple MSE loss is used, it will eventually affect the camouflage attributes, causing the entire image to be identical to the original image.
[0152] To address the first question, let's review the sampling mechanism of DDIM. The modeling process of the diffusion model is as follows: For the forward process, according to the Markov theorem, the current state is only related to the state of the previous state, which is transformed into the noise relationship between each time step and the previous time step.
[0153] ;
[0154] For the reverse process, given the state at each time step, we need to predict the state at the previous time step. By modeling the mean and variance and using a neural network (i.e., Unet) for prediction, we can obtain the results we need.
[0155] ;
[0156] Since the forward process is fixed, given It can be calculated directly. The result.
[0157] ;
[0158] ;
[0159] In the process of reverse reasoning, once we know the current state, we can derive the prediction based on the current state using the above formula. The result. Use this result to compare with... By performing calculations, the problem of being unable to properly calculate the MSE loss due to noise in the intermediate process of the diffusion model can be eliminated.
[0160] ;
[0161] in, It is a parameterized neural network, also known as Unet, used to predict noise at each step.
[0162] The final calculation process is as follows:
[0163] ;
[0164] in, This refers to the decoder part of the diffusion model, which predicts... The prediction was obtained after decoding. . This and The MSE is calculated, and this loss is used as a guide for the input noise after the thirtieth step of the diffusion model. After one Unet iteration, the noise is predicted and updated. Then, the model is configured to allow gradient propagation, and the model is reused during this process. Inference is performed using Unet to predict noise and obtain... Future predictions And calculate the MSE loss, and finally use this loss to calculate the relative... The gradient.
[0165]
[0166] The second issue is that when we use attention-based enhancement mechanisms, the target region changes because its features become more similar to the background, and this change will also be reflected in... Compared to In the gradient, that is, we calculate the MSE loss and update When doing so, targets that have already been camouflaged will also move in the same direction as targets that were not originally camouflaged. Therefore, we propose using a mask to define the background area as a region suitable for gradient descent.
[0167] Specifically, given And a downsampling factor downsample, which limits the gradient propagation calculation to the background region when we calculate the gradient.
[0168]
[0169] The noise update process for the final time step is shown below:
[0170]
[0171] ;
[0172] in, This refers to the learning rate of the gradient descent.
[0173] In a preferred embodiment of the invention, we found that when using image inversion, the more inversion steps there are, the greater the accumulated error at each step, and the worse the final reconstruction quality. Reviewing all the techniques described above, we can see that all improvements are based on time steps after the 25th step. Therefore, when performing image inversion, we only invert to the 30th step to obtain the latent variable expression for the 25th step, and then use the latent variable from the 25th step for the reverse denoising process. The content preservation of the reconstructed image is significantly better than inverting to the 0th step and then starting reconstruction.
[0174] The following are embodiments of the apparatus of the present invention, which can be used to execute embodiments of the method of the present invention. For details not disclosed in the apparatus embodiments, please refer to the embodiments of the method of the present invention.
[0175] Please see Figure 3 In this embodiment of the invention, a camouflage target generation system based on a diffusion model is provided, comprising:
[0176] The data acquisition module is used to acquire an image containing the target to be detected, and to segment the image containing the target to be detected to obtain a target image and a background image;
[0177] The camouflage target generation module is used to obtain an image containing a camouflage target by inference using a pre-trained diffusion model based on the image containing the target to be detected, the image of the detected target, and the background image;
[0178] The diffusion model includes:
[0179] The encoder module is used to input the image containing the target to be detected, the image of the target to be detected, and the background image, encode them, and output the initial state hidden variables;
[0180] The image inversion module is used to input the initial state latent variables, perform image inversion processing, and output the latent variables after image inversion.
[0181] The Unet module is used to input the inverted latent variables of the image and perform multiple diffusions based on a scheduler, outputting the diffused latent variables. The scheduler is used to predict the latent variables for the next stage based on time steps and noise. The Unet module includes an encoding layer and a decoding layer, both of which include the same number of Unet processing units. Each Unet processing unit includes a ResNet module with residual connections, an attention module, and a cross-attention module. The attention module in each Unet processing unit of the encoding layer employs a self-attention mechanism. The attention module in each Unet processing unit of the decoding layer employs a self-attention mechanism before a predetermined number of time steps, and then employs one or both of the following methods—direct attention fusion calculation and indirect attention injection—to inject the feature information of the latent variables of the background image into the target object in the image containing the target object.
[0182] The decoder module is used to input the diffused latent variables and decode them, outputting an image containing the camouflaged target.
[0183] In a third aspect, the present invention provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, implements the camouflage target generation method based on a diffusion model as described in any one of the first aspects of the present invention.
[0184] In one embodiment of the present invention, a computer device is provided, comprising a processor and a memory. The memory stores a computer program, which includes program instructions. The processor executes the program instructions stored in the computer storage medium. The processor may be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. It is the computing and control core of the terminal, suitable for implementing one or more instructions, specifically suitable for loading and executing one or more instructions in the computer storage medium to achieve a corresponding method flow or corresponding function. The processor described in this embodiment of the present invention can be used to execute the operation of a camouflage target generation method based on a diffusion model.
[0185] In one embodiment of the present invention, a storage medium is provided, specifically a computer-readable storage medium (Memory), which is a memory device in a computer device used to store programs and data. It is understood that the computer-readable storage medium here can include both the built-in storage medium in the computer device and extended storage media supported by the computer device. The computer-readable storage medium provides storage space that stores the operating system of the terminal. Furthermore, the storage space also stores one or more instructions suitable for loading and execution by a processor, which can be one or more computer programs (including program code). It should be noted that the computer-readable storage medium here can be high-speed RAM (Random Access Memory) or non-volatile memory, such as at least one disk storage device. The processor can load and execute one or more instructions stored in the computer-readable storage medium to implement the corresponding steps of the diffusion-based camouflage target generation method in the above embodiments.
[0186] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, optical storage, etc.) containing computer-usable program code.
[0187] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0188] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0189] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0190] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the specific implementation of the present invention. Any modifications or equivalent substitutions that do not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.
Claims
1. A method for generating camouflaged targets based on a diffusion model, characterized in that, Includes the following steps: Acquire an image containing the target to be detected, and segment the image containing the target to be detected to obtain a target image and a background image; Based on the image containing the target to be detected, the image of the detected target, and the background image, a pre-trained diffusion model is used for inference to obtain an image containing the disguised target; The diffusion model includes: The encoder module is used to input the image containing the target to be detected, the image of the target to be detected, and the background image, encode them, and output the initial state hidden variables; The image inversion module is used to input the initial state latent variables, perform image inversion processing, and output the latent variables after image inversion. The Unet module is used to input the inverted latent variables of the image and perform multiple diffusions based on a scheduler, outputting the diffused latent variables. The scheduler is used to predict the latent variables for the next stage based on time steps and noise. The Unet module includes an encoding layer and a decoding layer, both of which include the same number of Unet processing units. Each Unet processing unit includes a ResNet module with residual connections, an attention module, and a cross-attention module. The attention module in each Unet processing unit of the encoding layer employs a self-attention mechanism. The attention module in each Unet processing unit of the decoding layer employs a self-attention mechanism before a predetermined number of time steps, and then employs one or both of the following methods—direct attention fusion calculation and indirect attention injection—to inject the feature information of the latent variables of the background image into the target object in the image containing the target object. The decoder module is used to input the diffused latent variables and decode them, outputting an image containing the camouflaged target.
2. The method for generating camouflaged targets based on a diffusion model according to claim 1, characterized in that, The step of injecting the feature information of the latent variables of the background image into the target object of the image containing the target object by employing one or both of the attention direct fusion calculation method and the attention indirect injection method, specifically includes the following steps: An attention fusion term is introduced into the self-attention calculation of the image containing the target to be detected. The query of the image containing the target to be detected, the key of the target image, and the value of the background image are used to perform attention calculation. The attention calculation result is added to the reconstruction process of the original image containing the target to be detected. A mapping relationship is established between the image containing the target to be detected and the target region in the detected target image. The mapping relationship is an attention weight matrix established by the query of the image containing the target to be detected and the key of the detected target image. Using the mapping relationship, the value of the background image is directly injected into the image containing the target to be detected in the form of self-attention calculation.
3. The method for generating camouflaged targets based on a diffusion model according to claim 1, characterized in that, The step of injecting the latent variable feature information of the background image into the target object in the image containing the target object by employing one or both of the attention direct fusion calculation method and the attention indirect injection method. The direct attention fusion calculation method directly uses the Query of the image containing the target to be detected, the Key of the target image, and the value of the background image to perform self-attention calculation. The indirect attention injection method involves injecting the key and value of the background image into the target image to be detected. The complete reasoning process for the final three images is as follows: ; ; ; In the formula, These represent the query, key, and value of an image containing the target to be detected, respectively. These represent the query, key, and value of the target image to be detected, respectively. These represent the query, key, and value for the background image, respectively. This indicates the scaling dot product attention mechanism; This refers to the normalized exponential function; This represents scaling, with the size being the dimension of the key. and These represent the weights for indirect injection and direct injection, respectively.
4. The method for generating camouflaged targets based on a diffusion model according to claim 1, characterized in that, In the step of multiple diffusion based on the scheduler, in each time step after a predetermined number of time steps, content-based loss guidance is performed after the latent variables of the image containing the target to be detected are updated. The content-based loss guidance step involves setting the mode to allow gradient propagation and re-processing the latent variables of the image containing the target to be detected. Inputting the data into the Unet module yields the results. , utilizing the current Predicting latent variables at time t=0 ; hidden variables The image is input into the decoder module to obtain the reconstructed image at the current time step. Using reconstructed images and images containing the target to be detected Calculate the content loss of the background region Optimize using the calculated loss ; The loss calculation expression is: ; ; In the formula, The diffusion model is represented by the first... Hidden variables of the step; These are hyperparameters predefined when training the diffusion model; It is a parameterized network for predicting noise; t represents the number of inference steps in the current diffusion model; This represents the time at step t. The corresponding implicit variables; It is the learning rate of gradient descent; This represents the downsampling operation; z refers to the latent variable containing the image of the target to be detected. This refers to pixel-level difference loss; The segmented image for the target.
5. The method for generating camouflaged targets based on a diffusion model according to claim 4, characterized in that, The Unet module has a total of 16 Unet processing units. The resolution of each Unet processing unit increases with the depth of the Unet, the resolution of the latent variables first decreases and then increases, and the feature dimension of each pixel first increases and then decreases. The decoding layer of the Unet module is the part where the resolution increases and the number of feature dimensions of the pixels decreases.
6. The method for generating camouflaged targets based on a diffusion model according to claim 5, characterized in that, In each of the Unet processing units of the decoding layer, the attention module employs a self-attention mechanism before a predetermined number of time steps, and then uses one or both of the following methods—direct attention fusion calculation and indirect attention injection—to inject the latent variable feature information of the background image into the target object in the image containing the target object. In terms of time, in the steps after time step t=30, one or both of the attention direct fusion calculation method and attention indirect injection method are used to inject the feature information of the latent variables of the background image into the target to be detected in the image containing the target to be detected. Spatially, in the Unet processing units after the 12th layer of the Unet module, one or both of the attention direct fusion calculation method and the attention indirect injection method are used to inject the feature information of the latent variables of the background image into the target to be detected in the image containing the target to be detected.
7. The method for generating camouflaged targets based on a diffusion model according to claim 6, characterized in that, In the image inversion module, when performing image inversion, the background image, the target image to be detected, and the latent variable corresponding to the target image to be detected are inverted to the latent variable corresponding to time t=30. Then, in the subsequent inference process, the latent variable at time t=30 is used as the initial state for the reverse denoising process.
8. A camouflage target generation system based on a diffusion model, characterized in that, include: The data acquisition module is used to acquire an image containing the target to be detected, and to segment the image containing the target to be detected to obtain the target image and the background image; The camouflage target generation module is used to obtain an image containing a camouflage target by inference using a pre-trained diffusion model based on the image containing the target to be detected, the image of the detected target, and the background image; The diffusion model includes: The encoder module is used to input the image containing the target to be detected, the image of the target to be detected, and the background image, encode them, and output the initial state hidden variables; The image inversion module is used to input the initial state latent variables, perform image inversion processing, and output the latent variables after image inversion. The Unet module is used to input the inverted latent variables of the image and perform multiple diffusions based on a scheduler, outputting the diffused latent variables. The scheduler is used to predict the latent variables for the next stage based on time steps and noise. The Unet module includes an encoding layer and a decoding layer, both of which include the same number of Unet processing units. Each Unet processing unit includes a ResNet module with residual connections, an attention module, and a cross-attention module. The attention module in each Unet processing unit of the encoding layer employs a self-attention mechanism. The attention module in each Unet processing unit of the decoding layer employs a self-attention mechanism before a predetermined number of time steps, and then employs one or both of the following methods—direct attention fusion calculation and indirect attention injection—to inject the feature information of the latent variables of the background image into the target object in the image containing the target object. The decoder module is used to input the diffused latent variables and decode them, outputting an image containing the camouflaged target.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the camouflage target generation method based on the diffusion model as described in any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the camouflage target generation method based on the diffusion model as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Camouflage image generation method based on knowledge retrieval and reasoning enhancement
CN118052899A
Camouflage target detection method and system based on pyramid type visual Transform
CN118172540A