-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_loader.py
38 lines (28 loc) · 990 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
33
34
35
36
37
import cv2
import numpy as np
import pickle
import os
import glob
save_path = 'data/'
def createClassDictionary():
class_dictn = {}
for index, class_label in enumerate(os.listdir('data/training/')):
class_dictn[class_label] = index
return class_dictn
def make_dataset(dataType='train'):
X = []
y = []
dataFolder = 'data/{}ing/*/*.png'.format(dataType)
class_dictn = createClassDictionary()
for each_file in glob.iglob('data/training/*/*.png'):
X_current, y_current = cv2.imread(each_file), each_file.split('/')[2]
X.append(X_current)
label = class_dictn[y_current]
y.append(label)
return np.array(X), np.array(y)
def load_data():
with open(os.path.join(save_path, "train.pickle"), "rb") as f:
(X_train, y_train) = pickle.load(f)
with open(os.path.join(save_path, "val.pickle"), "rb") as f:
(X_test, y_test) = pickle.load(f)
return X_train/255, y_train, X_test/255, y_test