-
Notifications
You must be signed in to change notification settings - Fork 1
/
dataload_test.py
267 lines (247 loc) · 10.9 KB
/
dataload_test.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
"""
1 1 3
[0,0,0,0,0 ,0,0,0,0,0, 0,0,0,1 ,0,0,0,0,1 ,0,0,0,0,1]
[0,0,0,0,0 ,0,0,0,0,0, 0,0,0,1 ,0,0,0,0,1 ,0,0,0,1,0]
[0,0,0,0,0 ,0,0,0,0,0, 0,0,0,1 ,0,0,0,0,1 ,0,0,1,0,0]
2 1 1
[0,0,0,0,0 ,0,0,0,0,0, 0,0,1,0 ,0,0,0,0,1 ,0,0,0,0,1]
3 1 1
[0,0,0,0,0 ,0,0,0,0,0, 0,1,0,0 ,0,0,0,0,1 ,0,0,0,0,1]
2 2 3
[0,0,0,0,0 ,0,0,0,0,0, 0,0,1,0 ,0,0,0,1,0 ,0,0,0,0,1]
[0,0,0,0,0 ,0,0,0,0,0, 0,0,1,0 ,0,0,0,1,0 ,0,0,0,1,0]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,0,0,0 ,0,0,0,0,0])
images = []
labels = []
images2 = []
labels2 = []
test_images = []
test_labels = []
test_images2 = []
index1 = 0
index = 0
index2 = 0
index3 = 0
def load_file_list():
global images
global labels
print("load in!")
directory = './trainingset/train1/'
for filename in [y for y in os.listdir(directory)]:
mat = re.match("\d\d\D+",filename)
mat1 = re.match("\d1\d\D+",filename)
mat2 = re.match("1\d\d\D+",filename)
mat3 = re.match("1\d1\d",filename)
if mat or mat1 or mat2 or mat3:
images.append(directory+filename)
labels.append([0,0,0,0,0 ,0,0,0,0,0, 0,0,0,1 ,0,0,0,0,1 ,0,0,0,0,1])
print(len(images))
zipped = zip(images,labels)
random.shuffle(zipped)
images,labels = zip(*zipped);print('load down')
return len(images)
def load_file_list2():
global images2
global labels2
print("load in!")
directory = './trainingset/train10/'
for filename in [y for y in os.listdir(directory)]:
mat = re.match("\d\d\D+",filename)
mat1 = re.match("\d1\d\D+",filename)
mat2 = re.match("1\d\d\D+",filename)
mat3 = re.match("1\d1\d",filename)
if mat or mat1 or mat2 or mat3:
images2.append(directory+filename)
labels2.append([1,0,0,0,0 ,0,0,0,0,0, 0,0,0,0 ,0,0,0,0,1 ,0,0,0,0,1])
print(len(images2))
zipped = zip(images2,labels2)
random.shuffle(zipped)
images2,labels2 = zip(*zipped);print('load down')
return len(images2)
def load_test_list():
global test_images
global test_labels
directory = './testingset/test1/'
for filename in [y for y in os.listdir(directory)]:
#print("%s%s"%(directory,filename));img = cv2.imread("%s%s"%(directory,filename))
mat = re.match("\d\d\D+",filename)
mat1 = re.match("\d2\d\D+",filename)
mat2 = re.match("1\d\d\D+",filename)
mat3 = re.match("1\d1\d",filename)
if mat or mat1 or mat2 or mat3:
test_images.append(directory+filename)
test_labels.append([0,0,0,0,0 ,0,0,0,0,0, 0,0,0,1 ,0,0,0,0,1 ,0,0,0,0,1]);
#zipped = zip(test_images,test_labels)
#random.shuffle(zipped)
#test_images,test_labels = zip(*zipped);print('load down')
return len(test_images)
def load_test_list2():
global test_images2
global test_labels2
directory = './testingset/test10/'
for filename in [y for y in os.listdir(directory)]:
mat = re.match("\d\d\D+",filename)
mat1 = re.match("\d1\d\D+",filename)
mat2 = re.match("1\d\d\D+",filename)
mat3 = re.match("1\d1\d",filename)
if mat or mat1 or mat2 or mat3:
test_images2.append(directory+filename)
test_labels2.append([1,0,0,0,0 ,0,0,0,0,0, 0,0,0,0 ,0,0,0,0,1 ,0,0,0,0,1]);
#zipped = zip(test_images2,test_labels2)
#random.shuffle(zipped)
#test_images2,test_labels2 = zip(*zipped);print('load down')
return len(test_images2)
def get_batch(batch_size):
global index;global images;global labels
Max_couter = len(images)
Max_index = Max_couter//batch_size
index = index%Max_index
imgs =[];label=[]
for q in range(index*batch_size,(index+1)*batch_size):
imgs.append(cv2.imread(images[q]).reshape([3,48,48]))
label.append(labels[q])
mlabel = label&one_mlabel
clabel = label&one_clabel
index = (index+1)%Max_index
if index == 0:
zipped = zip(images,labels)
random.shuffle(zipped)
images,labels = zip(*zipped)
return imgs,label,mlabel,clabel
def get_batch2(batch_size):
global index2;global images2;global labels2
Max_couter = len(images)
Max_index = Max_couter//batch_size
index2 = index2%Max_index
imgs =[];label=[]
for q in range(index2*batch_size,(index2+1)*batch_size):
imgs.append(cv2.imread(images2[q]).reshape([3,48,48]))
label.append(labels2[q])
mlabel = label&one_mlabel
clabel = label&one_clabel
index2 = (index2+1)%Max_index
if index2 == 0:
zipped = zip(images2,labels2)
random.shuffle(zipped)
images2,labels2 = zip(*zipped)
return imgs,label,mlabel,clabel
def get_test(batch_size):
global index1;global test_images;global test_labels
Max_couter = len(test_images)
Max_index = Max_couter//batch_size
index1 = index1%Max_index
window = [x for x in range(index1*batch_size,(index1+1)*batch_size)]
imgs = [cv2.imread(test_images[q]).reshape([3,48,48]) for q in window]
label = [test_labels[q] for q in window];tm_label = label&one_mlabel
tc_label = label&one_clabel
index1 = (index1+1)%Max_index
return imgs,label,tm_label,tc_label
def get_test2(batch_size):
global index3;global test_images2;global test_labels2
Max_couter = len(test_images2)
Max_index = Max_couter//batch_size
index3 = index3%Max_index
window = [x for x in range(index3*batch_size,(index3+1)*batch_size)]
imgs = [cv2.imread(test_images2[q]).reshape([3,48,48]) for q in window]
label = [test_labels2[q] for q in window];tm_label = label&one_mlabel
tc_label = label&one_clabel
index3 = (index3+1)%Max_index
return imgs,label,tm_label,tc_label