2023-08-30 07:28:31 +02:00
|
|
|
import os
|
|
|
|
|
2024-01-05 08:19:23 +01:00
|
|
|
from iopaint.tests.utils import current_dir, check_device
|
2023-12-28 03:48:52 +01:00
|
|
|
|
2023-08-30 07:28:31 +02:00
|
|
|
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
import torch
|
|
|
|
|
2024-01-05 08:19:23 +01:00
|
|
|
from iopaint.model_manager import ModelManager
|
|
|
|
from iopaint.schema import HDStrategy, SDSampler
|
|
|
|
from iopaint.tests.test_model import get_config, assert_equal
|
2023-08-30 07:28:31 +02:00
|
|
|
|
|
|
|
|
2023-12-19 06:16:30 +01:00
|
|
|
@pytest.mark.parametrize("name", ["runwayml/stable-diffusion-inpainting"])
|
2023-12-28 03:48:52 +01:00
|
|
|
@pytest.mark.parametrize("device", ["cuda", "mps", "cpu"])
|
2023-08-30 07:28:31 +02:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"rect",
|
|
|
|
[
|
|
|
|
[0, -100, 512, 512 - 128 + 100],
|
|
|
|
[0, 128, 512, 512 - 128 + 100],
|
|
|
|
[128, 0, 512 - 128 + 100, 512],
|
|
|
|
[-100, 0, 512 - 128 + 100, 512],
|
|
|
|
[0, 0, 512, 512 + 200],
|
|
|
|
[0, 0, 512 + 200, 512],
|
|
|
|
[-100, -100, 512 + 200, 512 + 200],
|
|
|
|
],
|
|
|
|
)
|
2023-12-28 03:48:52 +01:00
|
|
|
def test_outpainting(name, device, rect):
|
|
|
|
sd_steps = check_device(device)
|
|
|
|
|
2023-08-30 07:28:31 +02:00
|
|
|
model = ModelManager(
|
2023-08-30 15:30:11 +02:00
|
|
|
name=name,
|
2023-12-28 03:48:52 +01:00
|
|
|
device=torch.device(device),
|
2023-08-30 07:28:31 +02:00
|
|
|
disable_nsfw=True,
|
|
|
|
sd_cpu_textencoder=False,
|
|
|
|
)
|
|
|
|
cfg = get_config(
|
|
|
|
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_guidance_scale=8.0,
|
2024-01-02 07:34:36 +01:00
|
|
|
sd_sampler=SDSampler.dpm_plus_plus_2m,
|
2023-08-30 07:28:31 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal(
|
|
|
|
model,
|
|
|
|
cfg,
|
2023-12-28 03:48:52 +01:00
|
|
|
f"{name.replace('/', '--')}_outpainting_{'_'.join(map(str, rect))}_device_{device}.png",
|
2023-08-30 07:28:31 +02:00
|
|
|
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
|
|
|
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
|
|
|
)
|
2023-08-30 15:30:11 +02:00
|
|
|
|
|
|
|
|
2023-12-19 06:16:30 +01:00
|
|
|
@pytest.mark.parametrize("name", ["kandinsky-community/kandinsky-2-2-decoder-inpaint"])
|
2023-12-28 03:48:52 +01:00
|
|
|
@pytest.mark.parametrize("device", ["cuda", "mps", "cpu"])
|
2023-08-30 15:30:11 +02:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"rect",
|
|
|
|
[
|
2023-11-14 07:19:56 +01:00
|
|
|
[-128, -128, 768, 768],
|
2023-08-30 15:30:11 +02:00
|
|
|
],
|
|
|
|
)
|
2023-12-28 03:48:52 +01:00
|
|
|
def test_kandinsky_outpainting(name, device, rect):
|
|
|
|
sd_steps = check_device(device)
|
|
|
|
|
2023-08-30 15:30:11 +02:00
|
|
|
model = ModelManager(
|
2023-12-19 06:16:30 +01:00
|
|
|
name=name,
|
2023-12-28 03:48:52 +01:00
|
|
|
device=torch.device(device),
|
2023-08-30 15:30:11 +02:00
|
|
|
disable_nsfw=True,
|
|
|
|
sd_cpu_textencoder=False,
|
|
|
|
)
|
|
|
|
cfg = get_config(
|
|
|
|
prompt="a cat",
|
|
|
|
negative_prompt="lowres, text, error, cropped, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, out of frame, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck, username, watermark, signature",
|
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_guidance_scale=7,
|
2024-01-02 07:34:36 +01:00
|
|
|
sd_sampler=SDSampler.dpm_plus_plus_2m,
|
2023-08-30 15:30:11 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal(
|
|
|
|
model,
|
|
|
|
cfg,
|
2023-12-28 03:48:52 +01:00
|
|
|
f"{name.replace('/', '--')}_outpainting_{'_'.join(map(str, rect))}_device_{device}.png",
|
2023-08-30 15:30:11 +02:00
|
|
|
img_p=current_dir / "cat.png",
|
|
|
|
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
2023-11-14 07:19:56 +01:00
|
|
|
fx=1,
|
|
|
|
fy=1,
|
2023-08-30 15:30:11 +02:00
|
|
|
)
|
2023-12-28 03:48:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("name", ["Sanster/PowerPaint-V1-stable-diffusion-inpainting"])
|
|
|
|
@pytest.mark.parametrize("device", ["cuda", "mps", "cpu"])
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"rect",
|
|
|
|
[
|
|
|
|
[-100, -100, 512 + 200, 512 + 200],
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_powerpaint_outpainting(name, device, rect):
|
|
|
|
sd_steps = check_device(device)
|
|
|
|
|
|
|
|
model = ModelManager(
|
|
|
|
name=name,
|
|
|
|
device=torch.device(device),
|
|
|
|
disable_nsfw=True,
|
|
|
|
sd_cpu_textencoder=False,
|
|
|
|
)
|
|
|
|
cfg = get_config(
|
|
|
|
prompt="a dog sitting on a bench in the park",
|
|
|
|
sd_steps=sd_steps,
|
|
|
|
use_extender=True,
|
|
|
|
extender_x=rect[0],
|
|
|
|
extender_y=rect[1],
|
|
|
|
extender_width=rect[2],
|
|
|
|
extender_height=rect[3],
|
|
|
|
sd_guidance_scale=8.0,
|
2024-01-02 07:34:36 +01:00
|
|
|
sd_sampler=SDSampler.dpm_plus_plus_2m,
|
2023-12-28 03:48:52 +01:00
|
|
|
powerpaint_task="outpainting",
|
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal(
|
|
|
|
model,
|
|
|
|
cfg,
|
|
|
|
f"{name.replace('/', '--')}_outpainting_{'_'.join(map(str, rect))}_device_{device}.png",
|
|
|
|
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
|
|
|
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
|
|
|
)
|