MCPcopy Create free account
hub / github.com/MAC-VO/MAC-VO / evaluate

Function evaluate

Train/MatchingNet/evaluate.py:27–63  ·  view source on GitHub ↗
(model: nn.DataParallel[FlowFormerCov], loader: DataLoader, length: int, usewandb)

Source from the content-addressed store, hash-verified

25
26
27def evaluate(model: nn.DataParallel[FlowFormerCov], loader: DataLoader, length: int, usewandb) -> List[Dict]:
28 model.eval()
29 with torch.no_grad():
30 step = 0
31 metric_list = []
32 for frameData in ColoredTqdm(loader, desc="Evaluation", total=length):
33
34 img1, img2 = frameData.cur.imageL.cuda(), frameData.nxt.imageL.cuda()
35 gt_flow = frameData.cur.gtFlow.cuda()
36 # flow, cov = model.module.inference(img1, img2)
37 flow_pre, cov_pre = model.forward(img1, img2)
38 flow, cov = flow_pre[0], torch.exp(2 * cov_pre[0])
39
40 error_mask = (gt_flow.norm(dim=1) < 240)
41 flow_mask = error_mask.unsqueeze(1).expand_as(gt_flow) # for masking the flow
42
43 MSE = (flow - gt_flow)**2
44 EPE = (flow - gt_flow).norm(dim=1)
45 masked_EPE = EPE[error_mask]
46
47 cov_dist = cov.sqrt().norm(dim=1)
48 cov_ratio = (cov_dist / EPE)
49 eval_loss = MSE / (2 * cov) + 0.5 * torch.log(cov)
50 step += 1
51 if step > length:
52 break
53 metric = {
54 'mse': MSE.mean().item(),
55 'epe': EPE.mean().item(),
56 'masked_epe': masked_EPE.mean().item(), # 'mask for epe < 200
57 'cov_dist': cov_dist.mean().item(),
58 'cov_ratio': cov_ratio.mean().item(),
59 'eval_loss': eval_loss.mean().item()
60 }
61
62 metric_list.append(metric)
63 return metric_list
64
65
66if __name__ == "__main__":

Callers 1

evaluate.pyFile · 0.85

Calls 3

ColoredTqdmClass · 0.90
forwardMethod · 0.45
meanMethod · 0.45

Tested by

no test coverage detected