forked from cleardusk/3DDFA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_aflw2000.py
107 lines (80 loc) · 3.02 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
#!/usr/bin/env python3
# coding: utf-8
import os.path as osp
import numpy as np
from math import sqrt
from utils.io import _load
d = 'test.configs'
yaws_list = _load(osp.join(d, 'AFLW2000-3D.pose.npy'))
# pts21 = _load(osp.join(d, 'AFLW2000-3D.pts21.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
# mean_nme_all = np.mean(nme_list) * 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
# std_nme_all = np.std(nme_list) * 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)
# s4 = '[ 0, 90]\tMean: \x1b[31m{:.3f}\x1b[0m, Std: {:.3f}'.format(mean_nme_all, std_nme_all)
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 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 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 = []
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))
#
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
def main():
pass
if __name__ == '__main__':
main()