-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.py
52 lines (40 loc) · 1.77 KB
/
test.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
import os
from config import cfg
import argparse
from data.build_DG_dataloader import build_reid_test_loader
from model import make_model
from processor.part_attention_vit_processor import do_inference as do_inf_pat
from processor.ori_vit_processor_with_amp import do_inference as do_inf
from utils.logger import setup_logger
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="ReID Training")
parser.add_argument(
"--config_file", default="./config/PAT.yml", help="path to config file", type=str
)
parser.add_argument("opts", help="Modify config options using the command-line", default=None,
nargs=argparse.REMAINDER)
args = parser.parse_args()
if args.config_file != "":
cfg.merge_from_file(args.config_file)
cfg.merge_from_list(args.opts)
cfg.freeze()
output_dir = os.path.join(cfg.LOG_ROOT, cfg.LOG_NAME)
if output_dir and not os.path.exists(output_dir):
os.makedirs(output_dir)
logger = setup_logger("PAT", output_dir, if_train=False)
logger.info(args)
if args.config_file != "":
logger.info("Loaded configuration file {}".format(args.config_file))
with open(args.config_file, 'r') as cf:
config_str = "\n" + cf.read()
logger.info(config_str)
logger.info("Running with config:\n{}".format(cfg))
os.environ['CUDA_VISIBLE_DEVICES'] = cfg.MODEL.DEVICE_ID
model = make_model(cfg, cfg.MODEL.NAME, 0,0,0)
model.load_param(cfg.TEST.WEIGHT)
for testname in cfg.DATASETS.TEST:
val_loader, num_query = build_reid_test_loader(cfg, testname)
if cfg.MODEL.NAME == 'part_attention_vit':
do_inf_pat(cfg, model, val_loader, num_query)
else:
do_inf(cfg, model, val_loader, num_query)