-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheval.py
69 lines (59 loc) · 2.12 KB
/
eval.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
import argparse
import itaclip_segmentor
import custom_datasets
from mmengine.config import Config
from mmengine.runner import Runner
def parse_args():
parser = argparse.ArgumentParser(
description='ITACLIP evaluation with MMSeg')
parser.add_argument('--config', default='')
parser.add_argument('--work-dir', default='./work_dir/')
parser.add_argument(
'--show', action='store_true', help='show prediction results')
parser.add_argument(
'--show_dir',
default='',
help='directory to save visualizaion images')
parser.add_argument(
'--launcher',
choices=['none', 'pytorch', 'slurm', 'mpi'],
default='none',
help='job launcher')
# When using PyTorch version >= 2.0.0, the `torch.distributed.launch`
# will pass the `--local-rank` parameter to `tools/train.py` instead
# of `--local_rank`.
parser.add_argument('--local_rank', '--local-rank', type=int, default=0)
args = parser.parse_args()
if 'LOCAL_RANK' not in os.environ:
os.environ['LOCAL_RANK'] = str(args.local_rank)
return args
def trigger_visualization_hook(cfg, args):
default_hooks = cfg.default_hooks
if 'visualization' in default_hooks:
visualization_hook = default_hooks['visualization']
# Turn on visualization
visualization_hook['draw'] = True
if args.show:
visualization_hook['show'] = True
visualization_hook['wait_time'] = args.wait_time
if args.show_dir:
visualizer = cfg.visualizer
visualizer['save_dir'] = args.show_dir
else:
raise RuntimeError(
'VisualizationHook must be included in default_hooks.'
'refer to usage '
'"visualization=dict(type=\'VisualizationHook\')"')
return cfg
def main():
args = parse_args()
cfg = Config.fromfile(args.config)
cfg.launcher = args.launcher
cfg.work_dir = args.work_dir
if args.show or args.show_dir:
cfg = trigger_visualization_hook(cfg, args)
runner = Runner.from_cfg(cfg)
runner.test()
if __name__ == '__main__':
main()