support re-rank for HID
This commit is contained in:
+70
-3
@@ -40,7 +40,6 @@ def de_diag(acc, each_angle=False):
|
|||||||
|
|
||||||
def identification(data, dataset, metric='euc'):
|
def identification(data, dataset, metric='euc'):
|
||||||
msg_mgr = get_msg_mgr()
|
msg_mgr = get_msg_mgr()
|
||||||
|
|
||||||
feature, label, seq_type, view = data['embeddings'], data['labels'], data['types'], data['views']
|
feature, label, seq_type, view = data['embeddings'], data['labels'], data['types'], data['views']
|
||||||
label = np.array(label)
|
label = np.array(label)
|
||||||
view_list = list(set(view))
|
view_list = list(set(view))
|
||||||
@@ -158,8 +157,12 @@ def evaluate_HID(data, dataset, metric='euc'):
|
|||||||
gallery_y = label[gallery_mask]
|
gallery_y = label[gallery_mask]
|
||||||
probe_x = feature[probe_mask, :]
|
probe_x = feature[probe_mask, :]
|
||||||
probe_y = seq_type[probe_mask]
|
probe_y = seq_type[probe_mask]
|
||||||
dist = cuda_dist(probe_x, gallery_x, metric)
|
|
||||||
idx = dist.cpu().sort(1)[1].numpy()
|
feat = np.concatenate([probe_x, gallery_x])
|
||||||
|
dist = cuda_dist(feat, feat, metric).cpu().numpy()
|
||||||
|
re_rank = re_ranking(dist, probe_x.shape[0], k1=6, k2=6, lambda_value=0.3)
|
||||||
|
idx = np.argsort(re_rank, axis=1)
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from time import strftime, localtime
|
from time import strftime, localtime
|
||||||
save_path = os.path.join(
|
save_path = os.path.join(
|
||||||
@@ -171,3 +174,67 @@ def evaluate_HID(data, dataset, metric='euc'):
|
|||||||
f.write("{},{}\n".format(probe_y[i], gallery_y[idx[i, 0]]))
|
f.write("{},{}\n".format(probe_y[i], gallery_y[idx[i, 0]]))
|
||||||
print("HID result saved to {}/{}".format(os.getcwd(), save_path))
|
print("HID result saved to {}/{}".format(os.getcwd(), save_path))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def re_ranking(original_dist, query_num, k1, k2, lambda_value):
|
||||||
|
# Modified from https://github.com/michuanhaohao/reid-strong-baseline/blob/master/utils/re_ranking.py
|
||||||
|
all_num = original_dist.shape[0]
|
||||||
|
original_dist = np.transpose(original_dist / np.max(original_dist, axis=0))
|
||||||
|
V = np.zeros_like(original_dist).astype(np.float16)
|
||||||
|
initial_rank = np.argsort(original_dist).astype(np.int32)
|
||||||
|
|
||||||
|
print('starting re_ranking')
|
||||||
|
for i in range(all_num):
|
||||||
|
# k-reciprocal neighbors
|
||||||
|
forward_k_neigh_index = initial_rank[i, :k1 + 1]
|
||||||
|
backward_k_neigh_index = initial_rank[forward_k_neigh_index, :k1 + 1]
|
||||||
|
fi = np.where(backward_k_neigh_index == i)[0]
|
||||||
|
k_reciprocal_index = forward_k_neigh_index[fi]
|
||||||
|
k_reciprocal_expansion_index = k_reciprocal_index
|
||||||
|
for j in range(len(k_reciprocal_index)):
|
||||||
|
candidate = k_reciprocal_index[j]
|
||||||
|
candidate_forward_k_neigh_index = initial_rank[candidate, :int(
|
||||||
|
np.around(k1 / 2)) + 1]
|
||||||
|
candidate_backward_k_neigh_index = initial_rank[candidate_forward_k_neigh_index,
|
||||||
|
:int(np.around(k1 / 2)) + 1]
|
||||||
|
fi_candidate = np.where(
|
||||||
|
candidate_backward_k_neigh_index == candidate)[0]
|
||||||
|
candidate_k_reciprocal_index = candidate_forward_k_neigh_index[fi_candidate]
|
||||||
|
if len(np.intersect1d(candidate_k_reciprocal_index, k_reciprocal_index)) > 2 / 3 * len(
|
||||||
|
candidate_k_reciprocal_index):
|
||||||
|
k_reciprocal_expansion_index = np.append(
|
||||||
|
k_reciprocal_expansion_index, candidate_k_reciprocal_index)
|
||||||
|
|
||||||
|
k_reciprocal_expansion_index = np.unique(k_reciprocal_expansion_index)
|
||||||
|
weight = np.exp(-original_dist[i, k_reciprocal_expansion_index])
|
||||||
|
V[i, k_reciprocal_expansion_index] = weight / np.sum(weight)
|
||||||
|
original_dist = original_dist[:query_num, ]
|
||||||
|
if k2 != 1:
|
||||||
|
V_qe = np.zeros_like(V, dtype=np.float16)
|
||||||
|
for i in range(all_num):
|
||||||
|
V_qe[i, :] = np.mean(V[initial_rank[i, :k2], :], axis=0)
|
||||||
|
V = V_qe
|
||||||
|
del V_qe
|
||||||
|
del initial_rank
|
||||||
|
invIndex = []
|
||||||
|
for i in range(all_num):
|
||||||
|
invIndex.append(np.where(V[:, i] != 0)[0])
|
||||||
|
|
||||||
|
jaccard_dist = np.zeros_like(original_dist, dtype=np.float16)
|
||||||
|
|
||||||
|
for i in range(query_num):
|
||||||
|
temp_min = np.zeros(shape=[1, all_num], dtype=np.float16)
|
||||||
|
indNonZero = np.where(V[i, :] != 0)[0]
|
||||||
|
indImages = [invIndex[ind] for ind in indNonZero]
|
||||||
|
for j in range(len(indNonZero)):
|
||||||
|
temp_min[0, indImages[j]] = temp_min[0, indImages[j]] + np.minimum(V[i, indNonZero[j]],
|
||||||
|
V[indImages[j], indNonZero[j]])
|
||||||
|
jaccard_dist[i] = 1 - temp_min / (2 - temp_min)
|
||||||
|
|
||||||
|
final_dist = jaccard_dist * (1 - lambda_value) + \
|
||||||
|
original_dist * lambda_value
|
||||||
|
del original_dist
|
||||||
|
del V
|
||||||
|
del jaccard_dist
|
||||||
|
final_dist = final_dist[:query_num, query_num:]
|
||||||
|
return final_dist
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
# HID Tutorial
|
# HID Tutorial
|
||||||

|

|
||||||
This is the official support for competition of [Human Identification at a Distance (HID)](http://hid2022.iapr-tc4.org/). We report our result is 68.7% using the baseline model. In order for participants to better start the first step, we provide a tutorial on how to use OpenGait for HID.
|
This is the official support for competition of [Human Identification at a Distance (HID)](http://hid2022.iapr-tc4.org/). We report our result of 68.7% using the baseline model and 80.0% with re-ranking. In order for participants to better start the first step, we provide a tutorial on how to use OpenGait for HID.
|
||||||
|
|
||||||
## Preprocess the dataset
|
## Preprocess the dataset
|
||||||
Download the raw dataset from the [official link](http://hid2022.iapr-tc4.org/). You will get three compressed files, i.e. `train.tar`, `HID2022_test_gallery.zip` and `HID2022_test_probe.zip`.
|
Download the raw dataset from the [official link](http://hid2022.iapr-tc4.org/). You will get three compressed files, i.e. `train.tar`, `HID2022_test_gallery.zip` and `HID2022_test_probe.zip`.
|
||||||
|
|||||||
Reference in New Issue
Block a user