Skip to content

Commit aab41a9

Browse files
fix(lanczos): correct dimension transposition for single-channel tensors (Comfy-Org#12679)
1 parent 4259a0c commit aab41a9

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

comfy/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,10 +1019,11 @@ def generate_bilinear_data(length_old, length_new, device):
10191019

10201020
def lanczos(samples, width, height):
10211021
#the below API is strict and expects grayscale to be squeezed
1022-
samples = samples.squeeze(1) if samples.shape[1] == 1 else samples.movedim(1, -1)
1022+
if samples.ndim == 4:
1023+
samples = samples.squeeze(1) if samples.shape[1] == 1 else samples.movedim(1, -1)
10231024
images = [Image.fromarray(np.clip(255. * image.cpu().numpy(), 0, 255).astype(np.uint8)) for image in samples]
10241025
images = [image.resize((width, height), resample=Image.Resampling.LANCZOS) for image in images]
1025-
images = [torch.from_numpy(np.array(image).astype(np.float32) / 255.0).movedim(-1, 0) for image in images]
1026+
images = [torch.from_numpy(t).movedim(-1, 0) if (t := np.array(image).astype(np.float32) / 255.0).ndim == 3 else torch.from_numpy(t) for image in images]
10261027
result = torch.stack(images)
10271028
return result.to(samples.device, samples.dtype)
10281029

0 commit comments

Comments
 (0)