This repository has been archived by the owner on Jun 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 135
/
test_reid.py
53 lines (43 loc) · 1.49 KB
/
test_reid.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
# coding=utf-8
"""Test person_reid and vehicle reid model"""
import argparse
import os
from glob import glob
import numpy as np
from torchreid.feature_extractor import FeatureExtractor
from torchreid.distance import compute_distance_matrix
parser = argparse.ArgumentParser()
parser.add_argument("query_img")
parser.add_argument("test_img_prefix")
parser.add_argument("--gpuid", default=0, type=int,
help="gpu id")
parser.add_argument("--vehicle_reid_model", default=None)
parser.add_argument("--person_reid_model", default=None)
parser.add_argument("--p_model_name", default="osnet_x1_0")
if __name__ == "__main__":
args = parser.parse_args()
if args.person_reid_model is not None:
extractor = FeatureExtractor(
model_name=args.p_model_name,
model_path=args.person_reid_model,
device="cuda:%d" % args.gpuid
)
elif args.vehicle_reid_model is not None:
extractor = FeatureExtractor(
model_name="resnet101",
model_path=args.vehicle_reid_model,
device="cuda:%d" % args.gpuid
)
else:
raise Exception("Please provide a model!")
test_imgs = glob(args.test_img_prefix + "*")
test_imgs.sort()
assert test_imgs
img_list = [args.query_img] + test_imgs
print(img_list)
features = extractor(img_list)
print(features.shape) # [n, 512]
# compute nxn distance
distmat = compute_distance_matrix(features, features, metric='euclidean')
np.set_printoptions(suppress=True, precision=3)
print(distmat.cpu().numpy())