2023-11-14 07:19:56 +01:00
|
|
|
import os
|
|
|
|
|
2023-12-28 03:48:52 +01:00
|
|
|
from lama_cleaner.tests.utils import check_device, current_dir
|
|
|
|
|
2023-11-14 07:19:56 +01:00
|
|
|
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
import torch
|
|
|
|
|
|
|
|
from lama_cleaner.model_manager import ModelManager
|
2023-12-19 06:16:30 +01:00
|
|
|
from lama_cleaner.schema import HDStrategy, SDSampler, FREEUConfig
|
2023-11-14 07:19:56 +01:00
|
|
|
from lama_cleaner.tests.test_model import get_config, assert_equal
|
|
|
|
|
|
|
|
|
2023-12-28 03:48:52 +01:00
|
|
|
@pytest.mark.parametrize("device", ["cuda", "mps"])
|
2023-11-14 07:19:56 +01:00
|
|
|
@pytest.mark.parametrize("strategy", [HDStrategy.ORIGINAL])
|
|
|
|
@pytest.mark.parametrize("sampler", [SDSampler.ddim])
|
2023-12-28 03:48:52 +01:00
|
|
|
def test_sdxl(device, strategy, sampler):
|
|
|
|
sd_steps = check_device(device)
|
|
|
|
|
2023-11-14 07:19:56 +01:00
|
|
|
model = ModelManager(
|
2023-12-19 06:16:30 +01:00
|
|
|
name="diffusers/stable-diffusion-xl-1.0-inpainting-0.1",
|
2023-12-28 03:48:52 +01:00
|
|
|
device=torch.device(device),
|
2023-12-19 06:16:30 +01:00
|
|
|
disable_nsfw=True,
|
|
|
|
sd_cpu_textencoder=False,
|
2023-11-14 07:19:56 +01:00
|
|
|
)
|
|
|
|
cfg = get_config(
|
2023-12-28 03:48:52 +01:00
|
|
|
strategy=strategy,
|
2023-12-19 06:16:30 +01:00
|
|
|
prompt="face of a fox, sitting on a bench",
|
2023-11-14 07:19:56 +01:00
|
|
|
sd_steps=sd_steps,
|
2023-12-19 06:16:30 +01:00
|
|
|
sd_strength=1.0,
|
2023-11-14 07:19:56 +01:00
|
|
|
sd_guidance_scale=7.0,
|
|
|
|
)
|
|
|
|
cfg.sd_sampler = sampler
|
|
|
|
|
|
|
|
assert_equal(
|
|
|
|
model,
|
|
|
|
cfg,
|
2023-12-28 03:48:52 +01:00
|
|
|
f"sdxl_device_{device}.png",
|
2023-11-14 07:19:56 +01:00
|
|
|
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
|
|
|
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
|
|
|
fx=2,
|
|
|
|
fy=2,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-12-28 03:48:52 +01:00
|
|
|
@pytest.mark.parametrize("device", ["cuda", "mps"])
|
2023-12-19 06:16:30 +01:00
|
|
|
@pytest.mark.parametrize("strategy", [HDStrategy.ORIGINAL])
|
|
|
|
@pytest.mark.parametrize("sampler", [SDSampler.ddim])
|
2023-12-28 03:48:52 +01:00
|
|
|
def test_sdxl_lcm_lora_and_freeu(device, strategy, sampler):
|
|
|
|
sd_steps = check_device(device)
|
|
|
|
|
2023-12-19 06:16:30 +01:00
|
|
|
model = ModelManager(
|
|
|
|
name="diffusers/stable-diffusion-xl-1.0-inpainting-0.1",
|
2023-12-28 03:48:52 +01:00
|
|
|
device=torch.device(device),
|
2023-12-19 06:16:30 +01:00
|
|
|
disable_nsfw=True,
|
|
|
|
sd_cpu_textencoder=False,
|
|
|
|
)
|
|
|
|
cfg = get_config(
|
2023-12-28 03:48:52 +01:00
|
|
|
strategy=strategy,
|
2023-12-19 06:16:30 +01:00
|
|
|
prompt="face of a fox, sitting on a bench",
|
|
|
|
sd_steps=sd_steps,
|
|
|
|
sd_strength=1.0,
|
|
|
|
sd_guidance_scale=2.0,
|
|
|
|
sd_lcm_lora=True,
|
|
|
|
)
|
|
|
|
cfg.sd_sampler = sampler
|
|
|
|
|
2023-12-28 03:48:52 +01:00
|
|
|
name = f"device_{device}_{sampler}"
|
2023-12-19 06:16:30 +01:00
|
|
|
|
|
|
|
assert_equal(
|
|
|
|
model,
|
|
|
|
cfg,
|
|
|
|
f"sdxl_{name}_lcm_lora.png",
|
|
|
|
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
|
|
|
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
|
|
|
fx=2,
|
|
|
|
fy=2,
|
|
|
|
)
|
|
|
|
|
|
|
|
cfg = get_config(
|
2023-12-28 03:48:52 +01:00
|
|
|
strategy=strategy,
|
2023-12-19 06:16:30 +01:00
|
|
|
prompt="face of a fox, sitting on a bench",
|
|
|
|
sd_steps=sd_steps,
|
|
|
|
sd_guidance_scale=7.5,
|
|
|
|
sd_freeu=True,
|
|
|
|
sd_freeu_config=FREEUConfig(),
|
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal(
|
|
|
|
model,
|
|
|
|
cfg,
|
2023-12-28 03:48:52 +01:00
|
|
|
f"sdxl_{name}_freeu_device_{device}.png",
|
2023-12-19 06:16:30 +01:00
|
|
|
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
|
|
|
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
|
|
|
fx=2,
|
|
|
|
fy=2,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-12-28 03:48:52 +01:00
|
|
|
@pytest.mark.parametrize("device", ["cuda", "mps"])
|
2023-11-14 07:19:56 +01:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"rect",
|
|
|
|
[
|
|
|
|
[-128, -128, 1024, 1024],
|
|
|
|
],
|
|
|
|
)
|
2023-12-28 03:48:52 +01:00
|
|
|
def test_sdxl_outpainting(device, rect):
|
|
|
|
sd_steps = check_device(device)
|
2023-11-14 07:19:56 +01:00
|
|
|
|
|
|
|
model = ModelManager(
|
2023-12-19 06:16:30 +01:00
|
|
|
name="diffusers/stable-diffusion-xl-1.0-inpainting-0.1",
|
2023-12-28 03:48:52 +01:00
|
|
|
device=torch.device(device),
|
2023-11-14 07:19:56 +01:00
|
|
|
disable_nsfw=True,
|
|
|
|
sd_cpu_textencoder=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
cfg = get_config(
|
2023-12-28 03:48:52 +01:00
|
|
|
strategy=HDStrategy.ORIGINAL,
|
2023-11-14 07:19:56 +01:00
|
|
|
prompt="a dog sitting on a bench in the park",
|
2023-12-28 03:48:52 +01:00
|
|
|
sd_steps=sd_steps,
|
2023-12-19 06:16:30 +01:00
|
|
|
use_extender=True,
|
|
|
|
extender_x=rect[0],
|
|
|
|
extender_y=rect[1],
|
|
|
|
extender_width=rect[2],
|
|
|
|
extender_height=rect[3],
|
2023-11-14 07:19:56 +01:00
|
|
|
sd_strength=1.0,
|
|
|
|
sd_guidance_scale=8.0,
|
|
|
|
sd_sampler=SDSampler.ddim,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal(
|
|
|
|
model,
|
|
|
|
cfg,
|
2023-12-28 03:48:52 +01:00
|
|
|
f"sdxl_outpainting_dog_ddim_{'_'.join(map(str, rect))}_device_{device}.png",
|
2023-11-14 07:19:56 +01:00
|
|
|
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
|
|
|
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
|
|
|
fx=1.5,
|
|
|
|
fy=1.5,
|
|
|
|
)
|