Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More inference tests #221

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions libs/spandrel/spandrel/architectures/KBNet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _load_l(self, state_dict: StateDict):
state_dict,
architecture=self,
purpose="Restoration",
tags=["L"],
tags=["L", f"{dim}dim"],
supports_half=False,
supports_bfloat16=True,
scale=1,
Expand All @@ -117,12 +117,12 @@ def _load_s(self, state_dict: StateDict):
enc_count = get_seq_len(state_dict, "encoders")
enc_blk_nums = [1] * enc_count
for i in range(enc_count):
enc_blk_nums[i] = get_seq_len(state_dict, "encoders." + str(i))
enc_blk_nums[i] = get_seq_len(state_dict, f"encoders.{i}")

dec_count = get_seq_len(state_dict, "decoders")
dec_blk_nums = [1] * dec_count
for i in range(dec_count):
dec_blk_nums[i] = get_seq_len(state_dict, "decoders." + str(i))
dec_blk_nums[i] = get_seq_len(state_dict, f"decoders.{i}")

# in code: ffn_ch = int(c * ffn_scale)
temp_c = state_dict["middle_blks.0.conv4.weight"].shape[1]
Expand All @@ -148,7 +148,11 @@ def _load_s(self, state_dict: StateDict):
state_dict,
architecture=self,
purpose="Restoration",
tags=["S"],
tags=[
"S",
f"{width}w",
*(["lightweight"] if lightweight else []),
],
supports_half=False,
supports_bfloat16=True,
scale=1,
Expand Down
42 changes: 42 additions & 0 deletions tests/__snapshots__/test_KBNet.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# serializer version: 1
# name: test_derain
ImageModelDescriptor(
architecture=KBNetArch(
id='KBNet',
name='KBNet',
),
input_channels=3,
output_channels=3,
purpose='Restoration',
scale=1,
size_requirements=SizeRequirements(minimum=0, multiple_of=16, square=False),
supports_bfloat16=True,
supports_half=False,
tags=list([
'L',
'48dim',
]),
tiling=<ModelTiling.SUPPORTED: 1>,
)
# ---
# name: test_sidd
ImageModelDescriptor(
architecture=KBNetArch(
id='KBNet',
name='KBNet',
),
input_channels=3,
output_channels=3,
purpose='Restoration',
scale=1,
size_requirements=SizeRequirements(minimum=0, multiple_of=1, square=False),
supports_bfloat16=True,
supports_half=False,
tags=list([
'S',
'64w',
'lightweight',
]),
tiling=<ModelTiling.SUPPORTED: 1>,
)
# ---
Binary file added tests/images/outputs/32x32/1x-KBNet_derain.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/images/outputs/32x32/fftformer_GoPro.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/images/outputs/jpeg-15/1x-KBNet_sidd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions tests/test_FFTformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from .util import (
ModelFile,
TestImage,
assert_image_inference,
assert_loads_correctly,
assert_size_requirements,
disallowed_props,
Expand Down Expand Up @@ -38,3 +40,4 @@ def test_fftformer_GoPro(snapshot):
model = file.load_model()
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, FFTformer)
assert_image_inference(file, model, [TestImage.SR_32])
42 changes: 41 additions & 1 deletion tests/test_KBNet.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
from spandrel.architectures.KBNet import KBNet_l, KBNet_s, KBNetArch

from .util import assert_loads_correctly, skip_if_unchanged
from .util import (
ModelFile,
TestImage,
assert_image_inference,
assert_loads_correctly,
assert_size_requirements,
disallowed_props,
skip_if_unchanged,
)

skip_if_unchanged(__file__)

Expand All @@ -27,3 +35,35 @@ def test_load():
lambda: KBNet_s(width=32, ffn_scale=3),
lambda: KBNet_s(width=32, lightweight=True),
)


def test_size_requirements():
file = ModelFile.from_url(
"https://github.com/OpenModelDB/model-hub/releases/download/kbnet/1x-KBNet_derain.pth",
)
assert_size_requirements(file.load_model())

file = ModelFile.from_url(
"https://github.com/OpenModelDB/model-hub/releases/download/kbnet/1x-KBNet_sidd.pth",
)
assert_size_requirements(file.load_model())


def test_derain(snapshot):
file = ModelFile.from_url(
"https://github.com/OpenModelDB/model-hub/releases/download/kbnet/1x-KBNet_derain.pth",
)
model = file.load_model()
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, KBNet_l)
assert_image_inference(file, model, [TestImage.SR_32])


def test_sidd(snapshot):
file = ModelFile.from_url(
"https://github.com/OpenModelDB/model-hub/releases/download/kbnet/1x-KBNet_sidd.pth",
)
model = file.load_model()
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, KBNet_s)
assert_image_inference(file, model, [TestImage.JPEG_15])
3 changes: 3 additions & 0 deletions tests/test_Restormer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from .util import (
ModelFile,
TestImage,
assert_image_inference,
assert_loads_correctly,
assert_size_requirements,
disallowed_props,
Expand Down Expand Up @@ -82,6 +84,7 @@ def test_gaussian_color_denoising_blind(snapshot):
model = file.load_model()
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, Restormer)
assert_image_inference(file, model, [TestImage.JPEG_15])


def test_gaussian_gray_denoising_sigma25(snapshot):
Expand Down
3 changes: 3 additions & 0 deletions tests/test_SCUNet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from .util import (
ModelFile,
TestImage,
assert_image_inference,
assert_loads_correctly,
assert_size_requirements,
disallowed_props,
Expand Down Expand Up @@ -43,6 +45,7 @@ def test_SCUNet_color_GAN(snapshot):
model = file.load_model()
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, SCUNet)
assert_image_inference(file, model, [TestImage.JPEG_15])


def test_SCUNet_color_RSNR(snapshot):
Expand Down
Loading