🚀 Controlnet - v1.1 - instruct pix2pix 版本
Controlnet v1.1 是一種神經網絡結構,可通過添加額外條件來控制擴散模型。本項目基於 Stable Diffusion,能實現強大的圖像生成功能,為圖像創作帶來更多可能。
🚀 快速開始
本檢查點可與 Stable Diffusion 結合使用,例如 runwayml/stable-diffusion-v1-5。
安裝依賴
$ pip install diffusers transformers accelerate
運行代碼示例
import torch
import os
from huggingface_hub import HfApi
from pathlib import Path
from diffusers.utils import load_image
from PIL import Image
import numpy as np
from diffusers import (
ControlNetModel,
StableDiffusionControlNetPipeline,
UniPCMultistepScheduler,
)
checkpoint = "lllyasviel/control_v11e_sd15_ip2p"
image = load_image("https://huggingface.co/lllyasviel/control_v11e_sd15_ip2p/resolve/main/images/input.png").convert('RGB')
prompt = "make it on fire"
controlnet = ControlNetModel.from_pretrained(checkpoint, torch_dtype=torch.float16)
pipe = StableDiffusionControlNetPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5", controlnet=controlnet, torch_dtype=torch.float16
)
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
pipe.enable_model_cpu_offload()
generator = torch.manual_seed(0)
image = pipe(prompt, num_inference_steps=30, generator=generator, image=image).images[0]
image.save('images/image_out.png')


✨ 主要特性
- 條件控制:ControlNet 是一種神經網絡結構,可通過添加額外條件來控制擴散模型。
- 多場景適配:可與 Stable Diffusion 等模型結合使用,適用於多種圖像生成場景。
- 多種檢查點:作者發佈了 14 種不同的檢查點,每種都針對不同類型的條件進行了訓練。
📦 安裝指南
安裝 diffusers
及相關依賴包:
$ pip install diffusers transformers accelerate
💻 使用示例
基礎用法
import torch
import os
from huggingface_hub import HfApi
from pathlib import Path
from diffusers.utils import load_image
from PIL import Image
import numpy as np
from diffusers import (
ControlNetModel,
StableDiffusionControlNetPipeline,
UniPCMultistepScheduler,
)
checkpoint = "lllyasviel/control_v11e_sd15_ip2p"
image = load_image("https://huggingface.co/lllyasviel/control_v11e_sd15_ip2p/resolve/main/images/input.png").convert('RGB')
prompt = "make it on fire"
controlnet = ControlNetModel.from_pretrained(checkpoint, torch_dtype=torch.float16)
pipe = StableDiffusionControlNetPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5", controlnet=controlnet, torch_dtype=torch.float16
)
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
pipe.enable_model_cpu_offload()
generator = torch.manual_seed(0)
image = pipe(prompt, num_inference_steps=30, generator=generator, image=image).images[0]
image.save('images/image_out.png')
📚 詳細文檔
模型詳情
模型介紹
Controlnet 由 Lvmin Zhang 和 Maneesh Agrawala 在 Adding Conditional Control to Text-to-Image Diffusion Models 中提出。
論文摘要如下:
我們提出了一種神經網絡結構 ControlNet,用於控制預訓練的大型擴散模型,以支持額外的輸入條件。ControlNet 以端到端的方式學習特定任務的條件,即使訓練數據集較小(< 50k),學習過程也很穩健。此外,訓練 ControlNet 的速度與微調擴散模型的速度一樣快,並且可以在個人設備上進行訓練。或者,如果有強大的計算集群可用,模型可以擴展到大量(數百萬到數十億)的數據。我們報告稱,像 Stable Diffusion 這樣的大型擴散模型可以通過 ControlNets 進行增強,以支持邊緣圖、分割圖、關鍵點等條件輸入。這可能會豐富控制大型擴散模型的方法,並進一步促進相關應用的發展。
其他發佈的 v1-1 檢查點
作者發佈了 14 種不同的檢查點,每種都在 Stable Diffusion v1-5 上針對不同類型的條件進行了訓練:
更多信息
如需更多信息,請查看 Diffusers ControlNet 博客文章 和 官方文檔。
📄 許可證
本項目採用 CreativeML OpenRAIL M 許可證。