Validate source paths in six-method manifest builder
Browse files
benchmarks/edit/__pycache__/build_six_method_manifest.cpython-313.pyc
CHANGED
|
Binary files a/benchmarks/edit/__pycache__/build_six_method_manifest.cpython-313.pyc and b/benchmarks/edit/__pycache__/build_six_method_manifest.cpython-313.pyc differ
|
|
|
benchmarks/edit/build_six_method_manifest.py
CHANGED
|
@@ -21,18 +21,53 @@ def read_jsonl(path: Path) -> list[dict]:
|
|
| 21 |
return rows
|
| 22 |
|
| 23 |
|
| 24 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
samples = read_jsonl(samples_path)
|
| 26 |
output_path.parent.mkdir(parents=True, exist_ok=True)
|
| 27 |
count = 0
|
|
|
|
|
|
|
| 28 |
with output_path.open("w", encoding="utf-8") as handle:
|
| 29 |
for sample in samples:
|
| 30 |
sample_id = str(sample["id"])
|
| 31 |
-
source_video =
|
| 32 |
-
if not source_video.
|
| 33 |
-
source_video
|
| 34 |
for method in METHODS:
|
| 35 |
edited_video = outputs_root / method / f"{sample_id}.mp4"
|
|
|
|
|
|
|
| 36 |
row = {
|
| 37 |
"split": split,
|
| 38 |
"sample_id": sample_id,
|
|
@@ -46,12 +81,27 @@ def build_split(repo_root: Path, split: str, samples_path: Path, outputs_root: P
|
|
| 46 |
handle.write(json.dumps(row, ensure_ascii=False) + "\n")
|
| 47 |
count += 1
|
| 48 |
print(f"{split}: wrote {count} rows -> {output_path}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
|
| 51 |
def main() -> None:
|
| 52 |
parser = argparse.ArgumentParser()
|
| 53 |
parser.add_argument("--repo-root", type=Path, default=Path.cwd())
|
| 54 |
parser.add_argument("--output-dir", type=Path, default=Path("out/edit_model_face_stage1/traditional_eval_manifests"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
args = parser.parse_args()
|
| 56 |
|
| 57 |
repo_root = args.repo_root.resolve()
|
|
@@ -75,7 +125,7 @@ def main() -> None:
|
|
| 75 |
for split, samples_path, outputs_root, output_path in jobs:
|
| 76 |
if not samples_path.exists():
|
| 77 |
raise FileNotFoundError(samples_path)
|
| 78 |
-
build_split(repo_root, split, samples_path, outputs_root, output_path)
|
| 79 |
|
| 80 |
|
| 81 |
if __name__ == "__main__":
|
|
|
|
| 21 |
return rows
|
| 22 |
|
| 23 |
|
| 24 |
+
def resolve_source_video(repo_root: Path, raw_path: str, source_roots: list[Path]) -> Path:
|
| 25 |
+
source_video = Path(raw_path)
|
| 26 |
+
if not source_video.is_absolute():
|
| 27 |
+
source_video = repo_root / source_video
|
| 28 |
+
if source_video.exists():
|
| 29 |
+
return source_video
|
| 30 |
+
|
| 31 |
+
# Some machines only have downloaded/evaluated outputs, not the original
|
| 32 |
+
# absolute data tree. Let callers provide roots that contain source mp4s.
|
| 33 |
+
for root in source_roots:
|
| 34 |
+
root = root if root.is_absolute() else repo_root / root
|
| 35 |
+
candidate = root / source_video.name
|
| 36 |
+
if candidate.exists():
|
| 37 |
+
return candidate
|
| 38 |
+
for root in source_roots:
|
| 39 |
+
root = root if root.is_absolute() else repo_root / root
|
| 40 |
+
if not root.exists():
|
| 41 |
+
continue
|
| 42 |
+
matches = list(root.rglob(source_video.name))
|
| 43 |
+
if matches:
|
| 44 |
+
return matches[0]
|
| 45 |
+
return source_video
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def build_split(
|
| 49 |
+
repo_root: Path,
|
| 50 |
+
split: str,
|
| 51 |
+
samples_path: Path,
|
| 52 |
+
outputs_root: Path,
|
| 53 |
+
output_path: Path,
|
| 54 |
+
source_roots: list[Path],
|
| 55 |
+
) -> None:
|
| 56 |
samples = read_jsonl(samples_path)
|
| 57 |
output_path.parent.mkdir(parents=True, exist_ok=True)
|
| 58 |
count = 0
|
| 59 |
+
missing_sources: set[str] = set()
|
| 60 |
+
missing_edits: list[str] = []
|
| 61 |
with output_path.open("w", encoding="utf-8") as handle:
|
| 62 |
for sample in samples:
|
| 63 |
sample_id = str(sample["id"])
|
| 64 |
+
source_video = resolve_source_video(repo_root, str(sample["control_video"]), source_roots)
|
| 65 |
+
if not source_video.exists():
|
| 66 |
+
missing_sources.add(str(source_video))
|
| 67 |
for method in METHODS:
|
| 68 |
edited_video = outputs_root / method / f"{sample_id}.mp4"
|
| 69 |
+
if not edited_video.exists():
|
| 70 |
+
missing_edits.append(str(edited_video))
|
| 71 |
row = {
|
| 72 |
"split": split,
|
| 73 |
"sample_id": sample_id,
|
|
|
|
| 81 |
handle.write(json.dumps(row, ensure_ascii=False) + "\n")
|
| 82 |
count += 1
|
| 83 |
print(f"{split}: wrote {count} rows -> {output_path}")
|
| 84 |
+
if missing_sources:
|
| 85 |
+
print(f"{split}: warning missing source videos: {len(missing_sources)} unique paths")
|
| 86 |
+
for path in sorted(missing_sources)[:20]:
|
| 87 |
+
print(f" missing source: {path}")
|
| 88 |
+
if missing_edits:
|
| 89 |
+
print(f"{split}: warning missing edited videos: {len(missing_edits)} rows")
|
| 90 |
+
for path in missing_edits[:20]:
|
| 91 |
+
print(f" missing edited: {path}")
|
| 92 |
|
| 93 |
|
| 94 |
def main() -> None:
|
| 95 |
parser = argparse.ArgumentParser()
|
| 96 |
parser.add_argument("--repo-root", type=Path, default=Path.cwd())
|
| 97 |
parser.add_argument("--output-dir", type=Path, default=Path("out/edit_model_face_stage1/traditional_eval_manifests"))
|
| 98 |
+
parser.add_argument(
|
| 99 |
+
"--source-root",
|
| 100 |
+
type=Path,
|
| 101 |
+
action="append",
|
| 102 |
+
default=[],
|
| 103 |
+
help="Optional directory to search for original source mp4s by basename when eval_samples control_video is missing.",
|
| 104 |
+
)
|
| 105 |
args = parser.parse_args()
|
| 106 |
|
| 107 |
repo_root = args.repo_root.resolve()
|
|
|
|
| 125 |
for split, samples_path, outputs_root, output_path in jobs:
|
| 126 |
if not samples_path.exists():
|
| 127 |
raise FileNotFoundError(samples_path)
|
| 128 |
+
build_split(repo_root, split, samples_path, outputs_root, output_path, args.source_root)
|
| 129 |
|
| 130 |
|
| 131 |
if __name__ == "__main__":
|
benchmarks/edit/traditional_eval_notes.md
CHANGED
|
@@ -500,6 +500,8 @@ PY
|
|
| 500 |
|
| 501 |
### 1. 生成 manifest
|
| 502 |
|
|
|
|
|
|
|
| 503 |
```bash
|
| 504 |
cd /inspire/hdd/project/intelligentcreativedesign/dangshengqi-253114050252/z-anna/low-high-new
|
| 505 |
|
|
@@ -508,6 +510,35 @@ python3 reference/benchmarks/edit/build_six_method_manifest.py \
|
|
| 508 |
--output-dir out/edit_model_face_stage1/traditional_eval_manifests
|
| 509 |
```
|
| 510 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 511 |
### 2. 主环境一次性跑 CLIP / DINO / LAION / MUSIQ / NIQE / LPIPS
|
| 512 |
|
| 513 |
这些指标可以在主环境跑。如果 `pyiqa` 或 `lpips` 没装,先安装:
|
|
|
|
| 500 |
|
| 501 |
### 1. 生成 manifest
|
| 502 |
|
| 503 |
+
`edited_video` 固定来自 `out/edit_model_face_stage1/eval_outputs*`。`source_video` 应该是真实原视频,默认来自 `eval_samples/*.jsonl` 里的 `control_video`;不能用某个 method 的 edited 输出冒充 source,否则 `PSNR/SSIM/LPIPS/source-edit CLIP` 会变成错误比较。
|
| 504 |
+
|
| 505 |
```bash
|
| 506 |
cd /inspire/hdd/project/intelligentcreativedesign/dangshengqi-253114050252/z-anna/low-high-new
|
| 507 |
|
|
|
|
| 510 |
--output-dir out/edit_model_face_stage1/traditional_eval_manifests
|
| 511 |
```
|
| 512 |
|
| 513 |
+
如果真实源视频在另一份目录里,给 builder 加 `--source-root`,脚本会按 `control_video` 的文件名递归搜索并重写 manifest:
|
| 514 |
+
|
| 515 |
+
```bash
|
| 516 |
+
python3 reference/benchmarks/edit/build_six_method_manifest.py \
|
| 517 |
+
--repo-root . \
|
| 518 |
+
--output-dir out/edit_model_face_stage1/traditional_eval_manifests \
|
| 519 |
+
--source-root /path/to/source/videos
|
| 520 |
+
```
|
| 521 |
+
|
| 522 |
+
生成后快速检查路径:
|
| 523 |
+
|
| 524 |
+
```bash
|
| 525 |
+
python3 - <<'PY'
|
| 526 |
+
import json
|
| 527 |
+
from pathlib import Path
|
| 528 |
+
|
| 529 |
+
for manifest in [
|
| 530 |
+
Path("out/edit_model_face_stage1/traditional_eval_manifests/val20.jsonl"),
|
| 531 |
+
Path("out/edit_model_face_stage1/traditional_eval_manifests/val100.jsonl"),
|
| 532 |
+
]:
|
| 533 |
+
rows = [json.loads(x) for x in manifest.read_text().splitlines() if x.strip()]
|
| 534 |
+
missing_sources = sorted({r["source_video"] for r in rows if not Path(r["source_video"]).exists()})
|
| 535 |
+
missing_edits = [r["edited_video"] for r in rows if not Path(r["edited_video"]).exists()]
|
| 536 |
+
print(manifest, "rows", len(rows), "missing_sources", len(missing_sources), "missing_edits", len(missing_edits))
|
| 537 |
+
for path in missing_sources[:10]:
|
| 538 |
+
print(" missing source:", path)
|
| 539 |
+
PY
|
| 540 |
+
```
|
| 541 |
+
|
| 542 |
### 2. 主环境一次性跑 CLIP / DINO / LAION / MUSIQ / NIQE / LPIPS
|
| 543 |
|
| 544 |
这些指标可以在主环境跑。如果 `pyiqa` 或 `lpips` 没装,先安装:
|