Don't depend on torchvision.

This commit is contained in:
comfyanonymous 2023-09-19 13:12:47 -04:00
parent 2b6b178173
commit 7c9a92f552

View File

@ -1,9 +1,9 @@
import torch
import torchvision
import math
import struct
import comfy.checkpoint_pickle
import safetensors.torch
import numpy as np
from PIL import Image
def load_torch_file(ckpt, safe_load=False, device=None):
@ -349,9 +349,9 @@ def bislerp(samples, width, height):
return result
def lanczos(samples, width, height):
images = [torchvision.transforms.functional.to_pil_image(image) for image in samples]
images = [Image.fromarray(np.clip(255. * image.movedim(0, -1).cpu().numpy(), 0, 255).astype(np.uint8)) 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]
images = [torch.from_numpy(np.array(image).astype(np.float32) / 255.0).movedim(-1, 0) for image in images]
result = torch.stack(images)
return result