README.md 4.98 KB
Newer Older
mashun1's avatar
anytext  
mashun1 committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# AnyText

## 论文

**AnyText: Multilingual Visual Text Generation And Editing**

* https://arxiv.org/abs/2311.03054

## 模型结构

模型由4部分构成,分别是`Auxiliary Latent Module``Text Embedding Module``Text-control Diffusion Pipeline`以及`Text Preceptual Loss`

其中,`Auxiliary Latent Module`可产生3种附加信息用以生成$`Z_a`$,其中$`l_g`$表示字形信息,$`l_p`$表示文字的位置信息,$`l_m`$表示被遮盖的图像(保留背景信息)。

`Text Embedding`用于生成$`c_{te}`$,$`y'`$表示待生成的文字,$`e_g`$表示待生成文字的图像信息,$`y_{\theta}`$表示OCR识别模型(用于提取文字特征),$`\xi`$表示线性层(用于约束特征尺寸),$`\tau_{\theta}`$表示encoder(CLIP)。

`Text-control Diffusion Pipeline`用于生成目标结果,$`z_0`$加噪t次后获得$`z_t`$,`Text ControlNet`用于生成控制信息(copy from Unet's Encoder),$`L_{td}`$表示扩散模型损失。

`Text Preceptual Loss`用于进一步提升文字生成的准确率。

![Alt text](readme_imgs/image-1.png)

## 算法原理

用途:该算法可以用于多语言文本图像生成。

原理:

该算法与`ControlNet`原理相似,结合了文字,图像位置等多模态信息条件。

![Alt text](readme_imgs/image-2.png)

## 环境配置


### Docker(方法一)

    docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:1.13.1-centos7.6-dtk-23.04.1-py39-latest
    docker run --shm-size 10g --network=host --name=anytext --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v 项目地址(绝对路径):/home/ -it <your IMAGE ID> bash

    cd BasicSR
    pip install -r requirements.txt
    cd ..
    pip install -r requirements.txt

### Docker(方法二)

    # 需要在对应的目录下
    docker build -t <IMAGE_NAME>:<TAG> .
    # <your IMAGE ID>用以上拉取的docker的镜像ID替换
    docker run -it --shm-size 10g --network=host --name=anytext --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined <your IMAGE ID> bash

    cd BasicSR
    pip install -r requirements.txt
    cd ..
    pip install -r requirements.txt

### Anaconda (方法三)
1、关于本项目DCU显卡所需的特殊深度学习库可从光合开发者社区下载安装:
https://developer.hpccube.com/tool/

    DTK驱动:dtk23.04.1
    python:python3.9
    torch:1.13.1
    torchvision:0.14.1
    torchaudio:0.13.1
    deepspeed:0.9.2
    apex:0.1

Tips:以上dtk驱动、python、torch等DCU相关工具版本需要严格一一对应

2、其它非特殊库参照requirements.txt安装

    cd BasicSR
    pip install -r requirements.txt
    cd ..
    pip install -r requirements.txt

## 数据集

无(暂未开源)

## 推理

### 模型下载

https://modelscope.cn/models/iic/cv_anytext_text_generation_editing/files

https://huggingface.co/openai/clip-vit-large-patch14/tree/main

    damo/
    └── cv_anytext_text_generation_editing
        ├── anytext_v1.1.ckpt
        ├── clip-vit-large-patch14
        │   ├── config.json
        │   ├── merges.txt
        │   ├── preprocessor_config.json
        │   ├── pytorch_model.bin
        │   ├── README.md
        │   ├── special_tokens_map.json
        │   ├── tokenizer_config.json
        │   ├── tokenizer.json
        │   └── vocab.json
        ├── configuration.json
        ├── description
        │   ├── eval.jpg
        │   ├── framework.jpg
        │   ├── gallary.png
        │   └── sample.jpg
        ├── ms_wrapper.py
        ├── nlp_csanmt_translation_zh2en
        │   ├── bpe.en
        │   ├── bpe.zh
        │   ├── configuration.json
        │   ├── README.md
        │   ├── resources
        │   │   ├── csanmt-model.png
        │   │   ├── ctl.png
        │   │   └── sampling.png
        │   ├── src_vocab.txt
        │   ├── tf_ckpts
        │   │   ├── checkpoint
        │   │   ├── ckpt-0.data-00000-of-00001
        │   │   ├── ckpt-0.index
        │   │   └── ckpt-0.meta
        │   ├── train.en
        │   ├── train.zh
        │   └── trg_vocab.txt
        └── README.md

### 命令行

    # 快速运行
    export ATTN_PRECISION=fp16
    CUDA_VISIBLE_DEVICES=x python inference.py

    # graido客户端运行
    export ATTN_PRECISION=fp16
    CUDA_VISIBLE_DEVICES=x python demo.py

## 训练



## result

![Alt text](readme_imgs/image-3.jpg)

![Alt text](readme_imgs/image-4.png)

### 精度



## 应用场景

### 算法类别

`AIGC`

### 热点应用行业

`零售,广媒,设计`

## 源码仓库及问题反馈

https://developer.hpccube.com/codes/modelzoo/anytext_pytorch

## 参考资料

https://github.com/tyxsspa/AnyText