-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathdataset.py
More file actions
27 lines (24 loc) · 764 Bytes
/
Copy pathdataset.py
File metadata and controls
27 lines (24 loc) · 764 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
import numpy as np
import os
from PIL import Image
from torch.utils.data import Dataset
import skimage.io as io
import glob
import numpy as np
import random
import torch
class BatchData(Dataset):
def __init__(self, images, labels, input_transform=None):
self.images = images
self.labels = labels
self.input_transform = input_transform
def __getitem__(self, index):
image = self.images[index]
image = Image.fromarray(np.uint8(image))
label = self.labels[index]
if self.input_transform is not None:
image = self.input_transform(image)
label = torch.LongTensor([label])
return image, label
def __len__(self):
return len(self.images)