tyxsspa / AnyText
Official implementation code of the paper <AnyText: Multilingual Visual Text Generation And Editing>
AI Architecture Analysis
This repository is indexed by RepoMind. By analyzing tyxsspa/AnyText in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.
Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.
Repository Overview (README excerpt)
Crawler viewAnyText: Multilingual Visual Text Generation And Editing šNews [2025.03.03] - š„š„š„We have open-sourced AnyText2, which is faster, performs better, and allows you to set properties such as font and color for the text! See [[demo]](https://modelscope.cn/studios/iic/studio_anytext2) [[code]](https://github.com/tyxsspa/AnyText2) [[ckpt]](https://modelscope.cn/models/iic/cv_anytext2)! [2024.04.18] - šššThe training code and dataset(**AnyWord-3M**) are released! [2024.04.18] - You can merge weights from self-trained or community models into AnyText now, including all base models and LoRA models based on SD1.5. Have fun! [2024.02.21] - The evaluation code and dataset(**AnyText-benchmark**) are released. [2024.02.06] - Happy Lunar New Year Everyone! We've launched a fun app(蔨ę å 大åø/MeMeMaster) on ModelScope and HuggingFace to create cute meme stickers. Come and have fun with it! [2024.01.17] - šAnyText has been accepted by ICLR 2024(**Spotlight**)! [2024.01.04] - FP16 inference is available, 3x faster! Now the demo can be deployed on GPU with >8GB memory. Enjoy! [2024.01.04] - HuggingFace Online demo is available here! [2023.12.28] - ModelScope Online demo is available here! [2023.12.27] - š§ØWe released the latest checkpoint(v1.1) and inference code, check on ModelScope in Chinese. [2023.12.05] - The paper is available at here. For more AIGC related works of our group, please visit here, and we are seeking collaborators and research interns(Email us). ā°TODOs ⢠[x] Release the model and inference code ⢠[x] Provide publicly accessible demo link ⢠[ ] Provide a free font file(š¤) ⢠[x] Release tools for merging weights from community models or LoRAs ⢠[ ] Support AnyText in stable-diffusion-webui(š¤) ⢠[x] Release AnyText-benchmark dataset and evaluation code ⢠[x] Release AnyWord-3M dataset and training code š”Methodology AnyText comprises a diffusion pipeline with two primary elements: an auxiliary latent module and a text embedding module. The former uses inputs like text glyph, position, and masked image to generate latent features for text generation or editing. The latter employs an OCR model for encoding stroke data as embeddings, which blend with image caption embeddings from the tokenizer to generate texts that seamlessly integrate with the background. We employed text-control diffusion loss and text perceptual loss for training to further enhance writing accuracy. š Installation š®Inference **[Recommend]**ļ¼ We release a demo on ModelScope and HuggingFace! You can also try AnyText through our API service. AnyText include two modes: Text Generation and Text Editing. Running the simple code below to perform inference in both modes and verify whether the environment is correctly installed. If you have advanced GPU (with at least 8G memory), it is recommended to deploy our demo as below, which includes usage instruction, user interface and abundant examples. FP16 inference is used as default, and a Chinese-to-English translation model is loaded for direct input of Chinese prompt (occupying ~4GB of GPU memory). The default behavior can be modified, as the following command enables FP32 inference and disables the translation model: If FP16 is used and the translation model not used(or load it on CPU, see here), generation of one single 512x512 image will occupy ~7.5GB of GPU memory. In addition, other font file can be used by(although the result may not be optimal): You can also load a specified AnyText checkpoint: **Please note** that when executing inference for the first time, the model files will be downloaded to: . If you need to modify the download directory, you can manually specify the environment variable: . In this demo, you can change the style during inference by either change the base model or loading LoRA models(must based on SD1.5): ⢠Change base model: Simply fill in your local base model's path in the [Base Model Path]. ⢠Load LoRA models: Input your LoRA model's path and weight ratio into the [LoRA Path and Ratio]. For example: . šEvaluation ⢠Data Preparation Download the AnyText-benchmark dataset from ModelScope or GoogleDrive and unzip the files. In *benchmark* folder, *laion_word* and *wukong_word* are datasets for English and Chinese evaluation, respectively. Open each *test1k.json* and modify the with your own path of *imgs* folder. The *FID* directory contains images that are used for calculating the FID (FrĆ©chet Inception Distance) score. ⢠Generate Images Before evaluation, we need to generate corresponding images for each method based on the evaluation set. We have also provided pre-generated images for all methods. Follow the instructions below to generate images on you own. Note that you need modify the paths and other parameters in the bash script accordingly. ⢠AnyText ļ¼If you encounter an error caused by huggingface being blocked, please uncomment line 98 of ./models_yaml/anytext_sd15.yaml, and replace the path of the *clip-vit-large-patch14* folder with a local oneļ¼ ā¢ ControlNet, Textdiffuser, GlyphControl We use glyph images rendered from AnyText-benchmark dataset as conditional input for these methods: Next, please clone the official repositories of **ControlNet**, **Textdiffuser**, and **GlyphControl**, and follow their documentation to set up the environment, download the respective checkpoints, and ensure that inference can be executed normally. Then, copy the three files , , and from the *./eval* folder to the root directory of the corresponding codebases, and run: ⢠Evaluate We use Sentence Accuracy (Sen. ACC) and Normalized Edit Distance (NED) to evaluate the accuracy of generated text. Please run: We use the FID metric to assess the quality of generated images. Please run: Compared to existing methods, AnyText has a significant advantage in both English and Chinese text generation. Please note that we have reorganized the code and have further aligned the configuration for each method under evaluation. As a result, there mayā¦