Safemotion Lib
Loading...
Searching...
No Matches
Functions | Variables
fastreid.evaluation.roc Namespace Reference

Functions

 evaluate_roc_py (distmat, q_feats, g_feats, q_pids, g_pids, q_camids, g_camids)
 
 evaluate_roc (distmat, q_feats, g_feats, q_pids, g_pids, q_camids, g_camids, use_cython=True)
 

Variables

bool IS_CYTHON_AVAI = True
 

Detailed Description

@author:  l1aoxingyu
@contact: sherlockliao01@gmail.com

Function Documentation

◆ evaluate_roc()

fastreid.evaluation.roc.evaluate_roc ( distmat,
q_feats,
g_feats,
q_pids,
g_pids,
q_camids,
g_camids,
use_cython = True )
Evaluates CMC rank.
Args:
    distmat (numpy.ndarray): distance matrix of shape (num_query, num_gallery).
    q_pids (numpy.ndarray): 1-D array containing person identities
        of each query instance.
    g_pids (numpy.ndarray): 1-D array containing person identities
        of each gallery instance.
    q_camids (numpy.ndarray): 1-D array containing camera views under
        which each query instance is captured.
    g_camids (numpy.ndarray): 1-D array containing camera views under
        which each gallery instance is captured.
    use_cython (bool, optional): use cython code for evaluation. Default is True.
        This is highly recommended as the cython code can speed up the cmc computation
        by more than 10x. This requires Cython to be installed.

Definition at line 68 of file roc.py.

77):
78 """Evaluates CMC rank.
79 Args:
80 distmat (numpy.ndarray): distance matrix of shape (num_query, num_gallery).
81 q_pids (numpy.ndarray): 1-D array containing person identities
82 of each query instance.
83 g_pids (numpy.ndarray): 1-D array containing person identities
84 of each gallery instance.
85 q_camids (numpy.ndarray): 1-D array containing camera views under
86 which each query instance is captured.
87 g_camids (numpy.ndarray): 1-D array containing camera views under
88 which each gallery instance is captured.
89 use_cython (bool, optional): use cython code for evaluation. Default is True.
90 This is highly recommended as the cython code can speed up the cmc computation
91 by more than 10x. This requires Cython to be installed.
92 """
93 if use_cython and IS_CYTHON_AVAI:
94 return evaluate_roc_cy(distmat, q_feats, g_feats, q_pids, g_pids, q_camids, g_camids)
95 else:
96 return evaluate_roc_py(distmat, q_feats, g_feats, q_pids, g_pids, q_camids, g_camids)

◆ evaluate_roc_py()

fastreid.evaluation.roc.evaluate_roc_py ( distmat,
q_feats,
g_feats,
q_pids,
g_pids,
q_camids,
g_camids )
Evaluation with ROC curve.
Key: for each query identity, its gallery images from the same camera view are discarded.

Args:
    distmat (np.ndarray): cosine distance matrix

Definition at line 24 of file roc.py.

24def evaluate_roc_py(distmat, q_feats, g_feats, q_pids, g_pids, q_camids, g_camids):
25 r"""Evaluation with ROC curve.
26 Key: for each query identity, its gallery images from the same camera view are discarded.
27
28 Args:
29 distmat (np.ndarray): cosine distance matrix
30 """
31 num_q, num_g = distmat.shape
32 dim = q_feats.shape[1]
33
34 index = faiss.IndexFlatL2(dim)
35 index.add(g_feats)
36
37 _, indices = index.search(q_feats, k=num_g)
38 matches = (g_pids[indices] == q_pids[:, np.newaxis]).astype(np.int32)
39
40 pos = []
41 neg = []
42 for q_idx in range(num_q):
43 # get query pid and camid
44 q_pid = q_pids[q_idx]
45 q_camid = q_camids[q_idx]
46
47 # Remove gallery samples that have the same pid and camid with query
48 order = indices[q_idx]
49 remove = (g_pids[order] == q_pid) & (g_camids[order] == q_camid)
50 keep = np.invert(remove)
51 raw_cmc = matches[q_idx][keep]
52
53 sort_idx = order[keep]
54
55 q_dist = distmat[q_idx]
56 ind_pos = np.where(raw_cmc == 1)[0]
57 pos.extend(q_dist[sort_idx[ind_pos]])
58
59 ind_neg = np.where(raw_cmc == 0)[0]
60 neg.extend(q_dist[sort_idx[ind_neg]])
61
62 scores = np.hstack((pos, neg))
63
64 labels = np.hstack((np.zeros(len(pos)), np.ones(len(neg))))
65 return scores, labels
66
67

Variable Documentation

◆ IS_CYTHON_AVAI

bool fastreid.evaluation.roc.IS_CYTHON_AVAI = True

Definition at line 15 of file roc.py.