更新同歌手加同时长判断
Showing
2 changed files
with
25 additions
and
5 deletions
| ... | @@ -33,7 +33,7 @@ python scripts/aliyun_dna/evaluate_aliyun_dna.py \ | ... | @@ -33,7 +33,7 @@ python scripts/aliyun_dna/evaluate_aliyun_dna.py \ |
| 33 | --queries downloads_db/queries.csv \ | 33 | --queries downloads_db/queries.csv \ |
| 34 | --out results/dna_eval.csv \ | 34 | --out results/dna_eval.csv \ |
| 35 | --db-id f08aee1806c14df782e03cc1ab93f1ea \ | 35 | --db-id f08aee1806c14df782e03cc1ab93f1ea \ |
| 36 | --concurrency 4 | 36 | --concurrency 8 |
| 37 | """ | 37 | """ |
| 38 | 38 | ||
| 39 | import argparse | 39 | import argparse | ... | ... |
| ... | @@ -15,10 +15,10 @@ | ... | @@ -15,10 +15,10 @@ |
| 15 | python scripts/download_from_db.py --song-ids 1,2,3 --extra-versions -1 | 15 | python scripts/download_from_db.py --song-ids 1,2,3 --extra-versions -1 |
| 16 | 16 | ||
| 17 | # 本地:导出查询结果到 CSV(不下载) | 17 | # 本地:导出查询结果到 CSV(不下载) |
| 18 | python scripts/download_from_db.py --song-limit 500 --extra-versions 3 --export-csv records.csv | 18 | python scripts/download_from_db.py --song-limit --extra-versions 3 --export-csv records_test.csv |
| 19 | 19 | ||
| 20 | # 服务器:从导出的 CSV 下载(不需要连接数据库) | 20 | # 服务器:从导出的 CSV 下载(不需要连接数据库) |
| 21 | python scripts/download_from_db.py --from-csv records.csv --concurrency 8 | 21 | python scripts/download_from_db.py --from-csv records_test.csv --concurrency 8 |
| 22 | 22 | ||
| 23 | 输出目录结构: | 23 | 输出目录结构: |
| 24 | {output_dir}/ | 24 | {output_dir}/ |
| ... | @@ -477,6 +477,15 @@ def main() -> None: | ... | @@ -477,6 +477,15 @@ def main() -> None: |
| 477 | # 生成 reference.csv 和 queries.csv | 477 | # 生成 reference.csv 和 queries.csv |
| 478 | ok_results = [r for r in results if r.get("status") == "ok" and r.get("local_path")] | 478 | ok_results = [r for r in results if r.get("status") == "ok" and r.get("local_path")] |
| 479 | 479 | ||
| 480 | # 先建 song_id → 主版本时长 映射,用于过滤负样本 | ||
| 481 | main_duration: dict[str, float] = {} | ||
| 482 | for r in ok_results: | ||
| 483 | if int(r["is_main_version"]) == 1 and r.get("duration"): | ||
| 484 | try: | ||
| 485 | main_duration[str(r["song_id"])] = float(r["duration"]) | ||
| 486 | except (ValueError, TypeError): | ||
| 487 | pass | ||
| 488 | |||
| 480 | ref_rows, query_rows = [], [] | 489 | ref_rows, query_rows = [], [] |
| 481 | variants_dir = output_dir / "variants" | 490 | variants_dir = output_dir / "variants" |
| 482 | 491 | ||
| ... | @@ -528,9 +537,20 @@ def main() -> None: | ... | @@ -528,9 +537,20 @@ def main() -> None: |
| 528 | continue | 537 | continue |
| 529 | query_rows.append(_query_row(dst, vname)) | 538 | query_rows.append(_query_row(dst, vname)) |
| 530 | else: | 539 | else: |
| 531 | # 负样本:翻唱/其他版本,不应匹配到 DNA 库中的主版本 | 540 | # 负样本:同歌手 + 时长相近 → 很可能是同一母带的不同分发,跳过 |
| 541 | singer = r["singer_name"] or "" | ||
| 542 | original = r["original_singer"] or "" | ||
| 543 | if singer and original and singer == original: | ||
| 544 | ref_dur = main_duration.get(str(r["song_id"])) | ||
| 545 | try: | ||
| 546 | cover_dur = float(r["duration"]) if r.get("duration") else None | ||
| 547 | except (ValueError, TypeError): | ||
| 548 | cover_dur = None | ||
| 549 | if ref_dur and cover_dur and abs(cover_dur - ref_dur) / ref_dur < 0.05: | ||
| 550 | logger.debug("跳过同歌手且时长相近的版本(非负样本): song_id=%s singer=%s dur=%.0f/%.0f", | ||
| 551 | r["song_id"], singer, cover_dur, ref_dur) | ||
| 552 | continue | ||
| 532 | platform = r["platform_name"] or "unknown" | 553 | platform = r["platform_name"] or "unknown" |
| 533 | singer = r["singer_name"] or "unknown" | ||
| 534 | query_rows.append({ | 554 | query_rows.append({ |
| 535 | "song_id": r["song_id"], | 555 | "song_id": r["song_id"], |
| 536 | "audio_path": r["local_path"], | 556 | "audio_path": r["local_path"], | ... | ... |
-
Please register or sign in to post a comment