forked from thangvubk/SRCNN_Pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_loader.py
35 lines (25 loc) · 943 Bytes
/
data_loader.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
import torch
from torch.utils.data import Dataset, DataLoader
from utils import make_input
class SRCNN_dataset(Dataset):
"""
Create dataset for SRCNN
Args:
config: config to get dataset from utils
transfrom: optional transform to be applied on a sample
"""
def __init__(self, config):
self.inputs, self.labels = make_input(config)
def __len__(self):
return self.inputs.shape[0]
def __getitem__(self, idx):
input_sample = self.inputs[idx]
label_sample = self.labels[idx]
# transpose channel because
# numpy image H x W x C
# torch image C x H x W
input_sample = input_sample.transpose(2, 0, 1)
label_sample = label_sample.transpose(2, 0, 1)
# Wrap with tensor
input_sample, label_sample = torch.Tensor(input_sample), torch.Tensor(label_sample)
return input_sample, label_sample