Skip to content

Instantly share code, notes, and snippets.

@InnovArul
Last active January 8, 2019 11:07
Show Gist options
  • Save InnovArul/1992c75d746b0700311976b4a3d128ea to your computer and use it in GitHub Desktop.
Save InnovArul/1992c75d746b0700311976b4a3d128ea to your computer and use it in GitHub Desktop.
Code to find Mars person reid data gallery-query split bug
# taken and improvised from : https://github.com/jiyanggao/Video-Person-ReID/issues/6
import numpy as np
from scipy.io import loadmat
q = loadmat('./mars/info/query_IDX.mat')['query_IDX'][0]
t = loadmat('./mars/info/tracks_test_info.mat')['track_test_info']
query_inds = q - 1 # to get 0 based predefined array indices for query instances
# get the predefined gallery indices
gallery_inds = [i for i in range(len(t)) if i not in query_inds]
# get the PIDs of gallery and query
query_pids = t[query_inds , 2]
gallery_pids = t[gallery_inds, 2]
print('total query instances: ', len(query_pids))
print('total gallery instances (including distractors): ', len(gallery_pids))
# get the unique pids
unique_qids, counts_qids = np.unique(query_pids, return_counts=True)
unique_testids, counts_testids = np.unique(t[:,2], return_counts=True)
print('number of distractors = ' + str(counts_testids[unique_testids == -1]))
# check if there is atleast one Gallery entry for the query ID
useless_qid_count = 0
all_galleryless_ids = []
for i, qid in enumerate(unique_qids):
qid_count = counts_qids[i]
testid_count = counts_testids[unique_testids == qid][0]
if (testid_count - qid_count) == 0:
all_galleryless_ids.append((qid, qid_count))
useless_qid_count += qid_count
print('useless qids (i.e., query person thats not having corresponding gallery instance)', useless_qid_count)
print('this persons are only in query')
print(all_galleryless_ids)
print('This person ids only in query')
print(np.setdiff1d(query_pids, gallery_pids))
print()
print('This pids only in gallery')
print(np.setdiff1d(gallery_pids, query_pids))
# check if the cam mixup is there between query and gallery
# first, collect the cam index based on predefined query index
query_cams = {}
for index in query_inds:
query_pid = t[index, 2]
# if the pid entry is not there, create
if query_pid not in query_cams:
query_cams[query_pid] = set()
query_cams[query_pid].add(t[index, 3])
# collect cams for gallery pids
gallery_cams = {}
for index in gallery_inds:
gallery_pid = t[index, 2]
# if the pid entry is not there, create
if gallery_pid not in gallery_cams:
gallery_cams[gallery_pid] = set()
gallery_cams[gallery_pid].add(t[index, 3])
mutual_inclusive_cams = []
# check if the query and gallery cams are mutually exclusive
for pid, query_cam_indices in query_cams.items():
if pid in gallery_cams:
gallery_cam_indices = gallery_cams[pid]
cam_ids_intersection = query_cam_indices.intersection(gallery_cam_indices)
if len(cam_ids_intersection) != 0:
mutual_inclusive_cams.append((pid, query_cam_indices, gallery_cam_indices))
else:
# print('cams of pid ', pid, ' not available in gallery')
pass
print(len(mutual_inclusive_cams), ' pids have mutual cams')
# print(mutual_inclusive_cams)
@InnovArul
Copy link
Author

InnovArul commented Jan 8, 2019

OUTPUT:

total query instances: 1980
total gallery instances (including distractors): 10200
number of distractors = [870]
useless qids (i.e., query person thats not having corresponding gallery instance) 28
this persons are only in query
[(6, 2), (152, 2), (436, 2), (454, 2), (640, 2), (782, 2), (944, 2), (1062, 2), (1138, 2), (1140, 2), (1146, 2), (1172, 2), (1252, 2), (1444, 2)]
This person ids only in query
[ 6 152 436 454 640 782 944 1062 1138 1140 1146 1172 1252 1444]

This pids only in gallery
[ -1 0 12 14 154 166 982 1034 1104 1354]
612 pids have mutual cams

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment