-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_transformed_data.py
More file actions
37 lines (33 loc) · 1.12 KB
/
get_transformed_data.py
File metadata and controls
37 lines (33 loc) · 1.12 KB
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
import os
import sys
import pickle
import numpy as np
from skimage import io
import matplotlib.pyplot as plt
import numpy
import torch
from torch.utils.data import Dataset
class getTransformedData(Dataset):
"""transformed dataset for incremental learning
"""
def __init__(self, images, labels, transform=None,seed=7):
np.random.seed(seed)
torch.manual_seed(seed)
self.train_images = images
self.labels = labels
self.train_images = np.array(self.train_images)
self.labels = np.array(self.labels)
#if transform is given, we transoform data using
self.transform = transform
def __len__(self):
return len(self.labels)
def __getitem__(self, index):
label = self.labels[index]
#r = self.train_images[index, :1024].reshape(32, 32)
#g = self.train_images[index, 1024:2048].reshape(32, 32)
#b = self.train_images[index, 2048:].reshape(32, 32)
#image = numpy.dstack((r, g, b))
image = self.train_images[index]
if self.transform:
image = self.transform(np.uint8(image))
return image, label