UniControl

UniControl

优化多任务条件生成的统一扩散模型

UniControl项目展示了一种新的多任务条件生成模型,支持多种语言提示,通过增强的预训练文本到图像扩散模型和任务感知的HyperNet,实现高精度图像生成和多任务适应。实验结果表明,UniControl在多个单任务控制方法上表现更佳,是可控视觉生成领域的重要进展。

UniControl控制生成视觉生成模型训练任务推理Github开源项目

UniControl arXiv webpage HuggingFace space

<div align="center"> <a><img src="https://yellow-cdn.veclightyear.com/35dd4d3f/c69c2b66-163b-45d0-a521-00309df00a98.png" height="100px" ></a> <a><img src="https://yellow-cdn.veclightyear.com/35dd4d3f/da881f36-d6d1-4580-b753-e8aaea4b8ca8.png" height="100px" ></a> <a><img src="https://yellow-cdn.veclightyear.com/35dd4d3f/2d822ee7-1dd9-4ef5-8e96-0adc887ef762.png" height="100px" ></a> </div>

这个代码库对应的论文是:

UniControl: A Unified Diffusion Model for Controllable Visual Generation In the Wild
Can Qin <sup>1,2</sup>, Shu Zhang<sup>1</sup>, Ning Yu <sup>1</sup>, Yihao Feng<sup>1</sup>, Xinyi Yang<sup>1</sup>, Yingbo Zhou <sup>1</sup>, Huan Wang <sup>1</sup>, Juan Carlos Niebles<sup>1</sup>, Caiming Xiong <sup>1</sup>, Silvio Savarese <sup>1</sup>, Stefano Ermon <sup>3</sup>, Yun Fu <sup>2</sup>, Ran Xu <sup>1</sup>
<sup>1</sup> Salesforce AI <sup>2</sup> Northeastern University <sup>3</sup> Stanford University
当Can Qin在Salesforce AI Research实习时完成的工作。

img

介绍

我们介绍了UniControl,一个新的生成基础模型,它在一个框架内整合了广泛的可控条件到图像(C2I)任务,同时仍然允许任意的语言提示。UniControl实现了像素级精确的图像生成,视觉条件主要影响生成的结构,语言提示引导风格和背景。为了让UniControl具备处理多样化视觉条件的能力,我们增强了预训练的文本-图像扩散模型,并引入了一个任务感知的HyperNet来调节扩散模型,使其能够同时适应不同的C2I任务。实验结果表明,UniControl通常表现优于具有相似模型大小的单任务控制方法。这种控制的多样性使UniControl在可控视觉生成领域中成为一项重要的进步。

img

更新

  • 05/18/23: UniControl 论文上传到 arXiv.
  • 05/26/23: UniControl 推理代码和检查点公开。
  • 05/28/23: 最新的UniControl模型 检查点 (1.4B 参数, 5.78GB) 更新。
  • 06/08/23: 最新的UniControl模型 检查点 更新,现在支持12个任务(Canny, HED, Sketch, Depth, Normal, Skeleton, Bbox, Seg, Outpainting, Inpainting, DeblurringColorization) !
  • 06/08/23: 训练数据集 (MultiGen-20M) 完全发布。
  • 06/08/23: 训练代码公开。:blush:
  • 07/06/23: 最新的UniControl模型 v1.1 检查点 更新,现在支持12个任务(Canny, HED, Sketch, Depth, Normal, Skeleton, Bbox, Seg, Outpainting, Inpainting, DeblurringColorization) !
  • 07/25/23: Huggingface Demo API 可用了! HuggingFace space
  • 07/25/23: Safetensors 模型可用了! 检查点
  • 09/21/23: UniControl 被NeurIPS 2023接收。:blush:

MultiGen-20M 数据集

这里有超过2000万个图像-提示-条件三元组 此处,总大小 > 2TB。它包括所有12个任务(Canny, HED, Sketch, Depth, Normal, Skeleton, Bbox, Seg, Outpainting, Inpainting, Deblurring, Colorization),完全发布。

指导

环境准备

首先设置环境(需要等待几分钟)。

conda env create -f environment.yaml
conda activate unicontrol

检查点准备

预训练的UniControl模型的检查点保存在 ./ckpts/unicontrol.ckpt

cd ckpts
wget https://storage.googleapis.com/sfr-unicontrol-data-research/unicontrol.ckpt 

你也可以使用最新的训练模型(ckpt和safetensors)

wget https://storage.googleapis.com/sfr-unicontrol-data-research/unicontrol_v1.1.ckpt
wget https://storage.googleapis.com/sfr-unicontrol-data-research/unicontrol_v1.1.st

如果你想从头开始训练,请按照ControlNet的指南准备检查点初始化。ControlNet提供了一个简单的脚本帮助你轻松实现。如果你的SD文件名是 ./ckpts/v1-5-pruned.ckpt,并且你希望把处理后的模型(SD+ControlNet)保存在 ./ckpts/control_sd15_ini.ckpt 位置,你可以运行:

python tool_add_control.py ./ckpts/v1-5-pruned.ckpt ./ckpts/control_sd15_ini.ckpt

数据准备

请下载训练数据集 (MultiGen-20M) 到 ./multigen20m。请:

cd multigen20m
gsutil -m cp -r gs://sfr-unicontrol-data-research/dataset ./

然后解压所有文件。

模型训练 (需要CUDA 11.0和Conda 4.12.0)

从头开始训练:

python train_unicontrol.py --ckpt ./ckpts/control_sd15_ini.ckpt --config ./models/cldm_v15_unicontrol_v11.yaml --lr 1e-5

模型微调:

python train_unicontrol.py --ckpt ./ckpts/unicontrol.ckpt  --config ./models/cldm_v15_unicontrol.yaml --lr 1e-7

模型推理 (需要CUDA 11.0和Conda 4.12.0)

对于不同的任务,请运行如下代码。如果遇到OOM错误,请减少 "--num_samples"。

如果你使用的是safetensors模型,可以按照 ./load_model/load_safetensors_model.py 加载模型。

Canny到图像生成:

python inference_demo.py --ckpt ./ckpts/unicontrol.ckpt --task canny

HED边缘到图像生成:

python inference_demo.py --ckpt ./ckpts/unicontrol.ckpt --task hed 

HED风格的素描到图像生成:

python inference_demo.py --ckpt ./ckpts/unicontrol.ckpt --task hedsketch

深度图到图像生成:

python inference_demo.py --ckpt ./ckpts/unicontrol.ckpt --task depth 

法线图到图像生成:

python inference_demo.py --ckpt ./ckpts/unicontrol.ckpt --task normal

分割图到图像生成:

python inference_demo.py --ckpt ./ckpts/unicontrol.ckpt --task seg

人体骨架到图像生成:

python inference_demo.py --ckpt ./ckpts/unicontrol.ckpt --task openpose

物体边界框到图像生成:

python inference_demo.py --ckpt ./ckpts/unicontrol.ckpt --task bbox

图像外绘:

python inference_demo.py --ckpt ./ckpts/unicontrol.ckpt --task outpainting

图像修补:

python inference_demo.py --ckpt ./ckpts/unicontrol.ckpt --task inpainting

图像去模糊:

python inference_demo.py --ckpt ./ckpts/unicontrol.ckpt --task blur

图像上色:

python inference_demo.py --ckpt ./ckpts/unicontrol.ckpt --task grayscale

Gradio Demo (应用示例视频, 需要CUDA 11.0和Conda 4.12.0)

我们为不同任务提供了Gradio demos。示例图像保存在 ./test_imgs

<div align="center"> <a><img src="https://yellow-cdn.veclightyear.com/35dd4d3f/c960c87d-9c6b-4ad8-9280-ebc0089ca403.png" height="450px" ></a> </div>

对于所有任务 (Canny, HED, Sketch, Depth, Normal, Human Pose, Seg, Bbox, Outpainting, Colorization, Deblurring, Inpainting) 请运行以下代码:

python app/gradio_all_tasks.py
<div align="center"> <a><img src="https://yellow-cdn.veclightyear.com/35dd4d3f/ec7658bc-6d76-4b31-a1e3-d3255c3e5d13.png" height="450px" ></a> </div>

我们支持直接从条件到图像的生成(如上图所示)。如果您希望直接上传条件图像,请在UI中取消选中条件提取


或者,我们提供特定任务的Gradio演示:

<div align="center"> <a><img src="https://yellow-cdn.veclightyear.com/35dd4d3f/5dcb1118-01da-4468-b3a0-b97d0448f099.png" height="450px" ></a> </div>

Canny到图像生成:

python app/gradio_canny2image.py

<div align="center"> <a><img src="https://yellow-cdn.veclightyear.com/35dd4d3f/fcf81eb4-1fd2-4b5c-9a02-a0d047289053.png" height="450px" ></a> </div>

HED边缘到图像生成:

python app/gradio_hed2image.py

<div align="center"> <a><img src="https://yellow-cdn.veclightyear.com/35dd4d3f/d5d13406-784b-468d-a613-093096ef2d30.png" height="450px" ></a> </div>

类似HED的素描到图像生成:

python app/gradio_hedsketch2image.py

<div align="center"> <a><img src="https://yellow-cdn.veclightyear.com/35dd4d3f/9508900e-6c76-4da0-aaab-36ce864a70e7.png" height="450px" ></a> </div>

深度图到图像生成:

python app/gradio_depth2image.py

<div align="center"> <a><img src="https://yellow-cdn.veclightyear.com/35dd4d3f/abf389a9-2eaa-4975-a6a3-f1424a5ded53.png" height="450px" ></a> </div>

法线表面图到图像生成:

python app/gradio_normal2image.py

<div align="center"> <a><img src="https://yellow-cdn.veclightyear.com/35dd4d3f/a7f94f81-72c4-483d-8b0c-df5cb452e7b4.png" height="450px" ></a> </div>

分割地图到图像生成:

python app/gradio_seg2image.py

<div align="center"> <a><img src="https://yellow-cdn.veclightyear.com/35dd4d3f/2678ab0e-6d94-4008-80fd-ee6b76fcec16.png" height="450px" ></a> </div>

人体骨架到图像生成:

python app/gradio_pose2image.py

<div align="center"> <a><img src="https://yellow-cdn.veclightyear.com/35dd4d3f/ed554e4a-e9ed-4eb0-ae6a-6837f6df8e25.png" height="450px" ></a> </div>

对象边界框到图像生成:

python app/gradio_bbox2image.py

<div align="center"> <a><img src="https://yellow-cdn.veclightyear.com/35dd4d3f/1210f27e-225c-41ed-a8c0-218ce4784283.png" height="450px" ></a> </div>

图像延展:

python app/gradio_outpainting.py

<div align="center"> <a><img src="https://yellow-cdn.veclightyear.com/35dd4d3f/a7c789e1-d025-438a-8556-cf8c814a4f2e.png" height="450px" ></a> </div>

图像上色:

python app/gradio_colorization.py

<div align="center"> <a><img src="https://yellow-cdn.veclightyear.com/35dd4d3f/aacd44a7-ee7e-41f7-8e80-0c6d13c611d0.png" height="450px" ></a> </div>

图像去模糊:

python app/gradio_deblur.py

<div align="center"> <a><img src="https://yellow-cdn.veclightyear.com/35dd4d3f/306a2a12-abb7-4bd2-b103-ff13133f319d.png" height="450px" ></a> </div>

图像修补:

python app/gradio_inpainting.py

待办事项

  • 数据准备
  • 预训练任务推理
  • Gradio演示
  • 模型训练
  • HF空间
  • Colab

提示

  • 负面提示有时非常有用: 黑白,低分辨率,糟糕的解剖结构,最差的质量,低质量 是负面提示的例子。

  • UniControl在某些任务上(如上色和去模糊)可以在没有任何文本提示的情况下表现良好。

  • 如果内存不足,使用 --num_samples 1 可能会有帮助

引用

如果您发现此项目对您的研究有用,请引用我们的论文:

@article{qin2023unicontrol, title={UniControl: A Unified Diffusion Model for Controllable Visual Generation In the Wild}, author={Qin, Can and Zhang, Shu and Yu, Ning and Feng, Yihao and Yang, Xinyi and Zhou, Yingbo and Wang, Huan and Niebles, Juan Carlos and Xiong, Caiming and Savarese, Silvio and others}, journal={arXiv preprint arXiv:2305.11147}, year={2023} }

致谢

本项目基于ControlNet和Stable Diffusion的巨大贡献。非常感谢他们!

Stable Diffusion https://github.com/CompVis/stable-diffusion

ControlNet https://github.com/lllyasviel/ControlNet

StyleGAN3 https://github.com/NVlabs/stylegan3

编辑推荐精选

Vora

Vora

免费创建高清无水印Sora视频

Vora是一个免费创建高清无水印Sora视频的AI工具

Refly.AI

Refly.AI

最适合小白的AI自动化工作流平台

无需编码,轻松生成可复用、可变现的AI自动化工作流

酷表ChatExcel

酷表ChatExcel

大模型驱动的Excel数据处理工具

基于大模型交互的表格处理系统,允许用户通过对话方式完成数据整理和可视化分析。系统采用机器学习算法解析用户指令,自动执行排序、公式计算和数据透视等操作,支持多种文件格式导入导出。数据处理响应速度保持在0.8秒以内,支持超过100万行数据的即时分析。

AI工具酷表ChatExcelAI智能客服AI营销产品使用教程
TRAE编程

TRAE编程

AI辅助编程,代码自动修复

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
AIWritePaper论文写作

AIWritePaper论文写作

AI论文写作指导平台

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

AI辅助写作AI工具AI论文工具论文写作智能生成大纲数据安全AI助手热门
博思AIPPT

博思AIPPT

AI一键生成PPT,就用博思AIPPT!

博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。

AI办公办公工具AI工具博思AIPPTAI生成PPT智能排版海量精品模板AI创作热门
潮际好麦

潮际好麦

AI赋能电商视觉革命,一站式智能商拍平台

潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。

iTerms

iTerms

企业专属的AI法律顾问

iTerms是法大大集团旗下法律子品牌,基于最先进的大语言模型(LLM)、专业的法律知识库和强大的智能体架构,帮助企业扫清合规障碍,筑牢风控防线,成为您企业专属的AI法律顾问。

SimilarWeb流量提升

SimilarWeb流量提升

稳定高效的流量提升解决方案,助力品牌曝光

稳定高效的流量提升解决方案,助力品牌曝光

Sora2视频免费生成

Sora2视频免费生成

最新版Sora2模型免费使用,一键生成无水印视频

最新版Sora2模型免费使用,一键生成无水印视频

下拉加载更多