-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataset_fr.py
31 lines (25 loc) · 1.11 KB
/
dataset_fr.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
from torchvision import transforms
from torch.utils.data import DataLoader, Dataset
import os
from PIL import Image
class datas(Dataset):
def __init__(self, array_list,base_path):
super().__init__()
self.array_list=array_list
self.base_path=base_path
def __len__(self):
return len(self.array_list)
def __getitem__(self,idx):
anchor_path=self.array_list[idx][0]
contrast_path=self.array_list[idx][1]
target=self.array_list[idx][2]
trans=transforms.Compose([transforms.Resize((105,105)),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406],
[0.229, 0.224, 0.225]),
])
anchor_img=Image.open(os.path.join(self.base_path,anchor_path))
contrast_img=Image.open(os.path.join(self.base_path,contrast_path))
anchor_tensor=trans(anchor_img)
contrast_tensor=trans(contrast_img)
return anchor_tensor, contrast_tensor,target