56 lines
2.0 KiB
Python
56 lines
2.0 KiB
Python
"""Shared fixtures for minimal reference bundle trees in batch/subprocess tests."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import yaml
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[1]
|
|
REFERENCE_NMS_SOURCE = (
|
|
REPO_ROOT / "app" / "algorithm_runner" / "actionformer_release" / "libs" / "utils" / "nms.py"
|
|
)
|
|
|
|
|
|
def complete_result_tsv_body() -> str:
|
|
return (
|
|
"rank\tstart_sec\tend_sec\tproduct_id_top1\ttop1_name\ttop1_conf\n"
|
|
"1\t0\t1\tP1\t耗材1\t1.0\n"
|
|
"医生信息:测试医生 (id=123, conf=0.99)\n"
|
|
)
|
|
|
|
|
|
def write_minimal_reference_bundle(bundle: Path) -> None:
|
|
bundle.mkdir(parents=True)
|
|
(bundle / "main.py").write_text("# fake\n", encoding="utf-8")
|
|
(bundle / "code").mkdir()
|
|
(bundle / "code" / "repo_root.py").write_text("# fake\n", encoding="utf-8")
|
|
nms_target = bundle / "code" / "actionformer_release" / "libs" / "utils"
|
|
nms_target.mkdir(parents=True, exist_ok=True)
|
|
if REFERENCE_NMS_SOURCE.is_file():
|
|
(nms_target / "nms.py").write_bytes(REFERENCE_NMS_SOURCE.read_bytes())
|
|
else:
|
|
(nms_target / "nms.py").write_text("# fake nms\n", encoding="utf-8")
|
|
weights_dir = bundle / "weights"
|
|
weights_dir.mkdir()
|
|
(weights_dir / "actionformer_epoch_045.pth.tar").write_bytes(b"fake-ckpt")
|
|
(bundle / "configs").mkdir()
|
|
(bundle / "configs" / "default_config.yaml").write_text(
|
|
yaml.safe_dump(
|
|
{
|
|
"io": {"video": "", "excel": "", "out": "", "whitelist_json": None},
|
|
"weights": {"actionformer": "weights/actionformer_epoch_045.pth.tar"},
|
|
"runtime": {"work_dir": None, "keep_work_dir": False, "python": None},
|
|
"device": {},
|
|
"phase1": {},
|
|
"phase2": {},
|
|
"classification": {},
|
|
"tear_merge": {},
|
|
"output": {},
|
|
},
|
|
allow_unicode=True,
|
|
sort_keys=False,
|
|
),
|
|
encoding="utf-8",
|
|
)
|