in scripts/compute_metrics.py [0:0]
def compute_metrics_track2(args):
gt = read_ground_truth(args.gt_filepath)
db_image_ids, xb = read_descriptors(args.db_descs)
d = xb.shape[1]
if d > args.max_dim:
raise RuntimeError(
f"maximum dimension exceeded {d} > {args.max_dim}"
)
query_image_ids, xq = read_descriptors(args.query_descs)
if d != xq.shape[1]:
raise RuntimeError(
f"query descriptors ({xq.shape[1]}) not same dimension as db ({d})"
)
if args.knn == -1:
print(
f"Track 2 running matching of {len(query_image_ids)} queries in "
f"{len(db_image_ids)} database ({d}D descriptors), "
f"max_results={args.max_results}."
)
predictions = match_and_make_predictions(
xq, query_image_ids,
xb, db_image_ids,
args.max_results,
metric = faiss.METRIC_INNER_PRODUCT if args.ip else faiss.METRIC_L2
)
else:
print(
f"Track 2 running matching of {len(query_image_ids)} queries in "
f"{len(db_image_ids)} database ({d}D descriptors), "
f"kNN with k={args.knn}."
)
predictions = knn_match_and_make_predictions(
xq, query_image_ids,
xb, db_image_ids,
args.knn,
metric = faiss.METRIC_INNER_PRODUCT if args.ip else faiss.METRIC_L2
)
if args.write_predictions:
print("writing predictions to", args.write_predictions)
write_predictions(predictions, args.write_predictions)
print(f"Evaluating {len(predictions)} predictions ({len(gt)} GT matches)")
metrics = evaluate(gt, predictions)
print_metrics(metrics)
if args.pr_curve_filepath:
plot_pr_curve(metrics, args.title, args.pr_curve_filepath)
return metrics