-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
dataset.py
executable file
·58 lines (40 loc) · 1.83 KB
/
dataset.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
class dataset_class:
def __init__(self, required_no):
#Dataset Name
self.dir = ("images/ORL")
self.images_name_for_train = []
self.target_name_as_array= []
self.target_name_as_set = {}
self.y_for_train = []
self.no_of_elements_for_train = []
self.images_name_for_test = []
self.y_for_test = []
self.no_of_elements_for_test = []
per_no = 0
for name in os.listdir(self.dir):
dir_path = os.path.join(self.dir, name)
if os.path.isdir(dir_path):
if len(os.listdir(dir_path)) >= required_no:
i = 0
for img_name in os.listdir(dir_path):
img_path = os.path.join(dir_path, img_name)
if i < required_no:
self.images_name_for_train += [img_path]
self.y_for_train += [per_no]
if len(self.no_of_elements_for_train) > per_no:
self.no_of_elements_for_train[per_no] += 1
else:
self.no_of_elements_for_train += [1]
if i is 0:
self.target_name_as_array += [name]
self.target_name_as_set[per_no] = name
else:
self.images_name_for_test += [img_path]
self.y_for_test += [per_no]
if len(self.no_of_elements_for_test) > per_no:
self.no_of_elements_for_test[per_no] += 1
else:
self.no_of_elements_for_test += [1]
i += 1
per_no += 1