-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathread_data.py
More file actions
44 lines (29 loc) · 927 Bytes
/
read_data.py
File metadata and controls
44 lines (29 loc) · 927 Bytes
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
33
34
35
36
37
38
39
40
41
42
43
import torch
import torch.utils.data as data
import torchvision.transforms as transforms
from PIL import Image
import scipy
import numpy as np
import time
import os
def img_loader(path):
return Image.open(path).convert('RGB')
def list_reader(flist):
imlist = []
with open(flist, 'r') as rf:
for line in rf.readlines():
impath, imlabel = line.split()
imlist.append((impath, int(imlabel)))
return imlist
class MyDataset(data.dataset.Dataset):
def __init__(self, flist, transform=None):
self.imlist = list_reader(flist)
self.transform = transform
def __getitem__(self, idx):
impath, target = self.imlist[idx]
img = img_loader(os.path.join('/data/val', impath))
if self.transform is not None:
img = self.transform(img)
return img, target
def __len__(self):
return len(self.imlist)