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

Function benchmark_data_loading

slowfast/utils/benchmark.py:20–103  ·  view source on GitHub ↗

Benchmark the speed of data loading in PySlowFast. Args: cfg (CfgNode): configs. Details can be found in slowfast/config/defaults.py

(cfg)

Source from the content-addressed store, hash-verified

18
19
20def benchmark_data_loading(cfg):
21 """
22 Benchmark the speed of data loading in PySlowFast.
23 Args:
24
25 cfg (CfgNode): configs. Details can be found in
26 slowfast/config/defaults.py
27 """
28 # Set up environment.
29 setup_environment()
30 # Set random seed from configs.
31 np.random.seed(cfg.RNG_SEED)
32 torch.manual_seed(cfg.RNG_SEED)
33
34 # Setup logging format.
35 logging.setup_logging(cfg.OUTPUT_DIR)
36
37 # Print config.
38 logger.info("Benchmark data loading with config:")
39 logger.info(pprint.pformat(cfg))
40
41 timer = Timer()
42 dataloader = loader.construct_loader(cfg, "train")
43 logger.info(
44 "Initialize loader using {:.2f} seconds.".format(timer.seconds())
45 )
46 # Total batch size across different machines.
47 batch_size = cfg.TRAIN.BATCH_SIZE * cfg.NUM_SHARDS
48 log_period = cfg.BENCHMARK.LOG_PERIOD
49 epoch_times = []
50 # Test for a few epochs.
51 for cur_epoch in range(cfg.BENCHMARK.NUM_EPOCHS):
52 timer = Timer()
53 timer_epoch = Timer()
54 iter_times = []
55 if cfg.BENCHMARK.SHUFFLE:
56 loader.shuffle_dataset(dataloader, cur_epoch)
57 for cur_iter, _ in enumerate(tqdm.tqdm(dataloader)):
58 if cur_iter > 0 and cur_iter % log_period == 0:
59 iter_times.append(timer.seconds())
60 ram_usage, ram_total = misc.cpu_mem_usage()
61 logger.info(
62 "Epoch {}: {} iters ({} videos) in {:.2f} seconds. "
63 "RAM Usage: {:.2f}/{:.2f} GB.".format(
64 cur_epoch,
65 log_period,
66 log_period * batch_size,
67 iter_times[-1],
68 ram_usage,
69 ram_total,
70 )
71 )
72 timer.reset()
73 epoch_times.append(timer_epoch.seconds())
74 ram_usage, ram_total = misc.cpu_mem_usage()
75 logger.info(
76 "Epoch {}: in total {} iters ({} videos) in {:.2f} seconds. "
77 "RAM Usage: {:.2f}/{:.2f} GB.".format(

Callers

nothing calls this directly

Calls 2

setup_environmentFunction · 0.90
resetMethod · 0.45

Tested by

no test coverage detected