|
|
|
@ -1,8 +1,10 @@
|
|
|
|
|
import torch |
|
|
|
|
import torchvision |
|
|
|
|
import math |
|
|
|
|
import struct |
|
|
|
|
import comfy.checkpoint_pickle |
|
|
|
|
import safetensors.torch |
|
|
|
|
from PIL import Image |
|
|
|
|
|
|
|
|
|
def load_torch_file(ckpt, safe_load=False, device=None): |
|
|
|
|
if device is None: |
|
|
|
@ -346,6 +348,13 @@ def bislerp(samples, width, height):
|
|
|
|
|
result = result.reshape(n, h_new, w_new, c).movedim(-1, 1) |
|
|
|
|
return result |
|
|
|
|
|
|
|
|
|
def lanczos(samples, width, height): |
|
|
|
|
images = [torchvision.transforms.functional.to_pil_image(image) for image in samples] |
|
|
|
|
images = [image.resize((width, height), resample=Image.Resampling.LANCZOS) for image in images] |
|
|
|
|
images = [torchvision.transforms.functional.to_tensor(image) for image in images] |
|
|
|
|
result = torch.stack(images) |
|
|
|
|
return result |
|
|
|
|
|
|
|
|
|
def common_upscale(samples, width, height, upscale_method, crop): |
|
|
|
|
if crop == "center": |
|
|
|
|
old_width = samples.shape[3] |
|
|
|
@ -364,6 +373,8 @@ def common_upscale(samples, width, height, upscale_method, crop):
|
|
|
|
|
|
|
|
|
|
if upscale_method == "bislerp": |
|
|
|
|
return bislerp(s, width, height) |
|
|
|
|
elif upscale_method == "lanczos": |
|
|
|
|
return lanczos(s, width, height) |
|
|
|
|
else: |
|
|
|
|
return torch.nn.functional.interpolate(s, size=(height, width), mode=upscale_method) |
|
|
|
|
|
|
|
|
|