diffusers
v0.31.0
?擴散器是用於生成圖像,音頻甚至分子3D結構的最先進的擴散模型的首選庫。無論您是尋找簡單的推理解決方案還是培訓自己的擴散模型,?擴散器是一個支持兩者的模塊化工具箱。我們的圖書館的設計側重於性能,簡單的簡單性和對抽象的可定制性。
?擴散器提供了三個核心組成部分:
我們建議安裝嗎?來自PYPI或CONDA的虛擬環境中的擴散器。有關安裝Pytorch和亞麻的更多詳細信息,請參考其官方文件。
使用pip
(官方包):
pip install --upgrade diffusers[torch]
與conda
(由社區維護):
conda install -c conda-forge diffusers
使用pip
(官方包):
pip install --upgrade diffusers[flax]
請參閱如何在Apple Silicon指南中使用穩定擴散的方法。
生成輸出非常容易?擴散器。要從文本中生成圖像,請使用從from_pretrained
方法加載任何預驗證的擴散模型(瀏覽中心以獲取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
查看即可今天啟動您的擴散之旅的快速啟動!
文件 | 我能學到什麼? |
---|---|
教程 | 一個基本的速成課程,用於學習如何使用圖書館最重要的功能,例如使用模型和調度程序來構建自己的擴散系統,並訓練自己的擴散模型。 |
載入中 | 指南如何加載和配置庫的所有組件(管道,模型和調度程序),以及如何使用不同的調度程序。 |
推理的管道 | 指南如何將管道用於不同的推理任務,批處理生成,控制生成的輸出和隨機性以及如何向庫貢獻管道。 |
最佳化 | 指南如何優化擴散模型以更快地運行並消耗更少的內存。 |
訓練 | 指南如何通過不同的訓練技術訓練不同任務的擴散模型。 |
我們來自開源社區的貢獻!如果您想為此圖書館做出貢獻,請查看我們的貢獻指南。您可以注意要解決的問題為圖書館做出貢獻。
另外,在我們的公共不和諧頻道中說。我們討論有關擴散模型的最熱門趨勢,互相幫助,貢獻,個人項目或只是閒逛。
任務 | 管道 | ?中心 |
---|---|---|
無條件的圖像生成 | DDPM | Google/ddpm-ema-church-256 |
文本對圖像 | 穩定的擴散文本對圖像 | 穩定 - 擴散-V1-5/穩定 - 擴散-V1-5 |
文本對圖像 | 拆平 | kakaobrain/karlo-v1-alpha |
文本對圖像 | deepfloyd if | deepfloyd/if-i-xl-v1.0 |
文本對圖像 | 康丁斯基 | Kandinsky-Community/Kandinsky-2-2二十碼 |
文本指導的圖像到圖像 | 控製網 | llyasviel/sd-controlnet-canny |
文本指導的圖像到圖像 | consendpix2pix | timbrooks/consend-pix2pix |
文本指導的圖像到圖像 | 穩定的擴散圖像到圖像 | 穩定 - 擴散-V1-5/穩定 - 擴散-V1-5 |
文本指導的圖像介紹 | 穩定的擴散介紹 | 跑道/穩定擴散侵蝕 |
圖像變化 | 穩定的擴散圖像變化 | lambdalabs/sd-image-riatiations-diffuser |
超級分辨率 | 穩定的擴散高檔 | 穩定/穩定擴散-X4-Upscaler |
超級分辨率 | 穩定的擴散潛在高檔 | 穩定性/SD-X2 LATENT-UPSCALER |
謝謝您使用我們❤️。
該圖書館旨在將許多不同作者的先前工作構成,如果沒有出色的研究和實施,就不可能。我們要特別感謝以下對我們開發的實現,並且沒有此事,API今天就不可能得到那麼好處:
我們還要感謝@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} }
}