forked from aliayub7/EEC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_previous_data.py
More file actions
62 lines (55 loc) · 1.8 KB
/
get_previous_data.py
File metadata and controls
62 lines (55 loc) · 1.8 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 3 2019
@author: Ali Ayub
"""
import numpy as np
from copy import deepcopy
import pickle
import math
import random
from multiprocessing import Pool
import os
from PIL import Image
os.environ["OMP_NUM_THREADS"] = "1"
def get_images(path):
resolution = 32
train_images = []
for file in os.listdir(path):
file_path = os.path.join(path,file)
img = Image.open(file_path)
#img = img.resize((32,32))
img = img.resize((resolution,resolution))
np_img = np.asarray(img)
if len(np_img.shape)==3:
train_images.append(np.asarray(img))
return train_images
class getPreviousData:
def __init__(self,path_to_train,total_classes,seed):
self.path_to_train = path_to_train
self.total_classes = total_classes
self.seed = seed
np.random.seed(seed)
random.seed(seed)
def initialize(self,path_to_train,total_classes,seed):
self.path_to_train = path_to_train
self.orig_lab = [i for i in range(0,full_classes)]
self.total_classes = total_classes
self.seed = seed
np.random.seed(seed)
random.seed(seed)
def previous_data(self):
classes = [i for i in range(self.total_classes)]
print ('classes to be loaded',classes)
train_images = []
train_labels = []
pack = []
for i in range(0,len(classes)):
pack.append(os.path.join(self.path_to_train,str(classes[i])))
my_pool = Pool(self.total_classes)
return_pack = my_pool.map(get_images,pack)
my_pool.close()
for i in range(0,len(classes)):
train_images.extend(return_pack[i])
train_labels.extend([i for x in range(0,len(return_pack[i]))])
return train_images,train_labels