forked from MinghuiChen43/CIL-ReID
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
84 lines (71 loc) · 2.88 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
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
79
80
81
82
83
84
import os
from config import cfg
import argparse
from datasets import make_dataloader
from model import make_model
from processor import do_inference
from utils.logger import setup_logger
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="ReID Baseline Training")
parser.add_argument("--config_file",
default="",
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 = cfg.OUTPUT_DIR
if output_dir and not os.path.exists(output_dir):
os.makedirs(output_dir)
logger = setup_logger("transreid", 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
train_loader, train_loader_normal, val_loader, corrupted_val_loader, corrupted_query_loader, corrupted_gallery_loader, num_query, num_classes, camera_num, view_num = make_dataloader(
cfg)
# market: 751
# cuhk: 767
# msmt: 1041
num_classes = 751
model = make_model(cfg,
num_class=num_classes,
camera_num=camera_num,
view_num=view_num)
model.load_param(cfg.TEST.WEIGHT)
for eval_epoch in range(10):
print("Eval epoch ", eval_epoch)
print("=" * 64)
loader_list = [
val_loader, corrupted_val_loader, corrupted_query_loader,
corrupted_gallery_loader
]
name = [
"Clean eval", "Corrupted eval", "Corrupted query",
"Corrupted gallery"
]
for loader_i in range(4):
print("Evaluating on ", name[loader_i])
mINP, mAP, rank1, rank5, rank10 = do_inference(
cfg, model, loader_list[loader_i], num_query)
mINP = round(mINP * 100, 2)
mAP = round(mAP * 100, 2)
rank1 = round(rank1 * 100, 2)
rank5 = round(rank5 * 100, 2)
rank10 = round(rank10 * 100, 2)
path = cfg.OUTPUT_DIR + '/' + cfg.DATASETS.NAMES + '_eval_info.csv'
import csv
with open(path, 'a+') as f:
csv_write = csv.writer(f)
data_row = [mINP, mAP, rank1, rank5, rank10]
csv_write.writerow(data_row)