refactor: integrate sharpfin for high-quality image resize

Vendor sharpfin library (Apache 2.0) and add centralized wrapper
module (images_sharpfin.py) replacing torchvision tensor/PIL
conversion and resize operations throughout the codebase.

- Add modules/sharpfin/ vendored library with MKS2021, Lanczos3,
  Mitchell, Catmull-Rom kernels and optional Triton sparse acceleration
- Add modules/images_sharpfin.py wrapper with to_tensor(), to_pil(),
  pil_to_tensor(), normalize(), resize(), resize_tensor()
- Add resize_quality and resize_linearize_srgb settings
- Add MKS2021 and Lanczos3 upscaler entries
- Replace torchvision.transforms.functional imports across 18 files
- to_pil() auto-detects HWC/BHWC layout, adds .round() before uint8
- Sparse Triton path falls back to dense GPU on compilation failure
- Mixed-axis resize splits into two single-axis scale() calls
- Masks and non-sRGB data always use linearize=False
This commit is contained in:
CalamitousFelicitousness
2026-02-10 00:13:35 +00:00
committed by vladmandic
parent 2c4d0751d9
commit 76aa949a26
30 changed files with 2878 additions and 78 deletions
+2 -2
View File
@@ -70,7 +70,7 @@ def setup_model(dirname):
self.face_helper.face_parse.to(device)
def restore(self, np_image, p=None, w=None): # pylint: disable=unused-argument
from torchvision.transforms.functional import normalize
from modules import images_sharpfin
from basicsr.utils import img2tensor, tensor2img
np_image = np_image[:, :, ::-1]
original_resolution = np_image.shape[0:2]
@@ -84,7 +84,7 @@ def setup_model(dirname):
self.face_helper.align_warp_face()
for cropped_face in self.face_helper.cropped_faces:
cropped_face_t = img2tensor(cropped_face / 255., bgr2rgb=True, float32=True)
normalize(cropped_face_t, (0.5, 0.5, 0.5), (0.5, 0.5, 0.5), inplace=True)
images_sharpfin.normalize(cropped_face_t, (0.5, 0.5, 0.5), (0.5, 0.5, 0.5), inplace=True)
cropped_face_t = cropped_face_t.unsqueeze(0).to(devices.device)
try:
with devices.inference_context():