🚀 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许可证。