Image generation method, device and medium for eliminating undesirable information in a text image
By constructing a self-attention layer SD model, training it using an image triplet dataset, adding noise and denoising it, and generating images with malicious information removed, the problem of undergeneralization of external defense measures and difficulty of internal defense measures in text-to-image models is solved, and security enhancement under adversarial prompts is achieved.
Patent Information
- Application Number
- CN202411353186.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-26
- Publication Date
- 2025-12-30
- Estimated Expiration
- 2044-09-26
AI Technical Summary
Existing text-to-image models face the problem of undergeneralization in external defense measures, while internal defense measures struggle with the technical challenges of handling visually explicit images, making it difficult to effectively identify and eliminate unwanted information.
By constructing an SD model containing a self-attention layer, training it using an image triplet dataset, adding noise and denoising it, calculating and optimizing the total loss function, and generating an image with unwanted information removed.
It effectively prevents the generation of unsafe images while maintaining the generation quality and quality of normal images, solves the technical problems existing in the prior art, and achieves enhanced security under adversarial prompts.
Smart Images

Figure CN119338948B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of text-to-image technology, and in particular to an image generation method, apparatus, device, and medium for removing unwanted information from text-to-image generation. Background Technology
[0002] With the rapid development of artificial intelligence technology, text-to-image generation models have gradually become a research hotspot. In this era of data explosion, massive amounts of text and image data provide ample resources for model training. The continuous convergence of computer vision and natural language processing has spurred the emergence of text-to-image generation models. Researchers hope to enable computers to understand semantic information in text and transform it into vivid image content, just like humans, by establishing effective model architectures such as Stable Diffusion (SD), MidJourney, and DALL·E. However, these models can also be used for unethical or illegal activities such as creating false content and spreading misleading information.
[0003] Existing technologies have proposed solutions from both external and internal perspectives, specifically:
[0004] First, external defenses employ security filters to detect inappropriate text input or image output during image generation. This approach is easy to deploy, but can be easily removed at the code level for open-source models. Furthermore, filters can also be used to review Not-Safe-For-Work (NSFW) text-image pairings and retrain Stable Diffusion 2.1 (SD-V2.1) from scratch, but this could potentially take up to 200,000 hours.
[0005] Second, internal defenses involve modifying the text-to-image model itself. Existing internal defenses aim to guide the model through sexually suggestive words, and are therefore text-dependent. These methods require predefined workplace insecurity concepts to avoid potentially unsafe areas, or fine-tuning model parameters to suppress inappropriate text.
[0006] Therefore, there is an urgent need to propose an image generation method, apparatus, device, and medium for eliminating unwanted information in text-to-image models. This would address the technical problems in existing text-to-image models, such as the undergeneralization of external defense measures, inadequacies in filtering adversarial cues and explicit images, difficulties encountered by internal defense measures in handling seemingly irrelevant but sexually suggestive words, difficulty in enumerating words, and the potential for visually explicit expressions in text-to-image models. Summary of the Invention
[0007] To overcome the problems existing in related technologies, this disclosure provides an image generation method, apparatus, device, and medium for eliminating unwanted information in text-to-image models. This addresses the technical problems in related technologies, such as the lack of generalization of external defense measures in text-to-image models, deficiencies in filtering adversarial prompts and explicit images, difficulties encountered by internal defense measures in handling seemingly irrelevant but sexually suggestive words, difficulty in enumerating words, and the potential for visually explicit expressions in text-to-image models.
[0008] This specification provides one or more embodiments of an image generation method for removing unwanted information from a text image, including the following steps:
[0009] Obtain a dataset of image triples, where each triple contains three images: a defective image, an image after the defective image has been thickly mosaicked, and a normal image;
[0010] An SD model containing a self-attention layer is constructed and trained using the dataset of image triples. The encoder of the SD model transforms the image triples into latent vector triples. Noise is added to the latent vector triples in a loop using the DDPM noise scheduler to obtain noisy latent vector triples. The self-attention layer denoises the noisy latent vector triples to obtain denoised latent vectors. The total loss function is calculated based on the output of the self-attention layer, and backpropagation is performed to perform optimization operations to obtain the trained SD model.
[0011] The text information is input into the trained SD model to generate an image with unwanted information removed.
[0012] Preferably, the self-attention layer denoises the noisy latent vector triples to obtain denoised latent vectors, specifically including the following steps:
[0013] Generate attention matrix using self-attention mechanism The noisy latent vector triplet is transformed into two vectors using an attention matrix, and the middle latent vector of the noisy latent vector triplet is transformed into a matrix using the attention matrix.
[0014] The matrix Q is multiplied by the vector K and then processed by the softmax function to obtain the self-attention matrix;
[0015] The attention matrix Multiplying the vector V with the denoised latent vector yields the denoised latent vector. .
[0016] Preferably, the total loss function includes a minimum loss function. and minimizing the loss function Specifically, it is expressed as:
[0017] ;
[0018] ;
[0019] ;
[0020] in, Hyperparameter coefficient size The hyperparameter coefficients representing the size of the defective images that need to be erased. This represents the estimation of noise components in poorly formatted images by the denoising UNet model. This represents the latent vector of the exposed image after T rounds of denoising. This represents the latent vector of the image after T rounds of denoising and mosaicking. This represents the total noise added by the noise scheduler during the process. This represents the estimation of noise components in a benign image by the denoising UNet model.
[0021] Preferably, the step of adding noise to the latent vector triples cyclically using the DDPM noise scheduler specifically includes the following steps:
[0022] The DDPM noise scheduler adds the same noise to both the bad latent vector and the mosaic-processed bad latent vector.
[0023] This specification provides one or more embodiments of an image generation apparatus for removing unwanted information from a text image, including a data acquisition module, a model training module, and an image generation module;
[0024] The data acquisition module is used to acquire a dataset of image triples, each triple containing three images: a defective image, an image after the defective image has been thickly mosaicked, and a normal image;
[0025] The model training module includes a model building unit for building an SD model containing a self-attention layer and training the SD model using the dataset of image triples; a noise addition unit for the encoder of the SD model to convert the image triples into latent vector triples and add noise to the latent vector triples in a loop using a DDPM noise scheduler to obtain noisy latent vector triples; a denoising unit for the self-attention layer to denoise the noisy latent vector triples to obtain denoised latent vectors; and an optimization unit for calculating the total loss function based on the output of the self-attention layer and performing backpropagation to perform optimization operations to obtain the trained SD model.
[0026] The image generation module is used to input text information into the trained SD model to generate an image with unwanted information removed.
[0027] Preferably, the noise reduction unit is specifically configured as follows:
[0028] Used to generate attention matrices using self-attention mechanisms The noisy latent vector triples are processed through an attention matrix. Transform into two vectors Through attention matrix The intermediate latent vector of the noisy latent vector triplet is transformed into a matrix. ;
[0029] The matrix Q is multiplied by the vector K, processed by the softmax function, and then combined to obtain the self-attention matrix. ;
[0030] The attention matrix Multiplying the vector V with the denoised latent vector yields the denoised latent vector. .
[0031] Preferably, the total loss function includes a minimum loss function. and minimizing the loss function Specifically, it is expressed as:
[0032] ;
[0033] ;
[0034] ;
[0035] in, Hyperparameter coefficient size The hyperparameter coefficients representing the size of the defective images that need to be erased. This represents the estimation of noise components in poorly formatted images by the denoising UNet model. This represents the latent vector of the exposed image after T rounds of denoising. This represents the latent vector of the image after T rounds of denoising and mosaicking. This represents the total noise added by the noise scheduler during the process. This represents the estimation of noise components in a benign image by the denoising UNet model.
[0036] Preferably, the noise adding unit is specifically configured as follows:
[0037] The same noise was added to both the bad latent vector and the mosaic-processed bad latent vector by the DDPM noise scheduler.
[0038] This specification provides one or more embodiments of a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the image generation method for removing unwanted information from the above-described text.
[0039] This specification provides one or more embodiments of a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the image generation method for removing unwanted information from a document image as described above.
[0040] This disclosure provides an image generation method, apparatus, device, and medium for removing unwanted information from textual images. Its advantages lie in acquiring a dataset containing image triplets (including unwanted images, images after thick mosaic processing of the unwanted images, and normal images), and training the model solely on image data without textual guidance. This severs the connection between the model's explicit visual representation and conceptually related sexually relevant prompts. A self-attention (SD) model is constructed, and the SD model is trained using the image triplet dataset. The encoder of the SD model transforms the image triplets into latent vector triplets, and a DDPM noise scheduler iteratively adds to the latent vector triplets. Noise is added to obtain noisy latent vector triples. The self-attention layer denoises these noisy latent vector triples to obtain denoised latent vectors. The total loss function is calculated based on the output of the self-attention layer, and backpropagation is performed to optimize the model, resulting in a trained SD model. The quality and semantics of the generated image are adjusted by unconditional denoising diffusion through the self-attention layer. Text information is input into the trained SD model to generate an image with unwanted information removed from the text-to-image representation. This allows the model to prevent the generation of unsafe images even under adversarial prompts, without affecting the quality of normal image generation. This is beneficial for subsequent targeted security enhancement of text-to-image applications. Attached Figure Description
[0041] To more clearly illustrate the technical solutions in one or more embodiments of this specification or in 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 only some embodiments recorded in this specification. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0042] Figure 1 A flowchart illustrating an image generation method for removing unwanted information from a text image, provided for one or more embodiments of this specification;
[0043] Figure 2 A schematic diagram illustrating the SD model training method provided in one or more embodiments of this specification;
[0044] Figure 3 A flowchart illustrating the process of an image generation method for removing unwanted information from a text image, provided for one or more embodiments of this specification.
[0045] Figure 4 A comparison chart showing the image generation method for removing unwanted information from raw images provided in one or more embodiments of this specification, and the removal rate of unwanted images by other methods;
[0046] Figure 5 A structural diagram of an image generation apparatus for removing unwanted information from a text image, provided for one or more embodiments of this specification;
[0047] Figure 6 This is a schematic diagram of the structure of a computer device provided for one or more embodiments of this specification. Detailed Implementation
[0048] To enable those skilled in the art to better understand the technical solutions in one or more embodiments of this specification, the technical solutions in one or more embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this specification, and not all of the embodiments. Based on one or more embodiments of this specification, all other embodiments obtained by those skilled in the art without creative effort should fall within the protection scope of this invention.
[0049] The present invention will now be described in detail with reference to specific embodiments and accompanying drawings.
[0050] Method Implementation Examples
[0051] According to embodiments of the present invention, an image generation method for removing unwanted information from text images is provided, such as... Figure 1 The diagram shown is a flowchart illustrating the image generation method for removing unwanted information from raw text images provided in this embodiment. The image generation method for removing unwanted information from raw text images according to this embodiment includes the following steps:
[0052] Step S110: Obtain an image triplet containing approximately 100 defective images, an image after thick mosaic processing of the defective images, and normal images. The dataset includes images of defective images that have been blurred using a mosaic neural network, and normal images that have been randomly sampled from the Human Detection Dataset.
[0053] Step S120: Construct an SD model containing a self-attention layer, utilizing the image triples. The SD model is trained on the dataset, such as Figure 2 The diagram shown is a schematic of the SD model training method provided in this embodiment, wherein the encoder of the SD model processes the image triples. Transform into latent vector triples superscript These are respectively represented as a defective image, an image after the defective image has been heavily pixelated, and a normal image. The subscript represents the time step, with a value of [value missing]. Noise is added to the latent vector triples cyclically using the DDPM (Denoising Diffusion Probabilistic Models) noise scheduler. This yields noisy implicit vector triples. The DDPM noise scheduler adds the same noise to both the bad latent vector and the mosaic-processed bad latent vector. Given blank text input, the self-attention layer of the U-Net structure in the SD model processes the noisy hidden vector triples. Denoising is performed from its attention matrix. The process involves progressively removing the connections between sex-related text and poor visual representations to obtain denoised latent vectors, such as... Figure 3 The diagram shown is a flowchart of an image generation method for removing unwanted information from a text image provided in this embodiment.
[0054] Simultaneously, the total loss function is calculated based on the output of the self-attention layer, gradient descent optimization is performed using the Adam optimizer, and backpropagation is performed to update the parameters related to the self-attention layer in the U-Net structure.
[0055] Step S130: Input the text information into the trained SD model to generate an image with unwanted information removed.
[0056] The method provided in this embodiment acquires a dataset containing image triplets, including inappropriate images, images of the inappropriate images after heavy mosaic processing, and normal images. It trains the model solely on image data, without textual guidance, thus severing the connection between the model's explicit visual representation and conceptually related sexually relevant prompts. An SD model containing a self-attention layer is constructed and trained using the image triplet dataset. The encoder of the SD model transforms the image triplets into latent vector triplets, and a DDPM noise scheduler iteratively adds noise to the latent vector triplets to obtain noisy latent vector triplets. The self-attention layer denoises the noisy latent vector triples to obtain denoised latent vectors. Based on the output of the self-attention layer, the total loss function is calculated, and backpropagation is performed to optimize the model, resulting in a trained SD model. The unconditional denoising diffusion of the self-attention layer adjusts the quality and semantics of the images generated by the model. Text information is input into the trained SD model to generate images without inappropriate content. This allows the model to prevent the generation of unsafe images even under adversarial prompts, without affecting the quality of normal image generation. This facilitates subsequent targeted security enhancements for text-to-image applications.
[0057] In one embodiment, classifier-independent image generation guidance is widely used, which includes a conditional denoising diffusion process. With an unconditional denoising diffusion process The noise predicted at time step t. It can be calculated using the following formula:
[0058] ;
[0059] Among them, the guiding scale parameters When the time (usually set to 7.5), the predicted noise tends to favor the conditional score and gradually deviates from the unconditional score. After this iterative denoising process is completed, It can then be converted to image space using a pre-trained decoder. .
[0060] In the denoising process, the conditional denoising diffusion process is implemented across the attention layer, while the unconditional denoising diffusion process is implemented by the self-attention layer. Specifically, the self-attention layer denoises the noisy latent vector triples to obtain the denoised latent vectors, which includes the following steps:
[0061] Generate attention matrix using self-attention mechanism The noisy hidden vector triples Through attention matrix Transform into two vectors Through attention matrix The noisy latent vector triples The intermediate implicit vector is transformed into a matrix. .
[0062] The matrix Q is multiplied by the vector K, processed by the softmax function, and then combined to obtain the self-attention matrix. .
[0063] The attention matrix Multiplying the vector V with the denoised latent vector yields the denoised latent vector. It contains important information that is preserved during the noise reduction process.
[0064] The method provided in this embodiment can more comprehensively understand visual information, sever the connection between explicit visual representations and conceptual sexually related cues, and ultimately effectively prevent the generation of inappropriate images.
[0065] In one embodiment, the optimization objective of the SD model is for U-Net to progressively denoise the latent vectors of noisy, defective images until they become noise-free images after thick mosaic processing of the defective images, i.e., the latent vectors. At the same time, it ensures that the latent vectors of a noisy, normal, unexposed image are transformed into the latent vectors of a noise-free, normal, unexposed image, i.e., the latent vectors... Therefore, the total loss function is designed to include the minimum loss function. and minimizing the loss function Minimize the loss function This allows the self-attention layer to remove representations of poorly formatted images, such as mapping them to latent vectors that have been heavily pixelated, while minimizing the loss function. This ensures that these layers maintain the representation quality of a normal image and avoid parameter shifts, specifically as follows:
[0066] ;
[0067] ;
[0068] ;
[0069] in, Hyperparameter coefficient size The hyperparameter coefficients representing the size of the defective images that need to be erased. This represents the estimation of noise components in poorly formatted images by the denoising UNet model. This represents the latent vector of the exposed image after T rounds of denoising. This represents the latent vector of the image after T rounds of denoising and mosaicking. This represents the total noise added by the noise scheduler during the process. This represents the estimation of noise components in a benign image by the denoising UNet model.
[0070] Furthermore, noise It follows a normal distribution and is added to the original latent vector each time. noise All of these are predefined by the DDPM noise scheduler. In other words, This represents the total noise added during the noise addition process, which is: Similarly, This represents the U-Net after adjustments at the self-attention layer. The predicted total noise. Experiments showed that setting the scaling parameter to... This allows the model to best achieve the goal of blocking inappropriate images while preserving normal images. For example... Figure 4 The image shown is a comparison chart of the removal rate of unwanted images by the image generation method for removing unwanted information in the text image provided in this embodiment and other methods.
[0071] The method provided in this embodiment, by setting a loss function that enables the self-attention layer to remove representations of bad images and maintains the representation quality of normal images while avoiding parameter shifts, enables the model to best achieve the blocking of bad images and the preservation of normal images.
[0072] Device Examples
[0073] According to embodiments of the present invention, an image generation apparatus for removing unwanted information from raw text images is provided, such as... Figure 5 The diagram shown is a structural diagram of the image generation device for removing unwanted information from a raw image provided in this embodiment. The image generation device for removing unwanted information from a raw image according to this embodiment includes a data acquisition module, a model training module, and an image generation module.
[0074] The data acquisition module 510 is used to acquire a dataset containing image triplets of defective images, images after thick mosaic processing of the defective images, and normal images.
[0075] The model training module 520 includes a model building unit for building an SD model containing a self-attention layer and training the SD model using the dataset of image triples; a noise addition unit for the encoder of the SD model to convert the image triples into latent vector triples and add noise to the latent vector triples cyclically using a DDPM noise scheduler to obtain noisy latent vector triples; specifically, the DDPM noise scheduler adds the same noise to bad latent vectors and bad latent vectors after mosaic processing; a denoising unit for the self-attention layer to denoise the noisy latent vector triples to obtain denoised latent vectors; and an optimization unit for calculating the total loss function based on the output of the self-attention layer and performing backpropagation to perform optimization operations to obtain the trained SD model.
[0076] Image generation module 530 is used to input text information into a trained SD model to generate an image with unwanted information removed.
[0077] The apparatus provided in this embodiment acquires a dataset containing image triplets, including defective images, images of the defective images after thick mosaic processing, and normal images, through a data acquisition module 510. The model is trained solely on the image data, without the need for textual data guidance, thus severing the connection between the model's explicit visual representation and conceptually related sexual prompts. A self-attention layer-based SD model is constructed through a model training module 520. This SD model is trained using the image triplet dataset. The encoder of the SD model converts the image triplets into latent vector triplets, and a DDPM noise scheduler iteratively adds noise to these latent vector triplets, resulting in a noisy dataset. The latent vector triplet of sound is denoised by the self-attention layer to obtain the denoised latent vector. The total loss function is calculated based on the output of the self-attention layer, and backpropagation is performed to perform optimization operations to obtain the trained SD model. The quality and semantics of the image generated by the model are adjusted by the unconditional denoising diffusion of the self-attention layer. The text information is input into the trained SD model through the image generation module 530 to generate an image with the bad information removed. This enables the model to prevent the generation of unsafe images even under the guidance of adversarial prompts, without affecting the quality of normal image generation. This is beneficial for subsequent targeted security enhancement of text-to-image applications.
[0078] In one embodiment, the noise reduction unit is specifically configured as follows:
[0079] Used to generate attention matrices using self-attention mechanisms The noisy latent vector triples are processed through an attention matrix. Transform into two vectors Through attention matrix The intermediate latent vector of the noisy latent vector triplet is transformed into a matrix. .
[0080] The matrix Q is multiplied by the vector K, processed by the softmax function, and then combined to obtain the self-attention matrix. .
[0081] The attention matrix Multiplying the vector V with the denoised latent vector yields the denoised latent vector. .
[0082] The device provided in this embodiment can more comprehensively understand visual information, sever the connection between explicit visual representations and conceptual sexually related cue words, and ultimately effectively prevent the generation of inappropriate images.
[0083] In one embodiment, the total loss function includes a minimum loss function. and minimizing the loss function Specifically, it is expressed as:
[0084] ;
[0085] ;
[0086] ;
[0087] in, Hyperparameter coefficient size The hyperparameter coefficients representing the size of the defective images that need to be erased. This represents the estimation of noise components in poorly formatted images by the denoising UNet model. This represents the latent vector of the exposed image after T rounds of denoising. This represents the latent vector of the image after T rounds of denoising and mosaicking. This represents the total noise added by the noise scheduler during the process. This represents the estimation of noise components in a benign image by the denoising UNet model.
[0088] The apparatus provided in this embodiment, by setting a loss function that enables the self-attention layer to remove the representation of defective images and maintains the representation quality of normal images while avoiding parameter shifts, enables the model to best realize defective images. This embodiment of the invention is an apparatus embodiment corresponding to the above method embodiment. The specific operation of each module processing step can be understood by referring to the description of the method embodiment, and will not be repeated here.
[0089] like Figure 6As shown, the present invention also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, it implements the image generation method for removing unwanted information from the text image in the above embodiments, or when the computer program is executed by a processor, it implements the image generation method for removing unwanted information from the text image in the above embodiments.
[0090] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, 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), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0091] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for apparatus or system embodiments, since they are basically similar to method embodiments, the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments. The apparatus and system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0092] 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 them. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features. These modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention, and the contents not described in detail in the specification of the present invention are well known to those skilled in the art.
Claims
1. An image generation method for eliminating undesirable information in a natural image, characterized by, The method comprises the following steps: obtaining a data set comprising an image triplet of an unhealthy picture, a picture after thick mosaic processing of the unhealthy picture and a normal picture; constructing a Stable Diffusion model comprising a self-attention layer, training the Stable Diffusion model by using the data set of the image triplet, wherein an encoder of the Stable Diffusion model converts the image triplet into a latent vector triplet, noise is added to the latent vector triplet through a Denoising Diffusion Probabilistic Models noise scheduler cycle, wherein the Denoising Diffusion Probabilistic Models noise scheduler adds the same noise to an unhealthy latent vector and a mosaic-processed unhealthy latent vector to obtain a latent vector triplet full of noise, the self-attention layer denoises the latent vector triplet full of noise under the input of blank text information to obtain a denoised latent vector, a total loss function is calculated according to the output result of the self-attention layer, and an optimization operation is performed through back propagation to obtain a trained Stable Diffusion model; inputting text information into the trained Stable Diffusion model to generate an image eliminating unhealthy information.
2. The image generation method of claim 1, wherein, The self-attention layer denoises the latent vector triplet full of noise to obtain a denoised latent vector, and specifically comprises the following steps: Generating an attention matrix using self-attention mechanisms the noisy latent vector triplets through an attention matrix into two vectors the intermediate latent vector of the noisy latent vector triplets into a matrix through an attention matrix ; After multiplying the matrix Q with the vector K , and processing it through a softmax function, the self-attention matrix is obtained. the attention matrix multiplying the vector V to obtain a denoised latent vector .
3. The image generation method of claim 1, wherein, The total loss function includes a minimum loss function and a minimization loss function , specifically represented as: ; ; ; wherein, a hyperparameter coefficient size, a hyperparameter coefficient size representing a bad picture that needs to be erased, an estimate of the noise component in the bad picture by the denoising UNet model, a latent vector representing a bad picture, a latent vector representing a naked picture after T times of denoising, a latent vector representing a mosaic picture after T times of denoising, noise added by the noise scheduler, an estimate of the noise component in the benign picture by the denoising UNet model, a latent vector representing a normal picture.
4. An image generating apparatus for eliminating undesirable information in a natural image, characterized by comprising: comprising a data acquisition module, a model training module and an image generation module; The data acquisition module is configured to acquire a data set comprising an image triplet of an unhealthy picture, a picture after thick mosaic processing of the unhealthy picture and a normal picture; The model training module comprises a model construction unit configured to construct a Stable Diffusion model comprising a self-attention layer, and train the Stable Diffusion model by using the data set of the image triplet, a noise adding unit configured to convert the image triplet into a latent vector triplet through an encoder of the Stable Diffusion model, add noise to the latent vector triplet through a Denoising Diffusion Probabilistic Models noise scheduler cycle, wherein the Denoising Diffusion Probabilistic Models noise scheduler adds the same noise to an unhealthy latent vector and a mosaic-processed unhealthy latent vector to obtain a latent vector triplet full of noise, a denoising unit configured to denoise the latent vector triplet full of noise through the self-attention layer under the input of blank text information to obtain a denoised latent vector, and an optimization unit configured to calculate a total loss function according to the output result of the self-attention layer, and perform an optimization operation through back propagation to obtain a trained Stable Diffusion model; The image generation module is configured to input the text information into the trained Stable Diffusion model to generate an image without undesirable information.
5. The image generation apparatus of claim 4, wherein The denoising unit is specifically configured to: Generating attention matrix using self-attention mechanism , the noise-filled hidden vector triplets are transformed into two vectors by an attention matrix , the noise-filled hidden vector triplets are transformed into two vectors by an attention matrix ; After multiplying the matrix Q with the vector K and processing through a softmax function, a self-attention matrix is obtained ; the attention matrix multiplying the vector V to obtain a denoised latent vector .
6. The image generation apparatus of claim 4, wherein The total loss function includes a minimum loss function and a minimization loss function , specifically represented as: ; ; ; wherein, a hyperparameter coefficient size, a hyperparameter coefficient size representing a bad picture that needs to be erased, an estimate of the noise component in the bad picture by the denoising UNet model, a latent vector representing a bad picture, a latent vector representing a naked picture after T times of denoising, a latent vector representing a mosaic picture after T times of denoising, noise added by the noise scheduler, an estimate of the noise component in the benign picture by the denoising UNet model, a latent vector representing a normal picture.
7. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, The processor executes the computer program to implement the image generation method for eliminating undesirable information in text-to-image as claimed in any one of claims 1 to 3.
8. A computer-readable storage medium storing a computer program, the computer-readable storage medium comprising: The computer program is executed by the processor to implement the steps of the image generation method for eliminating undesirable information in text-to-image as claimed in any one of claims 1 to 3.