| 5 | |
| 6 | |
| 7 | class FIDEvaluator(BaseEvaluator): |
| 8 | |
| 9 | def __init__(self, |
| 10 | data_len=0, |
| 11 | evaluator_model=None, |
| 12 | batch_size=None, |
| 13 | drop_last=False, |
| 14 | replication_times=1, |
| 15 | emb_scale=1, |
| 16 | replication_reduction='statistics', |
| 17 | **kwargs): |
| 18 | super().__init__(replication_times=replication_times, |
| 19 | replication_reduction=replication_reduction, |
| 20 | batch_size=batch_size, |
| 21 | drop_last=drop_last, |
| 22 | eval_begin_idx=0, |
| 23 | eval_end_idx=data_len, |
| 24 | evaluator_model=evaluator_model) |
| 25 | self.emb_scale = emb_scale |
| 26 | self.append_indexes = None |
| 27 | |
| 28 | def single_evaluate(self, results): |
| 29 | results = self.prepare_results(results) |
| 30 | device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') |
| 31 | pred_motion = results['pred_motion'] |
| 32 | pred_motion_length = results['pred_motion_length'] |
| 33 | pred_motion_mask = results['pred_motion_mask'] |
| 34 | motion = results['motion'] |
| 35 | motion_length = results['motion_length'] |
| 36 | motion_mask = results['motion_mask'] |
| 37 | with torch.no_grad(): |
| 38 | pred_motion_emb = self.encode_motion( |
| 39 | motion=pred_motion, |
| 40 | motion_length=pred_motion_length, |
| 41 | motion_mask=pred_motion_mask, |
| 42 | device=device).cpu().detach().numpy() |
| 43 | gt_motion_emb = self.encode_motion( |
| 44 | motion=motion, |
| 45 | motion_length=motion_length, |
| 46 | motion_mask=motion_mask, |
| 47 | device=device).cpu().detach().numpy() |
| 48 | gt_mu, gt_cov = calculate_activation_statistics( |
| 49 | gt_motion_emb, self.emb_scale) |
| 50 | pred_mu, pred_cov = calculate_activation_statistics( |
| 51 | pred_motion_emb, self.emb_scale) |
| 52 | fid = calculate_frechet_distance(gt_mu, gt_cov, pred_mu, pred_cov) |
| 53 | return fid |
| 54 | |
| 55 | def parse_values(self, values): |
| 56 | metrics = {} |
| 57 | metrics['FID (mean)'] = values[0] |
| 58 | metrics['FID (conf)'] = values[1] |
| 59 | return metrics |
nothing calls this directly
no outgoing calls
no test coverage detected