Skip to content

Commit

Permalink
Be more clear about Spandrel model nomenclature
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Dec 30, 2023
1 parent c0ca634 commit 777af66
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions extensions-builtin/SwinIR/scripts/swinir_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,18 @@ def load_model(self, path, scale=4):
else:
filename = path

model = modelloader.load_spandrel_model(
model_descriptor = modelloader.load_spandrel_model(
filename,
device=self._get_device(),
dtype=devices.dtype,
expected_architecture="SwinIR",
)
if getattr(opts, 'SWIN_torch_compile', False):
try:
model = torch.compile(model)
model_descriptor.model.compile()
except Exception:
logger.warning("Failed to compile SwinIR model, fallback to JIT", exc_info=True)
return model
return model_descriptor

def _get_device(self):
return devices.get_device_for('swinir')
Expand Down
10 changes: 6 additions & 4 deletions modules/gfpgan_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import logging
import os

import torch

from modules import (
devices,
errors,
Expand All @@ -25,7 +27,7 @@ def name(self):
def get_device(self):
return devices.device_gfpgan

def load_net(self) -> None:
def load_net(self) -> torch.Module:
for model_path in modelloader.load_models(
model_path=self.model_path,
model_url=model_url,
Expand All @@ -34,13 +36,13 @@ def load_net(self) -> None:
ext_filter=['.pth'],
):
if 'GFPGAN' in os.path.basename(model_path):
net = modelloader.load_spandrel_model(
model = modelloader.load_spandrel_model(
model_path,
device=self.get_device(),
expected_architecture='GFPGAN',
).model
net.different_w = True # see https://github.com/chaiNNer-org/spandrel/pull/81
return net
model.different_w = True # see https://github.com/chaiNNer-org/spandrel/pull/81
return model
raise ValueError("No GFPGAN model found")

def restore(self, np_image):
Expand Down
2 changes: 1 addition & 1 deletion modules/modelloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def load_spandrel_model(
*,
device: str | torch.device | None,
half: bool = False,
dtype: str | None = None,
dtype: str | torch.dtype | None = None,
expected_architecture: str | None = None,
) -> spandrel.ModelDescriptor:
import spandrel
Expand Down
4 changes: 2 additions & 2 deletions modules/realesrgan_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ def do_upscale(self, img, path):
errors.report(f"Unable to load RealESRGAN model {path}", exc_info=True)
return img

mod = modelloader.load_spandrel_model(
model_descriptor = modelloader.load_spandrel_model(
info.local_data_path,
device=self.device,
half=(not cmd_opts.no_half and not cmd_opts.upcast_sampling),
expected_architecture="ESRGAN", # "RealESRGAN" isn't a specific thing for Spandrel
)
return upscale_with_model(
mod,
model_descriptor,
img,
tile_size=opts.ESRGAN_tile,
tile_overlap=opts.ESRGAN_tile_overlap,
Expand Down
2 changes: 1 addition & 1 deletion modules/upscaler_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import tqdm
from PIL import Image

from modules import devices, images
from modules import images

logger = logging.getLogger(__name__)

Expand Down

0 comments on commit 777af66

Please sign in to comment.