Commit 55e5f769 55e5f769b16354d54966610410d808b1e67dfd21 by 沈秋雨

更新同歌手加同时长判断

1 parent 27d15fbd
......@@ -33,7 +33,7 @@ python scripts/aliyun_dna/evaluate_aliyun_dna.py \
--queries downloads_db/queries.csv \
--out results/dna_eval.csv \
--db-id f08aee1806c14df782e03cc1ab93f1ea \
--concurrency 4
--concurrency 8
"""
import argparse
......
......@@ -15,10 +15,10 @@
python scripts/download_from_db.py --song-ids 1,2,3 --extra-versions -1
# 本地:导出查询结果到 CSV(不下载)
python scripts/download_from_db.py --song-limit 500 --extra-versions 3 --export-csv records.csv
python scripts/download_from_db.py --song-limit --extra-versions 3 --export-csv records_test.csv
# 服务器:从导出的 CSV 下载(不需要连接数据库)
python scripts/download_from_db.py --from-csv records.csv --concurrency 8
python scripts/download_from_db.py --from-csv records_test.csv --concurrency 8
输出目录结构:
{output_dir}/
......@@ -477,6 +477,15 @@ def main() -> None:
# 生成 reference.csv 和 queries.csv
ok_results = [r for r in results if r.get("status") == "ok" and r.get("local_path")]
# 先建 song_id → 主版本时长 映射,用于过滤负样本
main_duration: dict[str, float] = {}
for r in ok_results:
if int(r["is_main_version"]) == 1 and r.get("duration"):
try:
main_duration[str(r["song_id"])] = float(r["duration"])
except (ValueError, TypeError):
pass
ref_rows, query_rows = [], []
variants_dir = output_dir / "variants"
......@@ -528,9 +537,20 @@ def main() -> None:
continue
query_rows.append(_query_row(dst, vname))
else:
# 负样本:翻唱/其他版本,不应匹配到 DNA 库中的主版本
# 负样本:同歌手 + 时长相近 → 很可能是同一母带的不同分发,跳过
singer = r["singer_name"] or ""
original = r["original_singer"] or ""
if singer and original and singer == original:
ref_dur = main_duration.get(str(r["song_id"]))
try:
cover_dur = float(r["duration"]) if r.get("duration") else None
except (ValueError, TypeError):
cover_dur = None
if ref_dur and cover_dur and abs(cover_dur - ref_dur) / ref_dur < 0.05:
logger.debug("跳过同歌手且时长相近的版本(非负样本): song_id=%s singer=%s dur=%.0f/%.0f",
r["song_id"], singer, cover_dur, ref_dur)
continue
platform = r["platform_name"] or "unknown"
singer = r["singer_name"] or "unknown"
query_rows.append({
"song_id": r["song_id"],
"audio_path": r["local_path"],
......