-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataset.py
More file actions
28 lines (20 loc) · 679 Bytes
/
dataset.py
File metadata and controls
28 lines (20 loc) · 679 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
import os
import pandas as pd
import torch
from PIL import Image
def loader(image_path):
with open(image_path, 'rb') as f:
image = Image.open(f).convert('RGB')
return image
class LPCVDataset(torch.utils.data.Dataset):
def __init__(self, root, csv_file, transforms):
_df = pd.read_csv(csv_file)
self.images = [os.path.join(root, x) for x in _df['images']]
self.targets = _df['targets']
self.transforms = transforms
def __len__(self):
return len(self.images)
def __getitem__(self, idx):
img = self.transforms(loader(self.images[idx]))
target = self.targets[idx]
return img, target