forked from callsys/DynRefer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eval.py
78 lines (60 loc) · 2.17 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
70
71
72
73
74
75
76
77
78
import argparse
import os.path
import random
import numpy as np
import torch
import torch.backends.cudnn as cudnn
# imports modules for registration
from dynrefer.tasks import *
from dynrefer.datasets import *
from dynrefer.models import *
from dynrefer.runners import *
from dynrefer.common.config import Config
import lavis.tasks as tasks
from lavis.common.dist_utils import get_rank, init_distributed_mode
from lavis.common.logger import setup_logger
from lavis.common.utils import now
def parse_args():
parser = argparse.ArgumentParser(description="Training")
parser.add_argument("--cfg-path", required=True, help="path to configuration file.")
parser.add_argument("--res-path", required=True, help="path to the dense caption result")
parser.add_argument("--metric", action="store_true", help="evaluate meteor score")
parser.add_argument("--visualize", action="store_true", help="visualize result")
parser.add_argument("--local-rank", default=-1, type=int) # for debug
parser.add_argument(
"--options",
nargs="+",
help="override some settings in the used config, the key-value pair "
"in xxx=yyy format will be merged into config file (deprecate), "
"change to --cfg-options instead.",
)
args = parser.parse_args()
# if 'LOCAL_RANK' not in os.environ:
# os.environ['LOCAL_RANK'] = str(args.local_rank)
return args
def setup_seeds(config):
seed = config.run_cfg.seed + get_rank()
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
cudnn.benchmark = False
cudnn.deterministic = True
def main():
job_id = now()
cfg = Config(parse_args())
init_distributed_mode(cfg.run_cfg)
setup_seeds(cfg)
setup_logger()
cfg.pretty_print()
task = tasks.setup_task(cfg)
res_path = cfg.args.res_path
assert os.path.exists(res_path)
if cfg.args.metric:
if ("reg" in task.eval_dataset_name) or ("refcoco" in task.eval_dataset_name):
task.report_metrics_reg(res_path)
else:
task.report_metrics_densecap(res_path)
if cfg.args.visualize:
task.visualize_result(res_path)
if __name__ == "__main__":
main()