## 主要更新 - ✨ 更新所有依赖到最新稳定版本 - 📝 添加详细的项目文档和模型推荐 - 🔧 配置 VSCode Cloud Studio 预览功能 - 🐛 修复 PyTorch API 弃用警告 ## 依赖更新 - diffusers: 0.27.2 → 0.35.2 - gradio: 4.21.0 → 5.46.0 - peft: 0.7.1 → 0.18.0 - Pillow: 9.5.0 → 11.3.0 - fastapi: 0.108.0 → 0.116.2 ## 新增文件 - CLAUDE.md - 项目架构和开发指南 - UPGRADE_NOTES.md - 详细的升级说明 - .vscode/preview.yml - 预览配置 - .vscode/LAUNCH_GUIDE.md - 启动指南 - .gitignore - 更新的忽略规则 ## 代码修复 - 修复 iopaint/model/ldm.py 中的 torch.cuda.amp.autocast() 弃用警告 ## 文档更新 - README.md - 添加模型推荐和使用指南 - 完整的项目源码(iopaint/) - Web 前端源码(web_app/) 🤖 Generated with Claude Code
161 lines
4.8 KiB
Python
161 lines
4.8 KiB
Python
import pytest
|
|
import torch
|
|
|
|
from iopaint.model_manager import ModelManager
|
|
from iopaint.schema import HDStrategy, LDMSampler
|
|
from iopaint.tests.utils import assert_equal, get_config, current_dir, check_device
|
|
|
|
|
|
@pytest.mark.parametrize("device", ["cuda", "mps", "cpu"])
|
|
@pytest.mark.parametrize(
|
|
"strategy", [HDStrategy.ORIGINAL, HDStrategy.RESIZE, HDStrategy.CROP]
|
|
)
|
|
def test_lama(device, strategy):
|
|
check_device(device)
|
|
model = ModelManager(name="lama", device=device)
|
|
assert_equal(
|
|
model,
|
|
get_config(strategy=strategy),
|
|
f"lama_{strategy[0].upper() + strategy[1:]}_result.png",
|
|
)
|
|
|
|
fx = 1.3
|
|
assert_equal(
|
|
model,
|
|
get_config(strategy=strategy),
|
|
f"lama_{strategy[0].upper() + strategy[1:]}_fx_{fx}_result.png",
|
|
fx=1.3,
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("device", ["cuda", "cpu"])
|
|
@pytest.mark.parametrize(
|
|
"strategy", [HDStrategy.ORIGINAL, HDStrategy.RESIZE, HDStrategy.CROP]
|
|
)
|
|
@pytest.mark.parametrize("ldm_sampler", [LDMSampler.ddim, LDMSampler.plms])
|
|
def test_ldm(device, strategy, ldm_sampler):
|
|
check_device(device)
|
|
model = ModelManager(name="ldm", device=device)
|
|
cfg = get_config(strategy=strategy, ldm_sampler=ldm_sampler)
|
|
assert_equal(
|
|
model, cfg, f"ldm_{strategy[0].upper() + strategy[1:]}_{ldm_sampler}_result.png"
|
|
)
|
|
|
|
fx = 1.3
|
|
assert_equal(
|
|
model,
|
|
cfg,
|
|
f"ldm_{strategy[0].upper() + strategy[1:]}_{ldm_sampler}_fx_{fx}_result.png",
|
|
fx=fx,
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("device", ["cuda", "cpu"])
|
|
@pytest.mark.parametrize(
|
|
"strategy", [HDStrategy.ORIGINAL, HDStrategy.RESIZE, HDStrategy.CROP]
|
|
)
|
|
@pytest.mark.parametrize("zits_wireframe", [False, True])
|
|
def test_zits(device, strategy, zits_wireframe):
|
|
check_device(device)
|
|
model = ModelManager(name="zits", device=device)
|
|
cfg = get_config(strategy=strategy, zits_wireframe=zits_wireframe)
|
|
assert_equal(
|
|
model,
|
|
cfg,
|
|
f"zits_{strategy[0].upper() + strategy[1:]}_wireframe_{zits_wireframe}_result.png",
|
|
)
|
|
|
|
fx = 1.3
|
|
assert_equal(
|
|
model,
|
|
cfg,
|
|
f"zits_{strategy.capitalize()}_wireframe_{zits_wireframe}_fx_{fx}_result.png",
|
|
fx=fx,
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("device", ["cuda", "cpu"])
|
|
@pytest.mark.parametrize("strategy", [HDStrategy.ORIGINAL])
|
|
@pytest.mark.parametrize("no_half", [True, False])
|
|
def test_mat(device, strategy, no_half):
|
|
check_device(device)
|
|
model = ModelManager(name="mat", device=device, no_half=no_half)
|
|
cfg = get_config(strategy=strategy)
|
|
|
|
assert_equal(
|
|
model,
|
|
cfg,
|
|
f"mat_{strategy.capitalize()}_result.png",
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("device", ["cuda", "cpu"])
|
|
@pytest.mark.parametrize("strategy", [HDStrategy.ORIGINAL])
|
|
def test_fcf(device, strategy):
|
|
check_device(device)
|
|
model = ModelManager(name="fcf", device=device)
|
|
cfg = get_config(strategy=strategy)
|
|
|
|
assert_equal(model, cfg, f"fcf_{strategy.capitalize()}_result.png", fx=2, fy=2)
|
|
assert_equal(model, cfg, f"fcf_{strategy.capitalize()}_result.png", fx=3.8, fy=2)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"strategy", [HDStrategy.ORIGINAL, HDStrategy.RESIZE, HDStrategy.CROP]
|
|
)
|
|
@pytest.mark.parametrize("cv2_flag", ["INPAINT_NS", "INPAINT_TELEA"])
|
|
@pytest.mark.parametrize("cv2_radius", [3, 15])
|
|
def test_cv2(strategy, cv2_flag, cv2_radius):
|
|
model = ModelManager(
|
|
name="cv2",
|
|
device=torch.device("cpu"),
|
|
)
|
|
cfg = get_config(strategy=strategy, cv2_flag=cv2_flag, cv2_radius=cv2_radius)
|
|
assert_equal(
|
|
model,
|
|
cfg,
|
|
f"cv2_{strategy.capitalize()}_{cv2_flag}_{cv2_radius}.png",
|
|
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
|
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("device", ["cuda", "cpu"])
|
|
@pytest.mark.parametrize(
|
|
"strategy", [HDStrategy.ORIGINAL, HDStrategy.RESIZE, HDStrategy.CROP]
|
|
)
|
|
def test_manga(device, strategy):
|
|
check_device(device)
|
|
model = ModelManager(
|
|
name="manga",
|
|
device=torch.device(device),
|
|
)
|
|
cfg = get_config(strategy=strategy)
|
|
assert_equal(
|
|
model,
|
|
cfg,
|
|
f"manga_{strategy.capitalize()}.png",
|
|
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
|
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("device", ["cuda", "mps", "cpu"])
|
|
@pytest.mark.parametrize("strategy", [HDStrategy.ORIGINAL])
|
|
def test_mi_gan(device, strategy):
|
|
check_device(device)
|
|
model = ModelManager(
|
|
name="migan",
|
|
device=torch.device(device),
|
|
)
|
|
cfg = get_config(strategy=strategy)
|
|
assert_equal(
|
|
model,
|
|
cfg,
|
|
f"migan_device_{device}.png",
|
|
img_p=current_dir / "overture-creations-5sI6fQgYIuo.png",
|
|
mask_p=current_dir / "overture-creations-5sI6fQgYIuo_mask.png",
|
|
fx=1.5,
|
|
fy=1.7
|
|
)
|