MCPcopy Create free account
hub / github.com/drinkingcoder/NeuralMarker / validate

Function validate

evaluation_FM.py:16–45  ·  view source on GitHub ↗
(args, model, step=None, split=None)

Source from the content-addressed store, hash-verified

14
15@torch.no_grad()
16def validate(args, model, step=None, split=None):
17 model.eval()
18 dataset_val = ValidateData(args, split)
19 epe_list = []
20 epes = []
21 for val_id in tqdm(range(len(dataset_val))):
22 im1, im2, flow_gt, valid_mask = dataset_val[val_id]
23 output = model(im1[None].cuda(), im2[None].cuda(), iters=args.iters, test_mode=True)
24 flow_pr = output[1]
25 epe = torch.sum((flow_pr[0].to(flow_gt.device) - flow_gt)**2, dim=0)[valid_mask].sqrt()
26 epe_list.append(epe.view(-1).cpu().tolist())
27 epes += [epe.mean()]
28
29 epe_all = np.concatenate(epe_list)
30 epe = np.mean(epe_all)
31 px1 = np.mean(epe_all<1)
32 px3 = np.mean(epe_all<3)
33 px5 = np.mean(epe_all<5)
34
35 print(colored('[Validation %s]: ', 'yellow') % (split) +
36 "EPE: %f, 1px: %f, 3px: %f, 5px: %f" % (np.mean(epes), px1, px3, px5))
37
38 if step:
39 wandb.log({
40 'val_step' : step,
41 split + '/epe' : epe,
42 split + '/1px' : px1,
43 split + '/3px' : px3,
44 split + '/5px' : px5,
45 })
46
47
48@torch.no_grad()

Callers 1

evaluation_FM.pyFile · 0.85

Calls 1

ValidateDataClass · 0.90

Tested by

no test coverage detected