🚀 SD3 Controlnet Inpainting模型
本模型是基於文本生成圖像的模型,它已被集成到Diffusers庫中,能方便地使用。它在圖像修復等方面有著出色的表現,能有效保留非修復區域的完整性,還能通過修復生成文本,在人像生成上有較好的美學效果。
🚀 快速開始
本模型已集成至 Diffusers,可便捷使用。
✨ 主要特性
圖像示例

一位穿著白色夾克、黑色帽子和黑色褲子的女士站在田野裡,帽子上寫著SD3

一個穿著白色鞋子的人,提著一個寫有“alibaba”字樣的白色水桶
SD3 Controlnet圖像修復
基於sd3 - medium微調的Controlnet圖像修復模型,該圖像修復模型具有以下優勢:
- 利用SD3的16通道VAE和1024的高分辨率生成能力,模型能有效保留非修復區域的完整性,包括文本。
- 能夠通過圖像修復生成文本。
- 在人像生成方面表現出更優的美學性能。
與 SDXL - Inpainting 相比:
從左到右依次為:輸入圖像、遮罩圖像、SDXL圖像修復結果、本模型結果。

一隻老虎坐在公園長椅上

一隻狗坐在公園長椅上

一位年輕女士穿著藍粉相間的碎花連衣裙

一位穿著白色夾克、黑色帽子和黑色褲子的女士站在田野裡,帽子上寫著SD3

一臺空調掛在臥室牆上
📦 安裝指南
從源代碼安裝並運行:
pip uninstall diffusers
pip install git+https://github.com/huggingface/diffusers
💻 使用示例
基礎用法
import torch
from diffusers.utils import load_image, check_min_version
from diffusers.pipelines import StableDiffusion3ControlNetInpaintingPipeline
from diffusers.models.controlnet_sd3 import SD3ControlNetModel
controlnet = SD3ControlNetModel.from_pretrained(
"alimama-creative/SD3-Controlnet-Inpainting", use_safetensors=True, extra_conditioning_channels=1
)
pipe = StableDiffusion3ControlNetInpaintingPipeline.from_pretrained(
"stabilityai/stable-diffusion-3-medium-diffusers",
controlnet=controlnet,
torch_dtype=torch.float16,
)
pipe.text_encoder.to(torch.float16)
pipe.controlnet.to(torch.float16)
pipe.to("cuda")
image = load_image(
"https://huggingface.co/alimama-creative/SD3-Controlnet-Inpainting/resolve/main/images/dog.png"
)
mask = load_image(
"https://huggingface.co/alimama-creative/SD3-Controlnet-Inpainting/resolve/main/images/dog_mask.png"
)
width = 1024
height = 1024
prompt = "A cat is sitting next to a puppy."
generator = torch.Generator(device="cuda").manual_seed(24)
res_image = pipe(
negative_prompt="deformed, distorted, disfigured, poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, mutated hands and fingers, disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, NSFW",
prompt=prompt,
height=height,
width=width,
control_image=image,
control_mask=mask,
num_inference_steps=28,
generator=generator,
controlnet_conditioning_scale=0.95,
guidance_scale=7,
).images[0]
res_image.save(f"sd3.png")
🔧 技術細節
訓練細節
- 模型在1200萬的laion2B和內部源圖像上進行了20000步的訓練,分辨率為1024x1024。
- 混合精度:FP16
- 學習率:1e - 4
- 批量大小:192
- 時間步採樣模式:'logit_normal'
- 損失函數:Flow Matching
侷限性
由於訓練階段僅使用了1024 * 1024像素的分辨率,推理在該尺寸下表現最佳,其他尺寸的效果欠佳。未來將開展多分辨率訓練,並開源新的權重。
📄 許可證
該模型基於SD3微調,因此許可證遵循原始的 SD3許可證。