-
Notifications
You must be signed in to change notification settings - Fork 57
/
benchmark_aflw2000.py
executable file
·143 lines (111 loc) · 4.19 KB
/
benchmark_aflw2000.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
"""
This evaluation script follows 3DDFA and 3DDFA_V2
https://github.com/cleardusk/3DDFA
https://github.com/cleardusk/3DDFA_V2
"""
import os.path as osp
import numpy as np
from math import sqrt
from utils.io import _load
d = './aflw2000_data/eval'
yaws_list = _load(osp.join(d, 'AFLW2000-3D.pose.npy'))
# origin
pts68_all_ori = _load(osp.join(d, 'AFLW2000-3D.pts68.npy'))
# reannonated
pts68_all_re = _load(osp.join(d, 'AFLW2000-3D-Reannotated.pts68.npy'))
roi_boxs = _load(osp.join(d, 'AFLW2000-3D_crop.roi_box.npy'))
def ana(nme_list):
yaw_list_abs = np.abs(yaws_list)
ind_yaw_1 = yaw_list_abs <= 30
ind_yaw_2 = np.bitwise_and(yaw_list_abs > 30, yaw_list_abs <= 60)
ind_yaw_3 = yaw_list_abs > 60
nme_1 = nme_list[ind_yaw_1]
nme_2 = nme_list[ind_yaw_2]
nme_3 = nme_list[ind_yaw_3]
mean_nme_1 = np.mean(nme_1) * 100
mean_nme_2 = np.mean(nme_2) * 100
mean_nme_3 = np.mean(nme_3) * 100
std_nme_1 = np.std(nme_1) * 100
std_nme_2 = np.std(nme_2) * 100
std_nme_3 = np.std(nme_3) * 100
mean_all = [mean_nme_1, mean_nme_2, mean_nme_3]
mean = np.mean(mean_all)
std = np.std(mean_all)
s1 = '[ 0, 30]\tMean: \x1b[32m{:.3f}\x1b[0m, Std: {:.3f}'.format(mean_nme_1, std_nme_1)
s2 = '[30, 60]\tMean: \x1b[32m{:.3f}\x1b[0m, Std: {:.3f}'.format(mean_nme_2, std_nme_2)
s3 = '[60, 90]\tMean: \x1b[32m{:.3f}\x1b[0m, Std: {:.3f}'.format(mean_nme_3, std_nme_3)
s5 = '[ 0, 90]\tMean: \x1b[31m{:.3f}\x1b[0m, Std: \x1b[31m{:.3f}\x1b[0m'.format(mean, std)
s = '\n'.join([s1, s2, s3, s5])
print(s)
return mean_nme_1, mean_nme_2, mean_nme_3, mean, std
def ana_msg(nme_list):
leng = nme_list.shape[0]
yaw_list_abs = np.abs(yaws_list)[:leng]
ind_yaw_1 = yaw_list_abs <= 30
ind_yaw_2 = np.bitwise_and(yaw_list_abs > 30, yaw_list_abs <= 60)
ind_yaw_3 = yaw_list_abs > 60
nme_1 = nme_list[ind_yaw_1]
nme_2 = nme_list[ind_yaw_2]
nme_3 = nme_list[ind_yaw_3]
mean_nme_1 = np.mean(nme_1) * 100
mean_nme_2 = np.mean(nme_2) * 100
mean_nme_3 = np.mean(nme_3) * 100
std_nme_1 = np.std(nme_1) * 100
std_nme_2 = np.std(nme_2) * 100
std_nme_3 = np.std(nme_3) * 100
mean_all = [mean_nme_1, mean_nme_2, mean_nme_3]
mean = np.mean(mean_all)
std = np.std(mean_all)
s0 = '\nFacial Alignment on AFLW2000-3D (NME):'
s1 = '[ 0, 30]\tMean: {:.3f}, Std: {:.3f}'.format(mean_nme_1, std_nme_1)
s2 = '[30, 60]\tMean: {:.3f}, Std: {:.3f}'.format(mean_nme_2, std_nme_2)
s3 = '[60, 90]\tMean: {:.3f}, Std: {:.3f}'.format(mean_nme_3, std_nme_3)
s4 = '[ 0, 90]\tMean: {:.3f}, Std: {:.3f}'.format(mean, std)
s = '\n'.join([s0, s1, s2, s3, s4])
return s
def convert_to_ori(lms, i):
std_size = 120
sx, sy, ex, ey = roi_boxs[i]
scale_x = (ex - sx) / std_size
scale_y = (ey - sy) / std_size
lms[0, :] = lms[0, :] * scale_x + sx
lms[1, :] = lms[1, :] * scale_y + sy
return lms
def convert_to_crop(lms, i):
std_size = 120
sx, sy, ex, ey = roi_boxs[i]
scale_x = (ex - sx) / std_size
scale_y = (ey - sy) / std_size
lms[0, :] = (lms[0, :] - sx)/ scale_x
lms[1, :] = (lms[1, :] - sy)/ scale_y
return lms
def calc_nme(pts68_fit_all, option='ori'):
if option == 'ori':
pts68_all = pts68_all_ori
elif option == 're':
pts68_all = pts68_all_re
std_size = 120
nme_list = []
length_list = []
for i in range(len(roi_boxs)):
pts68_fit = pts68_fit_all[i]
pts68_gt = pts68_all[i]
sx, sy, ex, ey = roi_boxs[i]
scale_x = (ex - sx) / std_size
scale_y = (ey - sy) / std_size
pts68_fit[0, :] = pts68_fit[0, :] * scale_x + sx
pts68_fit[1, :] = pts68_fit[1, :] * scale_y + sy
# build bbox
minx, maxx = np.min(pts68_gt[0, :]), np.max(pts68_gt[0, :])
miny, maxy = np.min(pts68_gt[1, :]), np.max(pts68_gt[1, :])
llength = sqrt((maxx - minx) * (maxy - miny))
length_list.append(llength)
dis = pts68_fit - pts68_gt[:2, :]
dis = np.sqrt(np.sum(np.power(dis, 2), 0))
dis = np.mean(dis)
nme = dis / llength
nme_list.append(nme)
nme_list = np.array(nme_list, dtype=np.float32)
return nme_list
if __name__ == '__main__':
pass