PyTorch和JAX中最先进的扩散技术。
项目描述
🤗 Diffusers 是用于生成图像、音频甚至分子 3D 结构的顶尖预训练扩散模型的首选库。无论您是在寻找简单的推理解决方案还是训练自己的扩散模型,🤗 Diffusers 都是一个模块化工具箱,支持这两者。我们的库设计注重 实用性胜于性能、简单易用 以及 可定制性胜于抽象。
🤗 Diffusers 提供三个核心组件
安装
我们建议您从 PyPI 或 Conda 在虚拟环境中安装 🤗 Diffusers。有关安装 PyTorch 和 Flax 的更多详细信息,请参阅它们的官方文档。
PyTorch
使用 pip
(官方包)
pip install --upgrade diffusers[torch]
使用 conda
(由社区维护)
conda install -c conda-forge diffusers
Flax
使用 pip
(官方包)
pip install --upgrade diffusers[flax]
Apple Silicon(M1/M2)支持
请参阅如何在 Apple Silicon 上使用 Stable Diffusion 指南。
快速入门
使用 🤗 Diffusers 生成输出非常简单。要从文本生成图像,请使用 from_pretrained
方法加载任何预训练的扩散模型(浏览 Hub 中的 30,000+ 个检查点)
from diffusers import DiffusionPipeline
import torch
pipeline = DiffusionPipeline.from_pretrained("runwayml/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
查看 快速入门,今天开始您的扩散之旅!
如何导航文档
文档 | 我可以学到什么? |
---|---|
教程 | 这是一门基础速成课程,用于学习如何使用库的最重要功能,例如使用模型和调度器构建自己的扩散系统,以及训练自己的扩散模型。 |
加载 | 如何加载和配置库的所有组件(管道、模型和调度器)的指南,以及如何使用不同的调度器。 |
推理管道 | 如何使用管道执行不同推理任务的指南,批量生成、控制生成输出和随机性,以及如何向库贡献管道。 |
优化 | 如何优化您的扩散模型以运行更快并消耗更少内存的指南。 |
训练 | 如何使用不同的训练技术训练扩散模型以执行不同任务的指南。 |
贡献
我们热爱开源社区的贡献!如果您想为这个库做出贡献,请查看我们的 贡献指南。您可以查看 问题 以找到您想解决的问题。
此外,在我们公共Discord频道中打招呼 👋 。我们讨论有关扩散模型的最新趋势,互相帮助贡献、个人项目或只是闲逛 ☕。
热门任务 & 流水线
任务 | 流水线 | 🤗 中心 |
---|---|---|
无条件图像生成 | DDPM | google/ddpm-ema-church-256 |
文本到图像 | 稳定扩散文本到图像 | runwayml/stable-diffusion-v1-5 |
文本到图像 | unCLIP | kakaobrain/karlo-v1-alpha |
文本到图像 | DeepFloyd IF | DeepFloyd/IF-I-XL-v1.0 |
文本到图像 | Kandinsky | kandinsky-community/kandinsky-2-2-decoder |
文本引导的图像到图像 | ControlNet | lllyasviel/sd-controlnet-canny |
文本引导的图像到图像 | InstructPix2Pix | timbrooks/instruct-pix2pix |
文本引导的图像到图像 | 稳定扩散图像到图像 | runwayml/stable-diffusion-v1-5 |
文本引导的图像修复 | 稳定扩散修复 | runwayml/stable-diffusion-inpainting |
图像变化 | 稳定扩散图像变化 | lambdalabs/sd-image-variations-diffusers |
超分辨率 | 稳定扩散升级 | stabilityai/stable-diffusion-x4-upscaler |
超分辨率 | 稳定扩散潜在升级 | stabilityai/sd-x2-latent-upscaler |
使用 🧨 Diffusers 的热门库
- https://github.com/microsoft/TaskMatrix
- https://github.com/invoke-ai/InvokeAI
- 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}}
}
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。