anytext_pytorch AIGC 可以用于生成多语言文字图像算法模型

AnyText

论文

AnyText: Multilingual Visual Text Generation And Editing

模型结构

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

其中,Auxiliary Latent Module可产生3种附加信息用以生成𝑍𝑎,其中𝑙𝑔表示字形信息,𝑙𝑝表示文字的位置信息,𝑙𝑚表示被遮盖的图像(保留背景信息)。

Text Embedding用于生成𝑐𝑡𝑒,𝑦′表示待生成的文字,𝑒𝑔表示待生成文字的图像信息,𝑦𝜃表示OCR识别模型(用于提取文字特征),𝜉表示线性层(用于约束特征尺寸),𝜏𝜃表示encoder(CLIP)。

Text-control Diffusion Pipeline用于生成目标结果,𝑧0加噪t次后获得𝑧𝑡,Text ControlNet用于生成控制信息(copy from Unet's Encoder),𝐿𝑡𝑑表示扩散模型损失。

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

算法原理

该算法借鉴ControlNet思想,并在此基础上结合了文字,图像位置等多模态信息条件,可用于多语言文本的图像生成。

环境配置

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

Dockerfile(方法二)

# 需要在对应的目录下
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://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

字体下载

下载并重命名
arialuni.ttf -> Arial_Unicode.ttf

文件结构
font/
└── Arial_Unicode.ttf

命令行

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

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

result

精度

应用场景

算法类别

AIGC

热点应用行业

零售,广媒,设计

源码仓库及问题反馈

ModelZoo / AnyText_pytorch · GitLab

参考资料

GitHub - tyxsspa/AnyText: Official implementation code of the paper <AnyText: Multilingual Visual Text Generation And Editing>

  • 23
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

技术瘾君子1573

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值