|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| """
|
| Created in September 2022
|
| @author: fabrizio.guillaro
|
| """
|
|
|
| from torch.utils.data import Dataset
|
| import random
|
| import numpy as np
|
| import torch
|
| from PIL import Image
|
|
|
|
|
| class TestDataset(Dataset):
|
| def __init__(self, list_img=None):
|
| self.img_list = list_img
|
|
|
| def shuffle(self):
|
| random.shuffle(self.img_list)
|
|
|
| def __len__(self):
|
| return len(self.img_list)
|
|
|
| def __getitem__(self, index):
|
| assert self.img_list
|
| assert 0 <= index < len(self.img_list), f"Index {index} is not available!"
|
| rgb_path = self.img_list[index]
|
| img_RGB = np.array(Image.open(rgb_path).convert("RGB"))
|
| return torch.tensor(img_RGB.transpose(2, 0, 1), dtype=torch.float) / 256.0, rgb_path
|
|
|
| def get_filename(self, index):
|
| item = self.img_list[index]
|
| if isinstance(item, list):
|
| return item[0]
|
| else:
|
| return item |