Closed opentld closed 3 years ago
你好你好你说的这个功能我之前参考cluster-contrast-reid/clustercontrast/evaluators.py 评测代码实现一版,希望对你有帮助。
`class Evaluator(object): def init(self, model): super(Evaluator, self).init() self.model = model
def evaluate(self, data_loader, query, gallery, cmc_flag=False, rerank=False):
features, _ = extract_features(self.model, data_loader)
distmat, query_features, gallery_features = pairwise_distance(features, query, gallery)
x = [f for f, _, _ in query]
y = [f for f, _, _ in gallery]
indices = np.argsort(distmat, axis=1)
for i, q_f_name in enumerate(x):
# q_f_name = query[i][0]
root_path = './query/spcl/{}'.format(i)
if not os.path.exists(root_path):
os.makedirs(root_path)
q_path = os.path.join(root_path, 'q')
if not os.path.exists(q_path):
os.makedirs(q_path)
g_path = os.path.join(root_path, 'g')
if not os.path.exists(g_path):
os.makedirs(g_path)
shutil.copy(q_f_name, os.path.join(q_path, os.path.basename(q_f_name)))
for j, index in enumerate(indices[i][:50]):
g_f_name = y[index]
g_name = '{}'.format(j) + '_' + os.path.basename(g_f_name)
g_name = os.path.join(g_path, g_name)
shutil.copy(g_f_name, g_name)
你好你好你说的这个功能我之前参考cluster-contrast-reid/clustercontrast/evaluators.py 评测代码实现一版,希望对你有帮助。
`class Evaluator(object): def init(self, model): super(Evaluator, self).init() self.model = model
def evaluate(self, data_loader, query, gallery, cmc_flag=False, rerank=False): features, _ = extract_features(self.model, data_loader) distmat, query_features, gallery_features = pairwise_distance(features, query, gallery) x = [f for f, _, _ in query] y = [f for f, _, _ in gallery] indices = np.argsort(distmat, axis=1) for i, q_f_name in enumerate(x): # q_f_name = query[i][0] root_path = './query/spcl/{}'.format(i) if not os.path.exists(root_path): os.makedirs(root_path) q_path = os.path.join(root_path, 'q') if not os.path.exists(q_path): os.makedirs(q_path) g_path = os.path.join(root_path, 'g') if not os.path.exists(g_path): os.makedirs(g_path) shutil.copy(q_f_name, os.path.join(q_path, os.path.basename(q_f_name))) for j, index in enumerate(indices[i][:50]): g_f_name = y[index] g_name = '{}'.format(j) + '_' + os.path.basename(g_f_name) g_name = os.path.join(g_path, g_name) shutil.copy(g_f_name, g_name)
perfect!thank you very much !
测试了一下,感觉效果很好! 如果能有一个可视化的程序就好了,比如,输入一张图片,在图像集中找出top10的图片。。。
@wangguangyuan @alibaba-oss