Imag / src /videogen_hub /utils /__init__.py
Baraaqasem's picture
Upload 49 files
413d4d0 verified
raw
history blame contribute delete
524 Bytes
import torch
from torchvision import transforms
from PIL import Image
def images_to_tensor(image_list):
"""
Parse a list of PIL images and convert them to a PyTorch tensor in shape (T, C, H, W).
"""
transform = transforms.ToTensor()
# Convert each PIL image to tensor and store in a list
tensor_list = [transform(img) for img in image_list]
# Stack the list of tensors along a new dimension to create the final tensor
tensor = torch.stack(tensor_list, dim=0)
return tensor