import os from PIL import Image from torchvision import transforms src_dir = "other_exps" tar_dir = "1024_interp" image_dir = os.listdir(src_dir) for image in image_dir: if 'txt' not in image: img = Image.open(os.path.join(src_dir, image)) T = transforms.Compose([ transforms.Resize(576), transforms.CenterCrop((576, 1024)) ]) img = T(img) img.save(os.path.join(tar_dir, image))