Views
No views yet


1# 安装git(如有请跳过)
2conda install -c anaconda git
3# 克隆anytext仓库
4git clone https://github.com/tyxsspa/AnyText.git
5cd AnyText
6# 准备字库文件(推荐Arial Unicode MS,需自行下载)
7mv your/path/to/arialuni.ttf ./font/Arial_Unicode.ttf
8# 方式一:如果使用modelscope notebook最新镜像(ubuntu22.04-cuda11.8.0-py310-torch2.1.0-tf2.14.0-1.10.0),直接安装如下包即可
9pip install Pillow==9.5.0
10pip install gradio==3.50.0
11# 方式二:重新创建一个独立虚拟环境(耗时较长)
12conda env create -f environment.yaml
13conda activate anytext1from modelscope.pipelines import pipeline
2from util import save_images
3pipe = pipeline('my-anytext-task', model='damo/cv_anytext_text_generation_editing', model_revision='v1.1.1', use_fp16=True, use_translator=False)
4img_save_folder = "SaveImages"
5params = {
6 "show_debug": True,
7 "image_count": 2,
8 "ddim_steps": 20,
9}
10
11# 1. text generation
12mode = 'text-generation'
13input_data = {
14 "prompt": 'photo of caramel macchiato coffee on the table, top-down perspective, with "Any" "Text" written on it using cream',
15 "seed": 66273235,
16 "draw_pos": 'example_images/gen9.png'
17}
18results, rtn_code, rtn_warning, debug_info = pipe(input_data, mode=mode, **params)
19if rtn_code >= 0:
20 save_images(results, img_save_folder)
21# 2. text editing
22mode = 'text-editing'
23input_data = {
24 "prompt": 'A cake with colorful characters that reads "EVERYDAY"',
25 "seed": 8943410,
26 "draw_pos": 'example_images/edit7.png',
27 "ori_image": 'example_images/ref7.jpg'
28}
29results, rtn_code, rtn_warning, debug_info = pipe(input_data, mode=mode, **params)
30if rtn_code >= 0:
31 save_images(results, img_save_folder)
32print(f'Done, result images are saved in: {img_save_folder}')export CUDA_VISIBLE_DEVICES=0 && python demo.pyexport CUDA_VISIBLE_DEVICES=0 && python demo.py --use_fp32 --no_translatorexport CUDA_VISIBLE_DEVICES=0 && python demo.py --font_path your/path/to/font/file.ttf

1@article{tuo2023anytext,
2 title={AnyText: Multilingual Visual Text Generation And Editing},
3 author={Yuxiang Tuo and Wangmeng Xiang and Jun-Yan He and Yifeng Geng and Xuansong Xie},
4 year={2023},
5 eprint={2311.03054},
6 archivePrefix={arXiv},
7 primaryClass={cs.CV}
8}