MCPcopy Create free account
hub / github.com/MotrixLab/FineMoGen / main

Function main

tools/test.py:49–107  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

47
48
49def main():
50 args = parse_args()
51
52 cfg = mmcv.Config.fromfile(args.config)
53 if args.cfg_options is not None:
54 cfg.merge_from_dict(args.cfg_options)
55 # set cudnn_benchmark
56 if cfg.get('cudnn_benchmark', False):
57 torch.backends.cudnn.benchmark = True
58 cfg.data.test.test_mode = True
59
60 # init distributed env first, since logger depends on the dist info.
61 if args.launcher == 'none':
62 distributed = False
63 else:
64 distributed = True
65 init_dist(args.launcher, **cfg.dist_params)
66
67 # build the dataloader
68 dataset = build_dataset(cfg.data.test)
69 # the extra round_up data will be removed during gpu/cpu collect
70 data_loader = build_dataloader(dataset,
71 samples_per_gpu=cfg.data.samples_per_gpu,
72 workers_per_gpu=cfg.data.workers_per_gpu,
73 dist=distributed,
74 shuffle=False,
75 round_up=False)
76
77 # build the model and load checkpoint
78 model = build_architecture(cfg.model)
79 fp16_cfg = cfg.get('fp16', None)
80 if fp16_cfg is not None:
81 wrap_fp16_model(model)
82 load_checkpoint(model, args.checkpoint, map_location='cpu')
83
84 if not distributed:
85 if args.device == 'cpu':
86 model = model.cpu()
87 else:
88 model = MMDataParallel(model, device_ids=[0])
89 outputs = single_gpu_test(model, data_loader)
90 else:
91 model = MMDistributedDataParallel(
92 model.cuda(),
93 device_ids=[torch.cuda.current_device()],
94 broadcast_buffers=False)
95 outputs = multi_gpu_test(model, data_loader, args.tmpdir,
96 args.gpu_collect)
97
98 rank, _ = get_dist_info()
99 if rank == 0:
100 mmcv.mkdir_or_exist(osp.abspath(args.work_dir))
101 results = dataset.evaluate(outputs, args.work_dir)
102 for k, v in results.items():
103 print(f'\n{k} : {v:.4f}')
104
105 if args.out and rank == 0:
106 print(f'\nwriting results to {args.out}')

Callers 1

test.pyFile · 0.70

Calls 7

build_datasetFunction · 0.90
build_dataloaderFunction · 0.90
build_architectureFunction · 0.90
single_gpu_testFunction · 0.90
multi_gpu_testFunction · 0.90
parse_argsFunction · 0.70
evaluateMethod · 0.45

Tested by

no test coverage detected