forked from vinayhanumaiah/ghc-face-detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwider_extract.py
76 lines (57 loc) · 1.99 KB
/
wider_extract.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
import numpy as np
path = "dataset/"
annotation_file = "wider_face_train_bbx_gt.txt"
relative_img_path = "dataset/WIDER_train/images/"
face_bb = {}
with open(path + annotation_file) as f:
l_filename = True
l_bb_cnt = False
l_bb = True
l_bb =0
f_name = " "
bb = []
bb_cnt = -1
for line in f:
if(bb_cnt == 0):
l_bb = False
l_filename = True
bb_cnt = -1
if(l_filename):
f_name = line[:-1]
l_bb_cnt = True
l_filename = False
# print ("f_name : ", f_name)
continue
if(l_bb_cnt):
bb_cnt = int(line)
bb_ref_cnt = bb_cnt
l_bb = True
l_bb_cnt = False
# print ("bb_cnt : ", bb_cnt)
continue
if(l_bb):
if(bb_ref_cnt == bb_cnt):
bb = [relative_img_path + f_name, relative_img_path + f_name, [300, 300]]
# bb.append(bb_ref_cnt)
if( bb_cnt > 0):
bb_cnt -= 1
bb_each = []
bb_info = line.split(" ") # x1, y1, w, h, blur, expression, illumination, invalid, occlusion, pose
isValid = bb_info[7] # 0, 1 using only 0
isOccluded = bb_info[8] # 0,1,2 use only 0,1
isBlur = bb_info[4] # 0,1,2 use only 0,1
x1 = int(bb_info[0])
x2 = x1 + int(bb_info[2])
y1 = int(bb_info[1])
y2 = y1 + int(bb_info[3])
bb_each.append([x1,x2,y1,y2])
class_id = 1 # face
bb_each.append(class_id)
if isValid==0 and isOccluded!=2 and isBlur!=2:
bb.append(bb_each)
# print ("bb: " , bb)
# print ("line : ", line)
if(bb_cnt == 0):
face_bb[f_name] = bb
#print (face_bb)
np.save('wider_test.npy', face_bb)