reloc: LocalMatch + bench --split-id/--vpr-csv + phan tich ghep VPR/LiDAR; robot that: 85 -> 108 chot dung, 0 sai

This commit is contained in:
trung09122002
2026-09-29 10:26:00 +07:00
parent ca3b7854ea
commit 399a46139e
8 changed files with 549 additions and 92 deletions

View File

@@ -247,6 +247,12 @@ def main():
ap.add_argument("--device", default="cuda")
ap.add_argument("--csv", default="logs/vpr_eval.csv")
ap.add_argument("--fig", default="report/vpr/vi_du.png")
# Xuat ung vien cho tools/vslam_reloc_bench --vpr-csv: moi node hoi (id >=
# split-id) lay top-K node GIONG NHAT trong phan ban do (id < split-id).
ap.add_argument("--split-id", type=int, default=-1)
ap.add_argument("--topk-csv", default="")
ap.add_argument("--topk", type=int, default=5)
ap.add_argument("--topk-method", default="eigenplaces+clahe")
a = ap.parse_args()
nodes = load_db(a.db)
@@ -266,13 +272,14 @@ def main():
raw = [n["img"] for n in nodes]
enh = [clahe(im) for im in raw]
nodot = [dedot(im) for im in raw]
results, all_rows = [], {}
results, all_rows, descs = [], {}, {}
print(f"\n===== loai tru +-{a.excl_sec:.0f} s | dung = < {a.pos_m} m & < {a.pos_deg:.0f} do =====")
for tag, imgs in (("", raw), ("+clahe", enh), ("+khu_cham", nodot)):
if "tiny" in variants:
D, ms = desc_tiny(imgs)
rows = evaluate(D, nodes, a.excl_sec, a.pos_m, a.pos_deg)
nm = "tiny" + tag
descs[nm] = D
s = summarize(nm, rows, ms)
if s:
results.append(s)
@@ -281,6 +288,7 @@ def main():
D, ms = torch_desc(fn, imgs, wh, a.device)
rows = evaluate(D, nodes, a.excl_sec, a.pos_m, a.pos_deg)
nm = mname + tag
descs[nm] = D
s = summarize(nm, rows, ms)
if s:
results.append(s)
@@ -303,6 +311,33 @@ def main():
f"{int(r['ok5'])},{int(r['ok10'])}\n")
save_examples(a.fig, nodes, all_rows[best["name"]], best["name"])
print(f" csv -> {a.csv}\n anh vi du -> {a.fig}")
if a.topk_csv:
D = descs.get(a.topk_method)
if D is None:
print(f" ⚠️ khong co mo ta '{a.topk_method}' (co: {', '.join(descs)}) -- khong xuat top-K")
return 1
ids = np.array([n["id"] for n in nodes])
t = np.array([n["t"] for n in nodes])
in_map = ids < a.split_id if a.split_id > 0 else np.ones(len(ids), bool)
is_q = ids >= a.split_id if a.split_id > 0 else np.ones(len(ids), bool)
mi = np.nonzero(in_map)[0]
n_rows = 0
os.makedirs(os.path.dirname(a.topk_csv) or ".", exist_ok=True)
with open(a.topk_csv, "w") as f:
f.write("query_id,rank,node_id,sim\n")
for qi in np.nonzero(is_q)[0]:
s = D[mi] @ D[qi]
# Cung luat loai tru nhu phan cham: node ban do qua gan thoi
# diem hoi (ngay truoc diem chia) giong la hien nhien.
s[np.abs(t[mi] - t[qi]) < a.excl_sec] = -np.inf
for r, j in enumerate(np.argsort(-s)[:a.topk], start=1):
if not np.isfinite(s[j]):
break
f.write(f"{ids[qi]},{r},{ids[mi[j]]},{s[j]:.4f}\n")
n_rows += 1
print(f" top-{a.topk} ({a.topk_method}, ban do id < {a.split_id}): {int(is_q.sum())} node hoi, "
f"{n_rows} dong -> {a.topk_csv}")
return 0