https://github.com/Disty0/diffusers.git
| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 7 个月前 | ||
| 11 个月前 | ||
| 8 个月前 | ||
| 6 个月前 | ||
| 7 个月前 | ||
| 7 个月前 | ||
| 5 个月前 | ||
| 6 个月前 | ||
| 7 个月前 | ||
| 8 个月前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 1 年前 | ||
| 4 年前 | ||
| 3 年前 | ||
| 2 年前 | ||
| 1 年前 | ||
| 8 个月前 | ||
| 3 年前 | ||
| 7 个月前 | ||
| 8 个月前 |
🤗 Diffusers 是用于生成图像、音频乃至分子 3D 结构的最先进预训练扩散模型的首选库。无论您是在寻找简单的推理解决方案,还是训练自己的扩散模型,🤗 Diffusers 都是一个支持这两种功能的模块化工具箱。我们的库在设计时注重可用性优先于性能、简洁优先于便捷以及可定制性优先于抽象。
🤗 Diffusers 提供三个核心组件:
安装
我们建议在虚拟环境中通过 PyPI 或 Conda 安装 🤗 Diffusers。有关安装 PyTorch 的更多详细信息,请参考其官方文档。
PyTorch
使用 pip(官方包):
pip install --upgrade diffusers[torch]
使用 conda(由社区维护):
conda install -c conda-forge diffusers
Apple Silicon(M1/M2)支持
请参考如何在 Apple Silicon 中使用 Stable Diffusion指南。
快速入门
使用 🤗 Diffusers 生成输出非常简单。要从文本生成图像,请使用 from_pretrained 方法加载任何预训练的扩散模型(可在Hub中浏览 30,000 多个检查点):
from diffusers import DiffusionPipeline
import torch
pipeline = DiffusionPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", torch_dtype=torch.float16)
pipeline.to("cuda")
pipeline("An image of a squirrel in Picasso style").images[0]
你也可以深入研究模型和调度器工具库,构建自己的扩散系统:
from diffusers import DDPMScheduler, UNet2DModel
from PIL import Image
import torch
scheduler = DDPMScheduler.from_pretrained("google/ddpm-cat-256")
model = UNet2DModel.from_pretrained("google/ddpm-cat-256").to("cuda")
scheduler.set_timesteps(50)
sample_size = model.config.sample_size
noise = torch.randn((1, 3, sample_size, sample_size), device="cuda")
input = noise
for t in scheduler.timesteps:
with torch.no_grad():
noisy_residual = model(input, t).sample
prev_noisy_sample = scheduler.step(noisy_residual, t, input).prev_sample
input = prev_noisy_sample
image = (input / 2 + 0.5).clamp(0, 1)
image = image.cpu().permute(0, 2, 3, 1).numpy()[0]
image = Image.fromarray((image * 255).round().astype("uint8"))
image
查看 快速入门,立即开启您的扩散模型之旅!
如何浏览文档
| 文档 | 可以学到什么? |
|---|---|
| 教程 | 一门基础速成课程,旨在学习如何使用该库的最重要功能,例如使用模型和调度器构建您自己的扩散系统,以及训练您自己的扩散模型。 |
| 加载 | 有关如何加载和配置库的所有组件(流水线、模型和调度器)以及如何使用不同调度器的指南。 |
| 推理流水线 | 有关如何将流水线用于不同推理任务、批量生成、控制生成输出和随机性,以及如何向库贡献流水线的指南。 |
| 优化 | 有关如何优化您的扩散模型以实现更快运行和更低内存消耗的指南。 |
| 训练 | 有关如何使用不同训练技术针对不同任务训练扩散模型的指南。 |
贡献
我们非常欢迎开源社区的贡献! 如果您想为这个库贡献力量,请查阅我们的贡献指南。 您可以关注issues,选择您想要解决的问题来为库做出贡献。
- 查看Good first issues以获取入门级的贡献机会
- 查看New model/pipeline来贡献令人兴奋的新扩散模型/扩散流水线
- 查看New scheduler
另外,欢迎在我们的公共Discord频道打个招呼 。我们在这里讨论扩散模型的最新趋势,互相帮助解决贡献、个人项目方面的问题,或者只是轻松地聊聊天 ☕。
热门任务与流水线
使用 🧨 Diffusers 的热门库
- https://github.com/microsoft/TaskMatrix
- https://github.com/invoke-ai/InvokeAI
- https://github.com/InstantID/InstantID
- https://github.com/apple/ml-stable-diffusion
- https://github.com/Sanster/lama-cleaner
- https://github.com/IDEA-Research/Grounded-Segment-Anything
- https://github.com/ashawkey/stable-dreamfusion
- https://github.com/deep-floyd/IF
- https://github.com/bentoml/BentoML
- https://github.com/bmaltais/kohya_ss
- 以及其他超过 14,000 个优秀的 GitHub 仓库 💪
感谢您的使用 ❤️。
致谢
本库整合了众多不同作者先前的研究成果,若无他们卓越的研究和实现,本库的开发将无法实现。我们特别感谢以下实现,它们在我们的开发过程中提供了帮助,正是有了这些实现,如今的 API 才能如此完善:
- @CompVis 的潜在扩散模型库,可在 此处 获取
- @hojonathanho 的原始 DDPM 实现,可在 此处 获取,以及 @pesser 将其出色地移植到 PyTorch 的版本,可在 此处 获取
- @ermongroup 的 DDIM 实现,可在 此处 获取
- @yang-song 的 Score-VE 和 Score-VP 实现,可在 此处 获取
我们还要感谢 @heejkoo 提供的关于扩散模型论文、代码和资源的非常有帮助的概述,可在 此处 获取,以及 @crowsonkb 和 @rromb 提供的有益讨论和见解。
引用
@misc{von-platen-etal-2022-diffusers,
author = {Patrick von Platen and Suraj Patil and Anton Lozhkov and Pedro Cuenca and Nathan Lambert and Kashif Rasul and Mishig Davaadorj and Dhruv Nair and Sayak Paul and William Berman and Yiyi Xu and Steven Liu and Thomas Wolf},
title = {Diffusers: State-of-the-art diffusion models},
year = {2022},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/huggingface/diffusers}}
}