update
This commit is contained in:
@@ -39,7 +39,6 @@ def test_runway_sd_1_5(
|
||||
sd_controlnet=True,
|
||||
device=torch.device(sd_device),
|
||||
hf_access_token="",
|
||||
sd_run_local=False,
|
||||
disable_nsfw=disable_nsfw,
|
||||
sd_cpu_textencoder=cpu_textencoder,
|
||||
sd_controlnet_method=sd_controlnet_method,
|
||||
@@ -88,11 +87,9 @@ def test_local_file_path(sd_device, sampler):
|
||||
sd_controlnet=True,
|
||||
device=torch.device(sd_device),
|
||||
hf_access_token="",
|
||||
sd_run_local=False,
|
||||
disable_nsfw=True,
|
||||
sd_cpu_textencoder=False,
|
||||
cpu_offload=True,
|
||||
sd_local_model_path="/Users/cwq/data/models/sd-v1-5-inpainting.ckpt",
|
||||
sd_controlnet_method="control_v11p_sd15_canny",
|
||||
)
|
||||
cfg = get_config(
|
||||
@@ -128,7 +125,6 @@ def test_local_file_path_controlnet_native_inpainting(sd_device, sampler):
|
||||
sd_controlnet=True,
|
||||
device=torch.device(sd_device),
|
||||
hf_access_token="",
|
||||
sd_run_local=False,
|
||||
disable_nsfw=True,
|
||||
sd_cpu_textencoder=False,
|
||||
cpu_offload=True,
|
||||
@@ -170,7 +166,6 @@ def test_controlnet_switch(sd_device, sampler):
|
||||
sd_controlnet=True,
|
||||
device=torch.device(sd_device),
|
||||
hf_access_token="",
|
||||
sd_run_local=False,
|
||||
disable_nsfw=True,
|
||||
sd_cpu_textencoder=False,
|
||||
cpu_offload=True,
|
||||
|
||||
@@ -8,23 +8,30 @@ from lama_cleaner.tests.test_model import get_config, assert_equal
|
||||
from lama_cleaner.schema import HDStrategy
|
||||
|
||||
current_dir = Path(__file__).parent.absolute().resolve()
|
||||
save_dir = current_dir / 'result'
|
||||
save_dir = current_dir / "result"
|
||||
save_dir.mkdir(exist_ok=True, parents=True)
|
||||
device = 'cuda' if torch.cuda.is_available() else 'mps'
|
||||
device = "cuda" if torch.cuda.is_available() else "mps"
|
||||
model_name = "timbrooks/instruct-pix2pix"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("disable_nsfw", [True, False])
|
||||
@pytest.mark.parametrize("cpu_offload", [False, True])
|
||||
def test_instruct_pix2pix(disable_nsfw, cpu_offload):
|
||||
sd_steps = 50 if device == 'cuda' else 20
|
||||
model = ModelManager(name="instruct_pix2pix",
|
||||
device=torch.device(device),
|
||||
hf_access_token="",
|
||||
sd_run_local=False,
|
||||
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)
|
||||
sd_steps = 50 if device == "cuda" else 20
|
||||
model = ModelManager(
|
||||
name=model_name,
|
||||
device=torch.device(device),
|
||||
hf_access_token="",
|
||||
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,
|
||||
)
|
||||
|
||||
name = f"device_{device}_disnsfw_{disable_nsfw}_cpu_offload_{cpu_offload}"
|
||||
|
||||
@@ -34,22 +41,27 @@ def test_instruct_pix2pix(disable_nsfw, cpu_offload):
|
||||
f"instruct_pix2pix_{name}.png",
|
||||
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
||||
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
||||
fx=1.3
|
||||
fx=1.3,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("disable_nsfw", [False])
|
||||
@pytest.mark.parametrize("cpu_offload", [False])
|
||||
def test_instruct_pix2pix_snow(disable_nsfw, cpu_offload):
|
||||
sd_steps = 50 if device == 'cuda' else 20
|
||||
model = ModelManager(name="instruct_pix2pix",
|
||||
device=torch.device(device),
|
||||
hf_access_token="",
|
||||
sd_run_local=False,
|
||||
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_steps = 50 if device == "cuda" else 20
|
||||
model = ModelManager(
|
||||
name=model_name,
|
||||
device=torch.device(device),
|
||||
hf_access_token="",
|
||||
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,
|
||||
)
|
||||
|
||||
name = f"snow"
|
||||
|
||||
|
||||
@@ -20,8 +20,6 @@ def test_load_model():
|
||||
hf_access_token="",
|
||||
disable_nsfw=False,
|
||||
sd_cpu_textencoder=True,
|
||||
sd_run_local=True,
|
||||
local_files_only=True,
|
||||
cpu_offload=True,
|
||||
enable_xformers=False,
|
||||
)
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
from lama_cleaner.schema import Config
|
||||
|
||||
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
|
||||
|
||||
import torch
|
||||
|
||||
from lama_cleaner.model_manager import ModelManager
|
||||
|
||||
|
||||
def test_model_switch():
|
||||
model = ModelManager(
|
||||
name="runwayml/stable-diffusion-inpainting",
|
||||
sd_controlnet=True,
|
||||
sd_controlnet_method="lllyasviel/control_v11p_sd15_canny",
|
||||
device=torch.device("mps"),
|
||||
hf_access_token="",
|
||||
disable_nsfw=True,
|
||||
sd_cpu_textencoder=True,
|
||||
cpu_offload=False,
|
||||
enable_xformers=False,
|
||||
callback=None,
|
||||
)
|
||||
|
||||
model.switch("lama")
|
||||
|
||||
|
||||
def test_controlnet_switch_onoff(caplog):
|
||||
name = "runwayml/stable-diffusion-inpainting"
|
||||
model = ModelManager(
|
||||
name=name,
|
||||
sd_controlnet=True,
|
||||
sd_controlnet_method="lllyasviel/control_v11p_sd15_canny",
|
||||
device=torch.device("mps"),
|
||||
hf_access_token="",
|
||||
disable_nsfw=True,
|
||||
sd_cpu_textencoder=True,
|
||||
cpu_offload=False,
|
||||
enable_xformers=False,
|
||||
callback=None,
|
||||
)
|
||||
|
||||
model.switch_controlnet_method(
|
||||
Config(
|
||||
name=name,
|
||||
controlnet_enabled=False,
|
||||
)
|
||||
)
|
||||
|
||||
assert "Disable controlnet" in caplog.text
|
||||
|
||||
|
||||
def test_controlnet_switch_method(caplog):
|
||||
name = "runwayml/stable-diffusion-inpainting"
|
||||
old_method = "lllyasviel/control_v11p_sd15_canny"
|
||||
new_method = "lllyasviel/control_v11p_sd15_openpose"
|
||||
model = ModelManager(
|
||||
name=name,
|
||||
sd_controlnet=True,
|
||||
sd_controlnet_method=old_method,
|
||||
device=torch.device("mps"),
|
||||
hf_access_token="",
|
||||
disable_nsfw=True,
|
||||
sd_cpu_textencoder=True,
|
||||
cpu_offload=False,
|
||||
enable_xformers=False,
|
||||
callback=None,
|
||||
)
|
||||
|
||||
model.switch_controlnet_method(
|
||||
Config(
|
||||
name=name,
|
||||
controlnet_enabled=True,
|
||||
controlnet_method=new_method,
|
||||
)
|
||||
)
|
||||
|
||||
assert f"Switch Controlnet method from {old_method} to {new_method}" in caplog.text
|
||||
|
||||
@@ -17,7 +17,7 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
|
||||
device = torch.device(device)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("name", ["sd1.5"])
|
||||
@pytest.mark.parametrize("name", ["runwayml/stable-diffusion-inpainting"])
|
||||
@pytest.mark.parametrize("sd_device", ["mps"])
|
||||
@pytest.mark.parametrize(
|
||||
"rect",
|
||||
@@ -42,7 +42,6 @@ def test_outpainting(name, sd_device, rect):
|
||||
name=name,
|
||||
device=torch.device(sd_device),
|
||||
hf_access_token="",
|
||||
sd_run_local=True,
|
||||
disable_nsfw=True,
|
||||
sd_cpu_textencoder=False,
|
||||
callback=callback,
|
||||
@@ -51,12 +50,11 @@ def test_outpainting(name, sd_device, rect):
|
||||
HDStrategy.ORIGINAL,
|
||||
prompt="a dog sitting on a bench in the park",
|
||||
sd_steps=50,
|
||||
use_croper=True,
|
||||
croper_is_outpainting=True,
|
||||
croper_x=rect[0],
|
||||
croper_y=rect[1],
|
||||
croper_width=rect[2],
|
||||
croper_height=rect[3],
|
||||
use_extender=True,
|
||||
extender_x=rect[0],
|
||||
extender_y=rect[1],
|
||||
extender_width=rect[2],
|
||||
extender_height=rect[3],
|
||||
sd_guidance_scale=8.0,
|
||||
sd_sampler=SDSampler.dpm_plus_plus,
|
||||
)
|
||||
@@ -64,13 +62,13 @@ def test_outpainting(name, sd_device, rect):
|
||||
assert_equal(
|
||||
model,
|
||||
cfg,
|
||||
f"{name.replace('.', '_')}_outpainting_dpm++_{'_'.join(map(str, rect))}.png",
|
||||
f"{name.replace('/', '--')}_outpainting_dpm++_{'_'.join(map(str, rect))}.png",
|
||||
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
||||
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("name", ["kandinsky2.2"])
|
||||
@pytest.mark.parametrize("name", ["kandinsky-community/kandinsky-2-2-decoder-inpaint"])
|
||||
@pytest.mark.parametrize("sd_device", ["mps"])
|
||||
@pytest.mark.parametrize(
|
||||
"rect",
|
||||
@@ -86,10 +84,9 @@ def test_kandinsky_outpainting(name, sd_device, rect):
|
||||
return
|
||||
|
||||
model = ModelManager(
|
||||
name="sd1.5",
|
||||
name=name,
|
||||
device=torch.device(sd_device),
|
||||
hf_access_token="",
|
||||
sd_run_local=True,
|
||||
disable_nsfw=True,
|
||||
sd_cpu_textencoder=False,
|
||||
callback=callback,
|
||||
@@ -99,12 +96,11 @@ def test_kandinsky_outpainting(name, sd_device, rect):
|
||||
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",
|
||||
sd_steps=50,
|
||||
use_croper=True,
|
||||
croper_is_outpainting=True,
|
||||
croper_x=rect[0],
|
||||
croper_y=rect[1],
|
||||
croper_width=rect[2],
|
||||
croper_height=rect[3],
|
||||
use_extender=True,
|
||||
extender_x=rect[0],
|
||||
extender_y=rect[1],
|
||||
extender_width=rect[2],
|
||||
extender_height=rect[3],
|
||||
sd_guidance_scale=7,
|
||||
sd_sampler=SDSampler.dpm_plus_plus,
|
||||
)
|
||||
@@ -112,7 +108,7 @@ def test_kandinsky_outpainting(name, sd_device, rect):
|
||||
assert_equal(
|
||||
model,
|
||||
cfg,
|
||||
f"{name.replace('.', '_')}_outpainting_dpm++_{'_'.join(map(str, rect))}.png",
|
||||
f"{name.replace('/', '--')}_outpainting_dpm++_{'_'.join(map(str, rect))}.png",
|
||||
img_p=current_dir / "cat.png",
|
||||
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
||||
fx=1,
|
||||
|
||||
@@ -10,15 +10,19 @@ from lama_cleaner.schema import HDStrategy
|
||||
from lama_cleaner.tests.test_model import get_config, get_data
|
||||
|
||||
current_dir = Path(__file__).parent.absolute().resolve()
|
||||
save_dir = current_dir / 'result'
|
||||
save_dir = current_dir / "result"
|
||||
save_dir.mkdir(exist_ok=True, parents=True)
|
||||
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
||||
device = "cuda" if torch.cuda.is_available() else "mps"
|
||||
device = torch.device(device)
|
||||
model_name = "Fantasy-Studio/Paint-by-Example"
|
||||
|
||||
|
||||
def assert_equal(
|
||||
model, config, gt_name,
|
||||
fx: float = 1, fy: float = 1,
|
||||
model,
|
||||
config,
|
||||
gt_name,
|
||||
fx: float = 1,
|
||||
fy: float = 1,
|
||||
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
||||
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
||||
example_p=current_dir / "bunny.jpeg",
|
||||
@@ -27,7 +31,9 @@ def assert_equal(
|
||||
|
||||
example_image = cv2.imread(str(example_p))
|
||||
example_image = cv2.cvtColor(example_image, cv2.COLOR_BGRA2RGB)
|
||||
example_image = cv2.resize(example_image, None, fx=fx, fy=fy, interpolation=cv2.INTER_AREA)
|
||||
example_image = cv2.resize(
|
||||
example_image, None, fx=fx, fy=fy, interpolation=cv2.INTER_AREA
|
||||
)
|
||||
|
||||
print(f"Input image shape: {img.shape}, example_image: {example_image.shape}")
|
||||
config.paint_by_example_example_image = Image.fromarray(example_image)
|
||||
@@ -35,14 +41,13 @@ def assert_equal(
|
||||
cv2.imwrite(str(save_dir / gt_name), res)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("strategy", [HDStrategy.ORIGINAL])
|
||||
def test_paint_by_example(strategy):
|
||||
model = ModelManager(name="paint_by_example", device=device, disable_nsfw=True)
|
||||
cfg = get_config(strategy, paint_by_example_steps=30)
|
||||
def test_paint_by_example():
|
||||
model = ModelManager(name=model_name, device=device, disable_nsfw=True)
|
||||
cfg = get_config(HDStrategy.ORIGINAL, sd_steps=30)
|
||||
assert_equal(
|
||||
model,
|
||||
cfg,
|
||||
f"paint_by_example_{strategy.capitalize()}.png",
|
||||
f"paint_by_example.png",
|
||||
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
||||
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
||||
fy=0.9,
|
||||
@@ -50,57 +55,31 @@ def test_paint_by_example(strategy):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("strategy", [HDStrategy.ORIGINAL])
|
||||
def test_paint_by_example_disable_nsfw(strategy):
|
||||
model = ModelManager(name="paint_by_example", device=device, disable_nsfw=False)
|
||||
cfg = get_config(strategy, paint_by_example_steps=30)
|
||||
def test_paint_by_example_cpu_offload():
|
||||
model = ModelManager(
|
||||
name=model_name, device=device, cpu_offload=True, disable_nsfw=False
|
||||
)
|
||||
cfg = get_config(HDStrategy.ORIGINAL, sd_steps=30)
|
||||
assert_equal(
|
||||
model,
|
||||
cfg,
|
||||
f"paint_by_example_{strategy.capitalize()}_disable_nsfw.png",
|
||||
f"paint_by_example_cpu_offload.png",
|
||||
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
||||
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("strategy", [HDStrategy.ORIGINAL])
|
||||
def test_paint_by_example_sd_scale(strategy):
|
||||
model = ModelManager(name="paint_by_example", device=device, disable_nsfw=True)
|
||||
cfg = get_config(strategy, paint_by_example_steps=30, sd_scale=0.85)
|
||||
def test_paint_by_example_cpu_offload_cpu_device():
|
||||
model = ModelManager(
|
||||
name=model_name, device=torch.device("cpu"), cpu_offload=True, disable_nsfw=True
|
||||
)
|
||||
cfg = get_config(HDStrategy.ORIGINAL, sd_steps=1)
|
||||
assert_equal(
|
||||
model,
|
||||
cfg,
|
||||
f"paint_by_example_{strategy.capitalize()}_sdscale.png",
|
||||
f"paint_by_example_cpu_offload_cpu_device.png",
|
||||
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
||||
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
||||
fy=0.9,
|
||||
fx=1.3
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("strategy", [HDStrategy.ORIGINAL])
|
||||
def test_paint_by_example_cpu_offload(strategy):
|
||||
model = ModelManager(name="paint_by_example", device=device, cpu_offload=True, disable_nsfw=False)
|
||||
cfg = get_config(strategy, paint_by_example_steps=30, sd_scale=0.85)
|
||||
assert_equal(
|
||||
model,
|
||||
cfg,
|
||||
f"paint_by_example_{strategy.capitalize()}_cpu_offload.png",
|
||||
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
||||
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("strategy", [HDStrategy.ORIGINAL])
|
||||
def test_paint_by_example_cpu_offload_cpu_device(strategy):
|
||||
model = ModelManager(name="paint_by_example", device=torch.device('cpu'), cpu_offload=True, disable_nsfw=True)
|
||||
cfg = get_config(strategy, paint_by_example_steps=1, sd_scale=0.85)
|
||||
assert_equal(
|
||||
model,
|
||||
cfg,
|
||||
f"paint_by_example_{strategy.capitalize()}_cpu_offload_cpu_device.png",
|
||||
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
||||
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
||||
fy=0.9,
|
||||
fx=1.3
|
||||
fx=1.3,
|
||||
)
|
||||
|
||||
@@ -7,7 +7,7 @@ import pytest
|
||||
import torch
|
||||
|
||||
from lama_cleaner.model_manager import ModelManager
|
||||
from lama_cleaner.schema import HDStrategy, SDSampler
|
||||
from lama_cleaner.schema import HDStrategy, SDSampler, FREEUConfig
|
||||
from lama_cleaner.tests.test_model import get_config, assert_equal
|
||||
|
||||
current_dir = Path(__file__).parent.absolute().resolve()
|
||||
@@ -16,178 +16,127 @@ save_dir.mkdir(exist_ok=True, parents=True)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("sd_device", ["cuda", "mps"])
|
||||
@pytest.mark.parametrize("strategy", [HDStrategy.ORIGINAL])
|
||||
@pytest.mark.parametrize("sampler", [SDSampler.ddim])
|
||||
@pytest.mark.parametrize("cpu_textencoder", [True, False])
|
||||
@pytest.mark.parametrize("disable_nsfw", [True, False])
|
||||
def test_runway_sd_1_5_ddim(
|
||||
sd_device, strategy, sampler, cpu_textencoder, disable_nsfw
|
||||
):
|
||||
def callback(i, t, latents):
|
||||
pass
|
||||
|
||||
if sd_device == "cuda" and not torch.cuda.is_available():
|
||||
return
|
||||
|
||||
sd_steps = 50 if sd_device == "cuda" else 1
|
||||
model = ModelManager(
|
||||
name="sd1.5",
|
||||
device=torch.device(sd_device),
|
||||
hf_access_token="",
|
||||
sd_run_local=True,
|
||||
disable_nsfw=disable_nsfw,
|
||||
sd_cpu_textencoder=cpu_textencoder,
|
||||
callback=callback,
|
||||
)
|
||||
cfg = get_config(strategy, prompt="a fox sitting on a bench", sd_steps=sd_steps)
|
||||
cfg.sd_sampler = sampler
|
||||
|
||||
name = f"device_{sd_device}_{sampler}_cpu_textencoder_{cpu_textencoder}_disnsfw_{disable_nsfw}"
|
||||
|
||||
assert_equal(
|
||||
model,
|
||||
cfg,
|
||||
f"runway_sd_{strategy.capitalize()}_{name}.png",
|
||||
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
||||
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
||||
fx=1.3,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("sd_device", ["cuda", "mps"])
|
||||
@pytest.mark.parametrize("strategy", [HDStrategy.ORIGINAL])
|
||||
@pytest.mark.parametrize(
|
||||
"sampler", [SDSampler.pndm, SDSampler.k_lms, SDSampler.k_euler, SDSampler.k_euler_a]
|
||||
"sampler",
|
||||
[
|
||||
SDSampler.ddim,
|
||||
SDSampler.pndm,
|
||||
SDSampler.k_lms,
|
||||
SDSampler.k_euler,
|
||||
SDSampler.k_euler_a,
|
||||
SDSampler.lcm,
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize("cpu_textencoder", [False])
|
||||
@pytest.mark.parametrize("disable_nsfw", [True])
|
||||
def test_runway_sd_1_5(sd_device, strategy, sampler, cpu_textencoder, disable_nsfw):
|
||||
def callback(i, t, latents):
|
||||
print(f"sd_step_{i}")
|
||||
|
||||
def test_runway_sd_1_5_all_samplers(
|
||||
sd_device,
|
||||
sampler,
|
||||
):
|
||||
if sd_device == "cuda" and not torch.cuda.is_available():
|
||||
return
|
||||
|
||||
sd_steps = 50 if sd_device == "cuda" else 1
|
||||
sd_steps = 30
|
||||
model = ModelManager(
|
||||
name="sd1.5",
|
||||
name="runwayml/stable-diffusion-inpainting",
|
||||
device=torch.device(sd_device),
|
||||
hf_access_token="",
|
||||
sd_run_local=True,
|
||||
disable_nsfw=disable_nsfw,
|
||||
sd_cpu_textencoder=cpu_textencoder,
|
||||
callback=callback,
|
||||
disable_nsfw=True,
|
||||
sd_cpu_textencoder=False,
|
||||
)
|
||||
cfg = get_config(
|
||||
HDStrategy.ORIGINAL, prompt="a fox sitting on a bench", sd_steps=sd_steps
|
||||
)
|
||||
cfg = get_config(strategy, prompt="a fox sitting on a bench", sd_steps=sd_steps)
|
||||
cfg.sd_sampler = sampler
|
||||
|
||||
name = f"device_{sd_device}_{sampler}_cpu_textencoder_{cpu_textencoder}_disnsfw_{disable_nsfw}"
|
||||
name = f"device_{sd_device}_{sampler}"
|
||||
|
||||
assert_equal(
|
||||
model,
|
||||
cfg,
|
||||
f"runway_sd_{strategy.capitalize()}_{name}.png",
|
||||
f"runway_sd_{name}.png",
|
||||
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
||||
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
||||
fx=1.3,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("sd_device", ["cuda", "mps"])
|
||||
@pytest.mark.parametrize("strategy", [HDStrategy.ORIGINAL])
|
||||
@pytest.mark.parametrize("sampler", [SDSampler.ddim])
|
||||
@pytest.mark.parametrize("sd_prevent_unmasked_area", [False, True])
|
||||
def test_runway_sd_1_5_negative_prompt(
|
||||
sd_device, strategy, sampler, sd_prevent_unmasked_area
|
||||
):
|
||||
def callback(i, t, latents):
|
||||
pass
|
||||
|
||||
@pytest.mark.parametrize("sampler", [SDSampler.lcm])
|
||||
def test_runway_sd_lcm_lora(sd_device, strategy, sampler):
|
||||
if sd_device == "cuda" and not torch.cuda.is_available():
|
||||
return
|
||||
|
||||
sd_steps = 50 if sd_device == "cuda" else 20
|
||||
sd_steps = 5
|
||||
model = ModelManager(
|
||||
name="sd1.5",
|
||||
name="runwayml/stable-diffusion-inpainting",
|
||||
device=torch.device(sd_device),
|
||||
hf_access_token="",
|
||||
sd_run_local=True,
|
||||
disable_nsfw=False,
|
||||
disable_nsfw=True,
|
||||
sd_cpu_textencoder=False,
|
||||
callback=callback,
|
||||
)
|
||||
cfg = get_config(
|
||||
strategy,
|
||||
prompt="face of a fox, sitting on a bench",
|
||||
sd_steps=sd_steps,
|
||||
prompt="Face of a fox, high resolution, sitting on a park bench",
|
||||
negative_prompt="orange, yellow, small",
|
||||
sd_sampler=sampler,
|
||||
sd_match_histograms=True,
|
||||
sd_prevent_unmasked_area=sd_prevent_unmasked_area,
|
||||
)
|
||||
|
||||
name = f"{sampler}_negative_prompt"
|
||||
|
||||
assert_equal(
|
||||
model,
|
||||
cfg,
|
||||
f"runway_sd_{strategy.capitalize()}_{name}_prevent_unmasked_area_{sd_prevent_unmasked_area}.png",
|
||||
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
||||
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
||||
fx=1,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("sd_device", ["cuda", "mps"])
|
||||
@pytest.mark.parametrize("strategy", [HDStrategy.ORIGINAL])
|
||||
@pytest.mark.parametrize("sampler", [SDSampler.k_euler_a])
|
||||
@pytest.mark.parametrize("cpu_textencoder", [False])
|
||||
@pytest.mark.parametrize("disable_nsfw", [False])
|
||||
def test_runway_sd_1_5_sd_scale(
|
||||
sd_device, strategy, sampler, cpu_textencoder, disable_nsfw
|
||||
):
|
||||
if sd_device == "cuda" and not torch.cuda.is_available():
|
||||
return
|
||||
|
||||
sd_steps = 50 if sd_device == "cuda" else 20
|
||||
model = ModelManager(
|
||||
name="sd1.5",
|
||||
device=torch.device(sd_device),
|
||||
hf_access_token="",
|
||||
sd_run_local=True,
|
||||
disable_nsfw=disable_nsfw,
|
||||
sd_cpu_textencoder=cpu_textencoder,
|
||||
)
|
||||
cfg = get_config(
|
||||
strategy, prompt="a fox sitting on a bench", sd_steps=sd_steps, sd_scale=0.85
|
||||
sd_guidance_scale=2,
|
||||
sd_lcm_lora=True,
|
||||
)
|
||||
cfg.sd_sampler = sampler
|
||||
|
||||
name = f"device_{sd_device}_{sampler}_cpu_textencoder_{cpu_textencoder}_disnsfw_{disable_nsfw}"
|
||||
|
||||
assert_equal(
|
||||
model,
|
||||
cfg,
|
||||
f"runway_sd_{strategy.capitalize()}_{name}_sdscale.png",
|
||||
f"runway_sd_1_5_lcm_lora.png",
|
||||
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
||||
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
||||
fx=1.3,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("sd_device", ["cuda", "mps"])
|
||||
@pytest.mark.parametrize("strategy", [HDStrategy.ORIGINAL])
|
||||
@pytest.mark.parametrize("sampler", [SDSampler.k_euler_a])
|
||||
@pytest.mark.parametrize("sampler", [SDSampler.ddim])
|
||||
def test_runway_sd_freeu(sd_device, strategy, sampler):
|
||||
if sd_device == "cuda" and not torch.cuda.is_available():
|
||||
return
|
||||
|
||||
sd_steps = 30
|
||||
model = ModelManager(
|
||||
name="runwayml/stable-diffusion-inpainting",
|
||||
device=torch.device(sd_device),
|
||||
hf_access_token="",
|
||||
disable_nsfw=True,
|
||||
sd_cpu_textencoder=False,
|
||||
)
|
||||
cfg = get_config(
|
||||
strategy,
|
||||
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(),
|
||||
)
|
||||
cfg.sd_sampler = sampler
|
||||
|
||||
assert_equal(
|
||||
model,
|
||||
cfg,
|
||||
f"runway_sd_1_5_freeu.png",
|
||||
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
||||
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("sd_device", ["cuda", "mps"])
|
||||
@pytest.mark.parametrize("strategy", [HDStrategy.ORIGINAL])
|
||||
@pytest.mark.parametrize("sampler", [SDSampler.ddim])
|
||||
def test_runway_sd_sd_strength(sd_device, strategy, sampler):
|
||||
if sd_device == "cuda" and not torch.cuda.is_available():
|
||||
return
|
||||
|
||||
sd_steps = 50 if sd_device == "cuda" else 20
|
||||
sd_steps = 30
|
||||
model = ModelManager(
|
||||
name="sd1.5",
|
||||
name="runwayml/stable-diffusion-inpainting",
|
||||
device=torch.device(sd_device),
|
||||
hf_access_token="",
|
||||
sd_run_local=True,
|
||||
disable_nsfw=True,
|
||||
sd_cpu_textencoder=False,
|
||||
)
|
||||
@@ -205,6 +154,33 @@ def test_runway_sd_sd_strength(sd_device, strategy, sampler):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("sd_device", ["cuda", "mps"])
|
||||
@pytest.mark.parametrize("strategy", [HDStrategy.ORIGINAL])
|
||||
@pytest.mark.parametrize("sampler", [SDSampler.ddim])
|
||||
def test_runway_norm_sd_model(sd_device, strategy, sampler):
|
||||
if sd_device == "cuda" and not torch.cuda.is_available():
|
||||
return
|
||||
|
||||
sd_steps = 30
|
||||
model = ModelManager(
|
||||
name="runwayml/stable-diffusion-v1-5",
|
||||
device=torch.device(sd_device),
|
||||
hf_access_token="",
|
||||
disable_nsfw=True,
|
||||
sd_cpu_textencoder=False,
|
||||
)
|
||||
cfg = get_config(strategy, prompt="face of a fox, sitting on a bench", sd_steps=sd_steps)
|
||||
cfg.sd_sampler = sampler
|
||||
|
||||
assert_equal(
|
||||
model,
|
||||
cfg,
|
||||
f"runway_{sd_device}_norm_sd_model.png",
|
||||
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
||||
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("sd_device", ["cuda"])
|
||||
@pytest.mark.parametrize("strategy", [HDStrategy.ORIGINAL])
|
||||
@pytest.mark.parametrize("sampler", [SDSampler.k_euler_a])
|
||||
@@ -212,19 +188,16 @@ def test_runway_sd_1_5_cpu_offload(sd_device, strategy, sampler):
|
||||
if sd_device == "cuda" and not torch.cuda.is_available():
|
||||
return
|
||||
|
||||
sd_steps = 50 if sd_device == "cuda" else 20
|
||||
sd_steps = 30
|
||||
model = ModelManager(
|
||||
name="sd1.5",
|
||||
name="runwayml/stable-diffusion-inpainting",
|
||||
device=torch.device(sd_device),
|
||||
hf_access_token="",
|
||||
sd_run_local=True,
|
||||
disable_nsfw=True,
|
||||
sd_cpu_textencoder=False,
|
||||
cpu_offload=True,
|
||||
)
|
||||
cfg = get_config(
|
||||
strategy, prompt="a fox sitting on a bench", sd_steps=sd_steps, sd_scale=0.85
|
||||
)
|
||||
cfg = get_config(strategy, prompt="a fox sitting on a bench", sd_steps=sd_steps)
|
||||
cfg.sd_sampler = sampler
|
||||
|
||||
name = f"device_{sd_device}_{sampler}"
|
||||
@@ -239,28 +212,27 @@ def test_runway_sd_1_5_cpu_offload(sd_device, strategy, sampler):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("sd_device", ["cuda", "mps"])
|
||||
@pytest.mark.parametrize("sampler", [SDSampler.uni_pc])
|
||||
@pytest.mark.parametrize("sampler", [SDSampler.ddim])
|
||||
@pytest.mark.parametrize(
|
||||
"local_model_path",
|
||||
"name",
|
||||
[
|
||||
"/Users/cwq/data/models/sd-v1-5-inpainting.ckpt",
|
||||
"/Users/cwq/data/models/sd-v1-5-inpainting.safetensors",
|
||||
"sd-v1-5-inpainting.ckpt",
|
||||
"sd-v1-5-inpainting.safetensors",
|
||||
"v1-5-pruned-emaonly.safetensors",
|
||||
],
|
||||
)
|
||||
def test_local_file_path(sd_device, sampler, local_model_path):
|
||||
def test_local_file_path(sd_device, sampler, name):
|
||||
if sd_device == "cuda" and not torch.cuda.is_available():
|
||||
return
|
||||
|
||||
sd_steps = 1 if sd_device == "cpu" else 30
|
||||
sd_steps = 30
|
||||
model = ModelManager(
|
||||
name="sd1.5",
|
||||
name=name,
|
||||
device=torch.device(sd_device),
|
||||
hf_access_token="",
|
||||
sd_run_local=True,
|
||||
disable_nsfw=True,
|
||||
sd_cpu_textencoder=False,
|
||||
cpu_offload=True,
|
||||
sd_local_model_path=local_model_path,
|
||||
cpu_offload=False,
|
||||
)
|
||||
cfg = get_config(
|
||||
HDStrategy.ORIGINAL,
|
||||
@@ -269,7 +241,7 @@ def test_local_file_path(sd_device, sampler, local_model_path):
|
||||
)
|
||||
cfg.sd_sampler = sampler
|
||||
|
||||
name = f"device_{sd_device}_{sampler}_{Path(local_model_path).stem}"
|
||||
name = f"device_{sd_device}_{sampler}_{name}"
|
||||
|
||||
assert_equal(
|
||||
model,
|
||||
|
||||
@@ -7,7 +7,7 @@ import pytest
|
||||
import torch
|
||||
|
||||
from lama_cleaner.model_manager import ModelManager
|
||||
from lama_cleaner.schema import HDStrategy, SDSampler
|
||||
from lama_cleaner.schema import HDStrategy, SDSampler, FREEUConfig
|
||||
from lama_cleaner.tests.test_model import get_config, assert_equal
|
||||
|
||||
current_dir = Path(__file__).parent.absolute().resolve()
|
||||
@@ -15,12 +15,10 @@ save_dir = current_dir / "result"
|
||||
save_dir.mkdir(exist_ok=True, parents=True)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("sd_device", ["mps"])
|
||||
@pytest.mark.parametrize("sd_device", ["cuda", "mps"])
|
||||
@pytest.mark.parametrize("strategy", [HDStrategy.ORIGINAL])
|
||||
@pytest.mark.parametrize("sampler", [SDSampler.ddim])
|
||||
@pytest.mark.parametrize("cpu_textencoder", [False])
|
||||
@pytest.mark.parametrize("disable_nsfw", [True])
|
||||
def test_sdxl(sd_device, strategy, sampler, cpu_textencoder, disable_nsfw):
|
||||
def test_sdxl(sd_device, strategy, sampler):
|
||||
def callback(i, t, latents):
|
||||
pass
|
||||
|
||||
@@ -29,24 +27,23 @@ def test_sdxl(sd_device, strategy, sampler, cpu_textencoder, disable_nsfw):
|
||||
|
||||
sd_steps = 20
|
||||
model = ModelManager(
|
||||
name="sdxl",
|
||||
name="diffusers/stable-diffusion-xl-1.0-inpainting-0.1",
|
||||
device=torch.device(sd_device),
|
||||
hf_access_token="",
|
||||
sd_run_local=False,
|
||||
disable_nsfw=disable_nsfw,
|
||||
sd_cpu_textencoder=cpu_textencoder,
|
||||
disable_nsfw=True,
|
||||
sd_cpu_textencoder=False,
|
||||
callback=callback,
|
||||
)
|
||||
cfg = get_config(
|
||||
strategy,
|
||||
prompt="a fox sitting on a bench",
|
||||
prompt="face of a fox, sitting on a bench",
|
||||
sd_steps=sd_steps,
|
||||
sd_strength=0.99,
|
||||
sd_strength=1.0,
|
||||
sd_guidance_scale=7.0,
|
||||
)
|
||||
cfg.sd_sampler = sampler
|
||||
|
||||
name = f"device_{sd_device}_{sampler}_cpu_textencoder_{cpu_textencoder}_disnsfw_{disable_nsfw}"
|
||||
name = f"device_{sd_device}_{sampler}"
|
||||
|
||||
assert_equal(
|
||||
model,
|
||||
@@ -59,6 +56,67 @@ def test_sdxl(sd_device, strategy, sampler, cpu_textencoder, disable_nsfw):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("sd_device", ["cuda", "mps"])
|
||||
@pytest.mark.parametrize("strategy", [HDStrategy.ORIGINAL])
|
||||
@pytest.mark.parametrize("sampler", [SDSampler.ddim])
|
||||
def test_sdxl_lcm_lora_and_freeu(sd_device, strategy, sampler):
|
||||
def callback(i, t, latents):
|
||||
pass
|
||||
|
||||
if sd_device == "cuda" and not torch.cuda.is_available():
|
||||
return
|
||||
|
||||
sd_steps = 5
|
||||
model = ModelManager(
|
||||
name="diffusers/stable-diffusion-xl-1.0-inpainting-0.1",
|
||||
device=torch.device(sd_device),
|
||||
hf_access_token="",
|
||||
disable_nsfw=True,
|
||||
sd_cpu_textencoder=False,
|
||||
callback=callback,
|
||||
)
|
||||
cfg = get_config(
|
||||
strategy,
|
||||
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
|
||||
|
||||
name = f"device_{sd_device}_{sampler}"
|
||||
|
||||
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(
|
||||
strategy,
|
||||
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,
|
||||
f"sdxl_{name}_freeu.png",
|
||||
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
||||
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
||||
fx=2,
|
||||
fy=2,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("sd_device", ["mps"])
|
||||
@pytest.mark.parametrize(
|
||||
"rect",
|
||||
@@ -67,33 +125,26 @@ def test_sdxl(sd_device, strategy, sampler, cpu_textencoder, disable_nsfw):
|
||||
],
|
||||
)
|
||||
def test_sdxl_outpainting(sd_device, rect):
|
||||
def callback(i, t, latents):
|
||||
pass
|
||||
|
||||
if sd_device == "cuda" and not torch.cuda.is_available():
|
||||
return
|
||||
|
||||
model = ModelManager(
|
||||
name="sdxl",
|
||||
name="diffusers/stable-diffusion-xl-1.0-inpainting-0.1",
|
||||
device=torch.device(sd_device),
|
||||
hf_access_token="",
|
||||
sd_run_local=True,
|
||||
disable_nsfw=True,
|
||||
sd_cpu_textencoder=False,
|
||||
callback=callback,
|
||||
)
|
||||
|
||||
cfg = get_config(
|
||||
HDStrategy.ORIGINAL,
|
||||
prompt="a dog sitting on a bench in the park",
|
||||
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",
|
||||
sd_steps=20,
|
||||
use_croper=True,
|
||||
croper_is_outpainting=True,
|
||||
croper_x=rect[0],
|
||||
croper_y=rect[1],
|
||||
croper_width=rect[2],
|
||||
croper_height=rect[3],
|
||||
use_extender=True,
|
||||
extender_x=rect[0],
|
||||
extender_y=rect[1],
|
||||
extender_width=rect[2],
|
||||
extender_height=rect[3],
|
||||
sd_strength=1.0,
|
||||
sd_guidance_scale=8.0,
|
||||
sd_sampler=SDSampler.ddim,
|
||||
|
||||
Reference in New Issue
Block a user