Hello. I wrote a function to load and pre-process images as below. The function loads a single image and apply pre-processing one by one. However, it seems so slow…
If possible, I wanna apply pre-processing on multiple images at the same time not one by one.
Anybody knows how?
def read_2D(self, file_path):

    image_names = os.listdir(file_path) #get file names
    images = torch.zeros(1, 3, 224, 224)
    trans = transforms.Compose([
        transforms.Resize(size=(224, 224)),
        transforms.ToTensor(),
        transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),
    ])
    
    for i in range(len(image_names)): 
        img = Image.open(file_path + image_names[i]).convert('RGB')
        img = trans(img).view(1, 3, 224, 224)
        images = torch.cat((images, img), 0)


    images = images[:-1]

    return image_names, images ```