🚀 EcomXL Inpaint ControlNet
EcomXLは、Stable Diffusion XLをベースに開発された、電子商取引シナリオ向けに最適化された一連のテキストから画像への拡散モデルを含んでいます。電子商取引シナリオに対応するため、拡散モデルを制御するInpaint ControlNetをトレーニングしました。一般的なシナリオで使用されるインペインコントロールネットとは異なり、このモデルは前景のアウトペイントを防ぐためにインスタンスマスクで微調整されています。
✨ 主な機能
- 電子商取引シナリオ向けに最適化されたテキストから画像への拡散モデルを提供します。
- Inpaint ControlNetを使用して拡散モデルを制御し、前景のアウトペイントを防ぎます。
💻 使用例
基本的な使用法
from diffusers import (
ControlNetModel,
StableDiffusionXLControlNetPipeline,
DDPMScheduler
)
from diffusers.utils import load_image
import torch
from PIL import Image
import numpy as np
def make_inpaint_condition(init_image, mask_image):
init_image = np.array(init_image.convert("RGB")).astype(np.float32) / 255.0
mask_image = np.array(mask_image.convert("L")).astype(np.float32) / 255.0
assert init_image.shape[0:1] == mask_image.shape[0:1], "image and image_mask must have the same image size"
init_image[mask_image > 0.5] = -1.0
init_image = np.expand_dims(init_image, 0).transpose(0, 3, 1, 2)
init_image = torch.from_numpy(init_image)
return init_image
def add_fg(full_img, fg_img, mask_img):
full_img = np.array(full_img).astype(np.float32)
fg_img = np.array(fg_img).astype(np.float32)
mask_img = np.array(mask_img).astype(np.float32) / 255.
full_img = full_img * mask_img + fg_img * (1-mask_img)
return Image.fromarray(np.clip(full_img, 0, 255).astype(np.uint8))
controlnet = ControlNetModel.from_pretrained(
"alimama-creative/EcomXL_controlnet_inpaint",
use_safetensors=True,
)
pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
controlnet=controlnet,
)
pipe.to("cuda")
pipe.scheduler = DDPMScheduler.from_config(pipe.scheduler.config)
image = load_image(
"https://huggingface.co/alimama-creative/EcomXL_controlnet_inpaint/resolve/main/images/inp_0.png"
)
mask = load_image(
"https://huggingface.co/alimama-creative/EcomXL_controlnet_inpaint/resolve/main/images/inp_1.png"
)
mask = Image.fromarray(255 - np.array(mask))
control_image = make_inpaint_condition(image, mask)
prompt="a product on the table"
generator = torch.Generator(device="cuda").manual_seed(1234)
res_image = pipe(
prompt,
image=control_image,
num_inference_steps=25,
guidance_scale=7,
width=1024,
height=1024,
controlnet_conditioning_scale=0.5,
generator=generator,
).images[0]
res_image = add_fg(res_image, image, mask)
res_image.save(f'res.png')
このモデルは、ControlNetの重み(controlnet_condition_scale)が0.5のときに良好な性能を示します。
🔧 技術詳細
トレーニングの詳細
- 第1フェーズでは、モデルは12Mのlaion2Bと内部ソース画像をランダムマスクで20kステップトレーニングされました。
- 第2フェーズでは、モデルは3Mの電子商取引画像をインスタンスマスクで20kステップトレーニングされました。
トレーニングパラメータ
属性 |
详情 |
混合精度 |
FP16 |
学習率 |
1e-4 |
バッチサイズ |
2048 |
ノイズオフセット |
0.05 |
📄 ライセンス
このモデルはApache-2.0ライセンスの下で提供されています。