-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOurDataset.py
32 lines (26 loc) · 1.05 KB
/
OurDataset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from PIL import Image
from torch.utils.data import Dataset
import pickle
import os
import torch
from typing import Tuple, Optional, Union
class OurDataset(Dataset):
def __init__(self, pkl_path, transform = None):
dataset_info = pickle.load(open(pkl_path, 'rb+'))
self.transform=transform
self.rgb_image_name = dataset_info.image_rgb_name
self.lunkuo_image_name = dataset_info.image_lunkuo_name
def __getitem__(self, index)-> Tuple[torch.Tensor, ...]:
seed = torch.randint(0, 100000, (1,)).item()
rgb_image= self.rgb_image_name[index]
lunkuo_image= self.lunkuo_image_name[index]
rgb_img_pil = Image.open(rgb_image)
lunkuo_img_pil = Image.open(lunkuo_image).convert('RGB')
if self.transform is not None:
torch.manual_seed(seed)
rgb_image = self.transform(rgb_img_pil)
torch.manual_seed(seed)
lunkuo_image = self.transform(lunkuo_img_pil)
return rgb_image,lunkuo_image
def __len__(self):
return len(self.rgb_image_name)