MCPcopy Create free account
hub / github.com/OpenGVLab/UniFormerV2 / perform_test

Function perform_test

tools/test_net.py:25–140  ·  view source on GitHub ↗

For classification: Perform mutli-view testing that uniformly samples N clips from a video along its temporal axis. For each clip, it takes 3 crops to cover the spatial dimension, followed by averaging the softmax scores across all Nx3 views to form a video-level prediction. All

(test_loader, model, test_meter, cfg, writer=None)

Source from the content-addressed store, hash-verified

23
24@torch.no_grad()
25def perform_test(test_loader, model, test_meter, cfg, writer=None):
26 """
27 For classification:
28 Perform mutli-view testing that uniformly samples N clips from a video along
29 its temporal axis. For each clip, it takes 3 crops to cover the spatial
30 dimension, followed by averaging the softmax scores across all Nx3 views to
31 form a video-level prediction. All video predictions are compared to
32 ground-truth labels and the final testing performance is logged.
33 For detection:
34 Perform fully-convolutional testing on the full frames without crop.
35 Args:
36 test_loader (loader): video testing loader.
37 model (model): the pretrained video model to test.
38 test_meter (TestMeter): testing meters to log and ensemble the testing
39 results.
40 cfg (CfgNode): configs. Details can be found in
41 slowfast/config/defaults.py
42 writer (TensorboardWriter object, optional): TensorboardWriter object
43 to writer Tensorboard log.
44 """
45 # Enable eval mode.
46 model.eval()
47 test_meter.iter_tic()
48
49 for cur_iter, (inputs, labels, video_idx, meta) in enumerate(test_loader):
50 if cfg.NUM_GPUS:
51 # Transfer the data to the current GPU device.
52 if isinstance(inputs, (list,)):
53 for i in range(len(inputs)):
54 inputs[i] = inputs[i].cuda(non_blocking=True)
55 else:
56 inputs = inputs.cuda(non_blocking=True)
57
58 # Transfer the data to the current GPU device.
59 labels = labels.cuda()
60 video_idx = video_idx.cuda()
61 for key, val in meta.items():
62 if isinstance(val, (list,)):
63 for i in range(len(val)):
64 val[i] = val[i].cuda(non_blocking=True)
65 else:
66 meta[key] = val.cuda(non_blocking=True)
67 test_meter.data_toc()
68
69 if cfg.DETECTION.ENABLE:
70 # Compute the predictions.
71 preds = model(inputs, meta["boxes"])
72 ori_boxes = meta["ori_boxes"]
73 metadata = meta["metadata"]
74
75 preds = preds.detach().cpu() if cfg.NUM_GPUS else preds.detach()
76 ori_boxes = (
77 ori_boxes.detach().cpu() if cfg.NUM_GPUS else ori_boxes.detach()
78 )
79 metadata = (
80 metadata.detach().cpu() if cfg.NUM_GPUS else metadata.detach()
81 )
82

Callers 1

testFunction · 0.85

Calls 8

plot_evalMethod · 0.80
iter_ticMethod · 0.45
data_tocMethod · 0.45
iter_tocMethod · 0.45
update_statsMethod · 0.45
log_iter_statsMethod · 0.45
joinMethod · 0.45
finalize_metricsMethod · 0.45

Tested by

no test coverage detected