File size: 4,104 Bytes
5ac1897
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from .metrics import *
from .evaluators import EvaluatorBase

from lib.body_models.smpl_utils.reality import eval_rot_delta as smpl_eval_rot_delta

class HSMR3DEvaluator(EvaluatorBase):

    def eval(self, **kwargs):
        # Get the predictions and ground truths.
        pd, gt = kwargs['pd'], kwargs['gt']
        v3d_pd, v3d_gt = pd['v3d_pose'], gt['v3d_pose']
        j3d_pd, j3d_gt = pd['j3d_pose'], gt['j3d_pose']

        # Compute the metrics.
        mpjpe    = eval_MPxE(j3d_pd, j3d_gt)
        pa_mpjpe = eval_PA_MPxE(j3d_pd, j3d_gt)
        mpve     = eval_MPxE(v3d_pd, v3d_gt)
        pa_mpve  = eval_PA_MPxE(v3d_pd, v3d_gt)

        # Append the results.
        self.accumulator['MPJPE'].append(mpjpe.detach().cpu())
        self.accumulator['PA-MPJPE'].append(pa_mpjpe.detach().cpu())
        self.accumulator['MPVE'].append(mpve.detach().cpu())
        self.accumulator['PA-MPVE'].append(pa_mpve.detach().cpu())



class SMPLRealityEvaluator(EvaluatorBase):

    def eval(self, **kwargs):
        # Get the predictions and ground truths.
        pd = kwargs['pd']
        body_pose = pd['body_pose']  # (..., 23, 3)

        # Compute the metrics.
        vio_d0  = smpl_eval_rot_delta(body_pose, tol_deg=0 )  # {k: (N, 3)}
        vio_d5  = smpl_eval_rot_delta(body_pose, tol_deg=5 )  # {k: (N, 3)}
        vio_d10 = smpl_eval_rot_delta(body_pose, tol_deg=10)  # {k: (N, 3)}
        vio_d20 = smpl_eval_rot_delta(body_pose, tol_deg=20)  # {k: (N, 3)}
        vio_d30 = smpl_eval_rot_delta(body_pose, tol_deg=30)  # {k: (N, 3)}

        # Append the results.
        parts = vio_d5.keys()
        for part in parts:
            self.accumulator[f'VD0_{part}' ].append(vio_d0[part].max(-1)[0].detach().cpu())   # (N,)
            self.accumulator[f'VD5_{part}' ].append(vio_d5[part].max(-1)[0].detach().cpu())   # (N,)
            self.accumulator[f'VD10_{part}'].append(vio_d10[part].max(-1)[0].detach().cpu())  # (N,)
            self.accumulator[f'VD20_{part}'].append(vio_d20[part].max(-1)[0].detach().cpu())  # (N,)
            self.accumulator[f'VD30_{part}'].append(vio_d30[part].max(-1)[0].detach().cpu())  # (N,)

    def get_results(self, chosen_metric=None):
        ''' Get the current mean results. '''
        # Only chosen metrics will be compacted and returned.
        compacted = self._compact_accumulator(chosen_metric)
        ret = {}
        for k, v in compacted.items():
            vio_max = v.max()
            vio_mean = v.mean()
            vio_median = v.median()
            tot_cnt = len(v)
            vio_cnt = (v > 0).float().sum()
            vio_p = vio_cnt / tot_cnt
            ret[f'{k}_max'] = vio_max.item()
            ret[f'{k}_mean'] = vio_mean.item()
            ret[f'{k}_median'] = vio_median.item()
            ret[f'{k}_percentage'] = vio_p.item()
        return ret


from lib.body_models.skel_utils.reality import eval_rot_delta as skel_eval_rot_delta

class SKELRealityEvaluator(SMPLRealityEvaluator):

    def eval(self, **kwargs):
        # Get the predictions and ground truths.
        pd = kwargs['pd']
        poses = pd['poses']  # (..., 46)

        # Compute the metrics.
        vio_d0  = skel_eval_rot_delta(poses, tol_deg=0 )  # {k: (N, 3)}
        vio_d5  = skel_eval_rot_delta(poses, tol_deg=5 )  # {k: (N, 3)}
        vio_d10 = skel_eval_rot_delta(poses, tol_deg=10)  # {k: (N, 3)}
        vio_d20 = skel_eval_rot_delta(poses, tol_deg=20)  # {k: (N, 3)}
        vio_d30 = skel_eval_rot_delta(poses, tol_deg=30)  # {k: (N, 3)}

        # Append the results.
        parts = vio_d5.keys()
        for part in parts:
            self.accumulator[f'VD0_{part}' ].append(vio_d0[part].max(-1)[0].detach().cpu())   # (N,)
            self.accumulator[f'VD5_{part}' ].append(vio_d5[part].max(-1)[0].detach().cpu())   # (N,)
            self.accumulator[f'VD10_{part}'].append(vio_d10[part].max(-1)[0].detach().cpu())  # (N,)
            self.accumulator[f'VD20_{part}'].append(vio_d20[part].max(-1)[0].detach().cpu())  # (N,)
            self.accumulator[f'VD30_{part}'].append(vio_d30[part].max(-1)[0].detach().cpu())  # (N,)