多尺度内容聚合与风格对比学习的字体生成模型
FontDiffuser是一个基于多尺度内容聚合和风格对比学习的字体生成模型。它能够生成新颖字符和风格,支持跨语言生成(如中文到韩文)。该模型在处理复杂字符和大幅风格变化方面表现优异,达到了领先水平。FontDiffuser生成的结果可与InstructPix2Pix结合用于进一步装饰。项目开源并提供在线演示。
模型 | 检查点 | 状态 |
---|---|---|
FontDiffuer | 谷歌云盘 / 百度网盘:gexg | 已发布 |
SCR | 谷歌云盘 / 百度网盘:gexg | 已发布 |
克隆此仓库:
git clone https://github.com/yeungchenwa/FontDiffuser.git
步骤 0: 从官方网站下载并安装Miniconda。
步骤 1: 创建一个conda环境并激活它。
conda create -n fontdiffuser python=3.9 -y conda activate fontdiffuser
步骤 2: 按照这里安装相关版本的Pytorch。
# 建议 pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu117
步骤 3: 安装所需的包。
pip install -r requirements.txt
训练数据文件树应为(数据示例显示在目录data_examples/train/
中):
├──data_examples
│ └── train
│ ├── ContentImage
│ │ ├── char0.png
│ │ ├── char1.png
│ │ ├── char2.png
│ │ └── ...
│ └── TargetImage.png
│ ├── style0
│ │ ├──style0+char0.png
│ │ ├──style0+char1.png
│ │ └── ...
│ ├── style1
│ │ ├──style1+char0.png
│ │ ├──style1+char1.png
│ │ └── ...
│ ├── style2
│ │ ├──style2+char0.png
│ │ ├──style2+char1.png
│ │ └── ...
│ └── ...
在运行训练脚本(包括以下三种模式)之前,您应通过以下方式设置训练配置,例如分布式训练:
accelerate config
即将推出 ...
sh train_phase_1.sh
data_root
: 数据根目录,如./data_examples
output_dir
: 训练输出日志和检查点保存目录。resolution
: 我们扩散模型中UNet的分辨率。style_image_size
: 风格图像的分辨率,可以与resolution
不同。content_image_size
: 内容图像的分辨率,应与resolution
相同。channel_attn
: 是否在MCA块中使用通道注意力。train_batch_size
: 训练中的批量大小。max_train_steps
: 训练步骤的最大值。learning_rate
: 训练时的学习率。ckpt_interval
: 训练时检查点保存间隔。drop_prob
: 无分类器指导训练概率。完成第二阶段训练后,你应该将训练好的检查点文件(unet.pth
、content_encoder.pth
和style_encoder.pth
)放入phase_1_ckpt
目录。在第二阶段,这些参数将被恢复使用。
sh train_phase_2.sh
phase_2
:第二阶段训练的标签。phase_1_ckpt_dir
:第一阶段训练后的模型检查点保存目录。scr_ckpt_path
:预训练SCR模块的检查点路径。你可以从上面的🔥模型库下载。sc_coefficient
:用于监督的风格对比损失系数。num_neg
:负样本数量,默认为16
。选项(1)从GoogleDrive / 百度网盘:gexg下载检查点,然后将ckpt
放到根目录,包括文件unet.pth
、content_encoder.pth
和style_encoder.pth
。
选项(2)将你重新训练的检查点文件夹ckpt
放到根目录,包括文件unet.pth
、content_encoder.pth
和style_encoder.pth
。
(1)从内容图像和参考图像采样。
sh script/sample_content_image.sh
ckpt_dir
:模型检查点保存目录。content_image_path
:内容/源图像路径。style_image_path
:风格/参考图像路径。save_image
:如果保存为图像则设置为True
。save_image_dir
:图像保存目录,保存的文件包括out_single.png
和out_with_cs.png
。device
:采样设备,推荐使用GPU加速。guidance_scale
:无分类器采样引导比例。num_inference_steps
:DPM-Solver++的推理步骤数。(2)从内容字符采样。 注意 你可能需要一个包含大量中文字符的ttf文件,可以从百度网盘:wrth下载。
sh script/sample_content_character.sh
character_input
:如果设置为True
,则使用字符串作为内容/源输入。content_character
:内容/源内容字符串。gradio gradio_app.py
示例:
<p align="center"> <img src="https://yellow-cdn.veclightyear.com/835a84d5/d8c317d2-5d1d-4789-8dba-4d3dec1b8a0c.png" width="80%" height="auto"> </p>即将推出...
@inproceedings{yang2024fontdiffuser,
title={FontDiffuser: One-Shot Font Generation via Denoising Diffusion with Multi-Scale Content Aggregation and Style Contrastive Learning},
author={Yang, Zhenhua and Peng, Dezhi and Kong, Yuxin and Zhang, Yuyi and Yao, Cong and Jin, Lianwen},
booktitle={Proceedings of the AAAI conference on artificial intelligence},
year={2024}
}
最强AI数据分析助手
小浣熊家族Raccoon,您的AI智能助手,致力于通过先进的人工智能技术,为用户提供高效、便捷的智能服务。无论是日常咨询还是专业问题解答,小浣熊都能以快速、准确的响应满足您的需求,让您的生活更加智能便捷。
像人一样思考的AI智能体
imini 是一款超级AI智能体,能根据人类指令,自主思考、自主完成、并且交付结果的AI智能体。
AI数字人视频创作平台
Keevx 一款开箱即用的AI数字人视频创作平台,广泛适用于电商广告、企业培训与社媒宣传,让全球企业与个人创作者无需拍摄剪辑,就能快速生成多语言、高质量的专业视频。
一站式AI创作平台
提供 AI 驱动的图片、视频生成及数字人等功能,助力创意创作