-
Notifications
You must be signed in to change notification settings - Fork 3
/
fruit_data.py
39 lines (27 loc) · 1.08 KB
/
fruit_data.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
33
34
35
36
37
38
39
from __future__ import print_function
from PIL import Image
import os
import sys
import numpy as np
import argparse
import torch.utils.data as data
class Fruit(data.Dataset):
def __init__(self, root_dir, train=True, transform=None):
self.root_dir = os.path.abspath(root_dir)
self.transform = transform
self.train=train
if (self.train):
self.data = np.load(os.path.join(self.root_dir, "train_data.npy"))
self.labels = np.load(os.path.join(self.root_dir, "train_labels.npy"))
else:
self.data = np.load(os.path.join(self.root_dir, "validation_data.npy"))
self.labels = np.load(os.path.join(self.root_dir, "validation_labels.npy"))
self.data = self.data.transpose((0, 2, 3, 1))
def __getitem__(self, index):
img, target = self.data[index], self.labels[index]
#img = Image.fromarray(img.astype('uint8'))
if self.transform is not None:
img = self.transform(img)
return img, target
def __len__(self):
return (len(self.data))