From 7c9a92f552552cb51c9230d80d05ee42ebd8be90 Mon Sep 17 00:00:00 2001 From: comfyanonymous Date: Tue, 19 Sep 2023 13:12:47 -0400 Subject: [PATCH] Don't depend on torchvision. --- comfy/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/comfy/utils.py b/comfy/utils.py index 4e08bcb8..7843b58c 100644 --- a/comfy/utils.py +++ b/comfy/utils.py @@ -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