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

Image tests #1

Merged
merged 6 commits into from
Nov 17, 2023
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
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
python-version: '3.9'
cache: 'pip'
- run: pip install .[typecheck]
- run: pip install .[test]
- run: pyright src/
- run: pyright tests/
- run: pyright scripts/
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dynamic = ["version"]
build = ["setuptools>=46.4.0", "wheel", "build", "twine"]
lint = ["ruff==0.1.4"]
typecheck = ["pyright==1.1.335"]
test = ["pytest==7.4.0", "syrupy==4.6.0"]
test = ["pytest==7.4.0", "syrupy==4.6.0", "opencv-python==4.8.1.78"]

# [tool.setuptools.dynamic]
# version = { attr = "spandrel.VERSION" }
Expand Down Expand Up @@ -73,4 +73,4 @@ ignore = [
"**/tests/**/*" = ["N802"]

[tool.pytest.ini_options]
filterwarnings = ["ignore::DeprecationWarning"]
filterwarnings = ["ignore::DeprecationWarning", "ignore::UserWarning"]
1 change: 1 addition & 0 deletions src/spandrel/architectures/ESRGAN/arch/RRDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(
super().__init__()

self.shuffle_factor = shuffle_factor
self.scale = scale

upsample_block = {
"upconv": B.upconv_block,
Expand Down
1 change: 1 addition & 0 deletions src/spandrel/architectures/SwinIR/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def load(state_dict: StateDict) -> SRModelDescriptor[SwinIR]:
num_feat=num_feat,
num_in_ch=num_in_ch,
num_out_ch=num_out_ch,
start_unshuffle=start_unshuffle,
)

head_length = len(depths) # type: ignore
Expand Down
2 changes: 2 additions & 0 deletions src/spandrel/architectures/SwinIR/arch/SwinIR.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,9 +835,11 @@ def __init__(
img_range=1.0,
upsampler="",
resi_connection="1conv",
start_unshuffle=1,
**kwargs,
):
super().__init__()
self.start_unshuffle = start_unshuffle
num_in_ch = in_chans
num_out_ch = in_chans
num_feat = 64
Expand Down
Binary file added tests/images/inputs/16x16.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/inputs/32x32.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/inputs/64x64.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.
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.
Binary file added tests/images/outputs/16x16/1x-Anti-Aliasing.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/16x16/2x-AniScale.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/16x16/2xHFA2kAVCOmniSR.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/16x16/4x-ardo.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/16x16/4xLexicaHAT.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/16x16/BSRGAN.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/16x16/BSRGANx2.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/16x16/RealESRGAN_x2plus.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/16x16/RealESRGAN_x4plus.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.
Binary file added tests/images/outputs/16x16/RealESRNet_x4plus.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/16x16/RealSR_DPED.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/16x16/RealSR_JPEG.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.
Binary file added tests/images/outputs/16x16/swift_srgan_2x.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/16x16/swift_srgan_4x.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.
Binary file added tests/images/outputs/32x32/1x-Anti-Aliasing.png
Binary file added tests/images/outputs/32x32/2x-AniScale.png
Binary file added tests/images/outputs/32x32/2xHFA2kAVCOmniSR.png
Binary file added tests/images/outputs/32x32/4x-ardo.png
Binary file added tests/images/outputs/32x32/4xLexicaHAT.png
Binary file added tests/images/outputs/32x32/BSRGAN.png
Binary file added tests/images/outputs/32x32/BSRGANx2.png
Binary file added tests/images/outputs/32x32/RealESRGAN_x2plus.png
Binary file added tests/images/outputs/32x32/RealESRGAN_x4plus.png
Binary file added tests/images/outputs/32x32/RealESRNet_x4plus.png
Binary file added tests/images/outputs/32x32/RealSR_DPED.png
Binary file added tests/images/outputs/32x32/RealSR_JPEG.png
Binary file added tests/images/outputs/32x32/swift_srgan_2x.png
Binary file added tests/images/outputs/32x32/swift_srgan_4x.png
Binary file added tests/images/outputs/64x64/1x-Anti-Aliasing.png
Binary file added tests/images/outputs/64x64/2x-AniScale.png
Binary file added tests/images/outputs/64x64/2xHFA2kAVCOmniSR.png
Binary file added tests/images/outputs/64x64/4x-ardo.png
Binary file added tests/images/outputs/64x64/4xLexicaHAT.png
Binary file added tests/images/outputs/64x64/BSRGAN.png
Binary file added tests/images/outputs/64x64/BSRGANx2.png
Binary file added tests/images/outputs/64x64/RealESRGAN_x2plus.png
Binary file added tests/images/outputs/64x64/RealESRGAN_x4plus.png
Binary file added tests/images/outputs/64x64/RealESRNet_x4plus.png
Binary file added tests/images/outputs/64x64/RealSR_DPED.png
Binary file added tests/images/outputs/64x64/RealSR_JPEG.png
Binary file added tests/images/outputs/64x64/swift_srgan_2x.png
Binary file added tests/images/outputs/64x64/swift_srgan_4x.png
12 changes: 11 additions & 1 deletion tests/test_Compact.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from spandrel import ModelLoader
from spandrel.architectures.Compact import SRVGGNetCompact

from .util import ModelFile, disallowed_props
from .util import ModelFile, TestImage, assert_image_inference, disallowed_props


def test_Compact_realesr_general_x4v3(snapshot):
Expand All @@ -11,6 +11,11 @@ def test_Compact_realesr_general_x4v3(snapshot):
model = ModelLoader().load_from_file(file.path)
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, SRVGGNetCompact)
assert_image_inference(
file,
model,
[TestImage.SR_16, TestImage.SR_32, TestImage.SR_64],
)


def test_Compact_community(snapshot):
Expand All @@ -20,3 +25,8 @@ def test_Compact_community(snapshot):
model = ModelLoader().load_from_file(file.path)
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, SRVGGNetCompact)
assert_image_inference(
file,
model,
[TestImage.SR_16, TestImage.SR_32, TestImage.SR_64],
)
47 changes: 46 additions & 1 deletion tests/test_ESRGAN.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from spandrel import ModelLoader
from spandrel.architectures.ESRGAN import RRDBNet

from .util import ModelFile, disallowed_props
from .util import ModelFile, TestImage, assert_image_inference, disallowed_props


def test_ESRGAN_community(snapshot):
Expand All @@ -11,6 +11,11 @@ def test_ESRGAN_community(snapshot):
model = ModelLoader().load_from_file(file.path)
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, RRDBNet)
assert_image_inference(
file,
model,
[TestImage.SR_16, TestImage.SR_32, TestImage.SR_64],
)


def test_BSRGAN(snapshot):
Expand All @@ -20,6 +25,11 @@ def test_BSRGAN(snapshot):
model = ModelLoader().load_from_file(file.path)
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, RRDBNet)
assert_image_inference(
file,
model,
[TestImage.SR_16, TestImage.SR_32, TestImage.SR_64],
)


def test_BSRGAN_2x(snapshot):
Expand All @@ -29,6 +39,11 @@ def test_BSRGAN_2x(snapshot):
model = ModelLoader().load_from_file(file.path)
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, RRDBNet)
assert_image_inference(
file,
model,
[TestImage.SR_16, TestImage.SR_32, TestImage.SR_64],
)


def test_RealSR_DPED(snapshot):
Expand All @@ -38,6 +53,11 @@ def test_RealSR_DPED(snapshot):
model = ModelLoader().load_from_file(file.path)
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, RRDBNet)
assert_image_inference(
file,
model,
[TestImage.SR_16, TestImage.SR_32, TestImage.SR_64],
)


def test_RealSR_JPEG(snapshot):
Expand All @@ -47,6 +67,11 @@ def test_RealSR_JPEG(snapshot):
model = ModelLoader().load_from_file(file.path)
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, RRDBNet)
assert_image_inference(
file,
model,
[TestImage.SR_16, TestImage.SR_32, TestImage.SR_64],
)


def test_RealESRGAN_x4plus(snapshot):
Expand All @@ -56,6 +81,11 @@ def test_RealESRGAN_x4plus(snapshot):
model = ModelLoader().load_from_file(file.path)
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, RRDBNet)
assert_image_inference(
file,
model,
[TestImage.SR_16, TestImage.SR_32, TestImage.SR_64],
)


def test_RealESRGAN_x2plus(snapshot):
Expand All @@ -65,6 +95,11 @@ def test_RealESRGAN_x2plus(snapshot):
model = ModelLoader().load_from_file(file.path)
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, RRDBNet)
assert_image_inference(
file,
model,
[TestImage.SR_16, TestImage.SR_32, TestImage.SR_64],
)


def test_RealESRGAN_x4plus_anime_6B(snapshot):
Expand All @@ -74,6 +109,11 @@ def test_RealESRGAN_x4plus_anime_6B(snapshot):
model = ModelLoader().load_from_file(file.path)
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, RRDBNet)
assert_image_inference(
file,
model,
[TestImage.SR_16, TestImage.SR_32, TestImage.SR_64],
)


def test_RealESRNet_x4plus(snapshot):
Expand All @@ -83,3 +123,8 @@ def test_RealESRNet_x4plus(snapshot):
model = ModelLoader().load_from_file(file.path)
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, RRDBNet)
assert_image_inference(
file,
model,
[TestImage.SR_16, TestImage.SR_32, TestImage.SR_64],
)
7 changes: 6 additions & 1 deletion tests/test_HAT.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from spandrel import ModelLoader
from spandrel.architectures.HAT import HAT

from .util import ModelFile, disallowed_props
from .util import ModelFile, TestImage, assert_image_inference, disallowed_props


def test_HAT_community1(snapshot):
Expand All @@ -11,6 +11,11 @@ def test_HAT_community1(snapshot):
model = ModelLoader().load_from_file(file.path)
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, HAT)
assert_image_inference(
file,
model,
[TestImage.SR_16, TestImage.SR_32, TestImage.SR_64],
)


# TODO: We don't support HAT-S models yet
Expand Down
12 changes: 11 additions & 1 deletion tests/test_OmniSR.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from spandrel import ModelLoader
from spandrel.architectures.OmniSR import OmniSR

from .util import ModelFile, disallowed_props
from .util import ModelFile, TestImage, assert_image_inference, disallowed_props


def test_OmniSR_community1(snapshot):
Expand All @@ -11,6 +11,11 @@ def test_OmniSR_community1(snapshot):
model = ModelLoader().load_from_file(file.path)
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, OmniSR)
assert_image_inference(
file,
model,
[TestImage.SR_16, TestImage.SR_32, TestImage.SR_64],
)


def test_OmniSR_community2(snapshot):
Expand All @@ -20,3 +25,8 @@ def test_OmniSR_community2(snapshot):
model = ModelLoader().load_from_file(file.path)
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, OmniSR)
assert_image_inference(
file,
model,
[TestImage.SR_16, TestImage.SR_32, TestImage.SR_64],
)
12 changes: 11 additions & 1 deletion tests/test_SwiftSRGAN.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from spandrel import ModelLoader
from spandrel.architectures.SwiftSRGAN import SwiftSRGAN

from .util import ModelFile, disallowed_props
from .util import ModelFile, TestImage, assert_image_inference, disallowed_props


def test_SwiftSRGan_2x(snapshot):
Expand All @@ -11,6 +11,11 @@ def test_SwiftSRGan_2x(snapshot):
model = ModelLoader().load_from_file(file.path)
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, SwiftSRGAN)
assert_image_inference(
file,
model,
[TestImage.SR_16, TestImage.SR_32, TestImage.SR_64],
)


def test_SwiftSRGan_4x(snapshot):
Expand All @@ -20,3 +25,8 @@ def test_SwiftSRGan_4x(snapshot):
model = ModelLoader().load_from_file(file.path)
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, SwiftSRGAN)
assert_image_inference(
file,
model,
[TestImage.SR_16, TestImage.SR_32, TestImage.SR_64],
)
7 changes: 6 additions & 1 deletion tests/test_Swin2SR.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from spandrel import ModelLoader
from spandrel.architectures.Swin2SR import Swin2SR

from .util import ModelFile, disallowed_props
from .util import ModelFile, TestImage, assert_image_inference, disallowed_props


def test_Swin2SR_4x(snapshot):
Expand All @@ -11,3 +11,8 @@ def test_Swin2SR_4x(snapshot):
model = ModelLoader().load_from_file(file.path)
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, Swin2SR)
assert_image_inference(
file,
model,
[TestImage.SR_16, TestImage.SR_32, TestImage.SR_64],
)
22 changes: 21 additions & 1 deletion tests/test_SwinIR.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from spandrel import ModelLoader
from spandrel.architectures.SwinIR import SwinIR

from .util import ModelFile, disallowed_props
from .util import ModelFile, TestImage, assert_image_inference, disallowed_props


def test_SwinIR_M_s64w8_2x(snapshot):
Expand All @@ -11,6 +11,11 @@ def test_SwinIR_M_s64w8_2x(snapshot):
model = ModelLoader().load_from_file(file.path)
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, SwinIR)
assert_image_inference(
file,
model,
[TestImage.SR_16, TestImage.SR_32, TestImage.SR_64],
)


def test_SwinIR_M_s48w8_4x(snapshot):
Expand All @@ -20,6 +25,11 @@ def test_SwinIR_M_s48w8_4x(snapshot):
model = ModelLoader().load_from_file(file.path)
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, SwinIR)
assert_image_inference(
file,
model,
[TestImage.SR_16, TestImage.SR_32, TestImage.SR_64],
)


def test_SwinIR_S_2x(snapshot):
Expand All @@ -29,6 +39,11 @@ def test_SwinIR_S_2x(snapshot):
model = ModelLoader().load_from_file(file.path)
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, SwinIR)
assert_image_inference(
file,
model,
[TestImage.SR_16, TestImage.SR_32, TestImage.SR_64],
)


def test_SwinIR_L_4x(snapshot):
Expand All @@ -38,3 +53,8 @@ def test_SwinIR_L_4x(snapshot):
model = ModelLoader().load_from_file(file.path)
assert model == snapshot(exclude=disallowed_props)
assert isinstance(model.model, SwinIR)
assert_image_inference(
file,
model,
[TestImage.SR_16, TestImage.SR_32, TestImage.SR_64],
)
Loading