2023-01-28 14:45:21 +01:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
import torch
|
|
|
|
|
|
|
|
from lama_cleaner.model_manager import ModelManager
|
|
|
|
from lama_cleaner.schema import HDStrategy
|
2023-12-28 03:48:52 +01:00
|
|
|
from lama_cleaner.tests.utils import get_config, check_device, assert_equal, current_dir
|
2023-01-28 14:45:21 +01:00
|
|
|
|
2023-12-19 06:16:30 +01:00
|
|
|
model_name = "timbrooks/instruct-pix2pix"
|
2023-01-28 14:45:21 +01:00
|
|
|
|
|
|
|
|
2023-12-28 03:48:52 +01:00
|
|
|
@pytest.mark.parametrize("device", ["cuda", "mps", "cpu"])
|
2023-01-28 14:45:21 +01:00
|
|
|
@pytest.mark.parametrize("disable_nsfw", [True, False])
|
|
|
|
@pytest.mark.parametrize("cpu_offload", [False, True])
|
2023-12-28 03:48:52 +01:00
|
|
|
def test_instruct_pix2pix(device, disable_nsfw, cpu_offload):
|
|
|
|
sd_steps = check_device(device)
|
2023-12-19 06:16:30 +01:00
|
|
|
model = ModelManager(
|
|
|
|
name=model_name,
|
|
|
|
device=torch.device(device),
|
|
|
|
disable_nsfw=disable_nsfw,
|
|
|
|
sd_cpu_textencoder=False,
|
|
|
|
cpu_offload=cpu_offload,
|
|
|
|
)
|
|
|
|
cfg = get_config(
|
|
|
|
strategy=HDStrategy.ORIGINAL,
|
|
|
|
prompt="What if it were snowing?",
|
|
|
|
p2p_steps=sd_steps,
|
|
|
|
sd_scale=1.1,
|
|
|
|
)
|
2023-01-28 14:45:21 +01:00
|
|
|
|
|
|
|
name = f"device_{device}_disnsfw_{disable_nsfw}_cpu_offload_{cpu_offload}"
|
|
|
|
|
|
|
|
assert_equal(
|
|
|
|
model,
|
|
|
|
cfg,
|
|
|
|
f"instruct_pix2pix_{name}.png",
|
|
|
|
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
|
|
|
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
2023-12-19 06:16:30 +01:00
|
|
|
fx=1.3,
|
2023-01-28 14:45:21 +01:00
|
|
|
)
|