Resolve eval sources from dataset manifests
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
|
@@ -4,8 +4,10 @@
|
|
| 4 |
from __future__ import annotations
|
| 5 |
|
| 6 |
import argparse
|
|
|
|
| 7 |
import json
|
| 8 |
from pathlib import Path
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
METHODS = ("wan_only", "ditto_global", "full", "text", "vace_hint", "vace_context")
|
|
@@ -53,13 +55,61 @@ def load_source_maps(paths: list[Path], repo_root: Path) -> tuple[dict[str, Path
|
|
| 53 |
return by_id, by_key
|
| 54 |
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
def resolve_source_video(
|
| 57 |
repo_root: Path,
|
| 58 |
sample_id: str,
|
| 59 |
raw_path: str,
|
|
|
|
|
|
|
| 60 |
source_roots: list[Path],
|
| 61 |
source_by_id: dict[str, Path],
|
| 62 |
source_by_key: dict[str, Path],
|
|
|
|
| 63 |
) -> Path:
|
| 64 |
if sample_id in source_by_id:
|
| 65 |
return source_by_id[sample_id]
|
|
@@ -69,6 +119,29 @@ def resolve_source_video(
|
|
| 69 |
if raw_name in source_by_key:
|
| 70 |
return source_by_key[raw_name]
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
source_video = Path(raw_path)
|
| 73 |
if not source_video.is_absolute():
|
| 74 |
source_video = repo_root / source_video
|
|
@@ -101,6 +174,7 @@ def build_split(
|
|
| 101 |
source_roots: list[Path],
|
| 102 |
source_by_id: dict[str, Path],
|
| 103 |
source_by_key: dict[str, Path],
|
|
|
|
| 104 |
) -> None:
|
| 105 |
samples = read_jsonl(samples_path)
|
| 106 |
output_path.parent.mkdir(parents=True, exist_ok=True)
|
|
@@ -114,9 +188,12 @@ def build_split(
|
|
| 114 |
repo_root,
|
| 115 |
sample_id,
|
| 116 |
str(sample["control_video"]),
|
|
|
|
|
|
|
| 117 |
source_roots,
|
| 118 |
source_by_id,
|
| 119 |
source_by_key,
|
|
|
|
| 120 |
)
|
| 121 |
if not source_video.exists():
|
| 122 |
missing_sources.add(str(source_video))
|
|
@@ -168,12 +245,24 @@ def main() -> None:
|
|
| 168 |
"It can also contain old_path/old_video/control_video to map old names to current hashed paths."
|
| 169 |
),
|
| 170 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
args = parser.parse_args()
|
| 172 |
|
| 173 |
repo_root = args.repo_root.resolve()
|
| 174 |
base = repo_root / "out/edit_model_face_stage1"
|
| 175 |
output_dir = args.output_dir if args.output_dir.is_absolute() else repo_root / args.output_dir
|
| 176 |
source_by_id, source_by_key = load_source_maps(args.source_map, repo_root)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
jobs = [
|
| 179 |
(
|
|
@@ -201,6 +290,7 @@ def main() -> None:
|
|
| 201 |
args.source_root,
|
| 202 |
source_by_id,
|
| 203 |
source_by_key,
|
|
|
|
| 204 |
)
|
| 205 |
|
| 206 |
|
|
|
|
| 4 |
from __future__ import annotations
|
| 5 |
|
| 6 |
import argparse
|
| 7 |
+
from collections import defaultdict
|
| 8 |
import json
|
| 9 |
from pathlib import Path
|
| 10 |
+
from typing import Any
|
| 11 |
|
| 12 |
|
| 13 |
METHODS = ("wan_only", "ditto_global", "full", "text", "vace_hint", "vace_context")
|
|
|
|
| 55 |
return by_id, by_key
|
| 56 |
|
| 57 |
|
| 58 |
+
def dataset_name_from_path(path: str) -> str:
|
| 59 |
+
parts = Path(path).parts
|
| 60 |
+
for index, part in enumerate(parts):
|
| 61 |
+
if part == "datas" and index + 1 < len(parts):
|
| 62 |
+
return parts[index + 1]
|
| 63 |
+
return ""
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def target_bucket_from_path(path: str) -> str:
|
| 67 |
+
stem = Path(path).stem
|
| 68 |
+
if "__" in stem:
|
| 69 |
+
return stem.split("__", 1)[0]
|
| 70 |
+
if "/" in path:
|
| 71 |
+
parts = Path(path).parts
|
| 72 |
+
if "high" in parts:
|
| 73 |
+
index = parts.index("high")
|
| 74 |
+
if index + 1 < len(parts):
|
| 75 |
+
return parts[index + 1]
|
| 76 |
+
return ""
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def edit_index_from_path(path: str) -> str:
|
| 80 |
+
stem = Path(path).stem
|
| 81 |
+
if "_" not in stem:
|
| 82 |
+
return ""
|
| 83 |
+
tail = stem.rsplit("_", 1)[-1]
|
| 84 |
+
return tail if tail.isdigit() else ""
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def load_dataset_manifests(paths: list[Path], repo_root: Path) -> dict[tuple[str, str, str], list[dict[str, Any]]]:
|
| 88 |
+
by_dataset_bucket_prompt: dict[tuple[str, str, str], list[dict[str, Any]]] = defaultdict(list)
|
| 89 |
+
for path in paths:
|
| 90 |
+
path = path if path.is_absolute() else repo_root / path
|
| 91 |
+
if not path.exists():
|
| 92 |
+
continue
|
| 93 |
+
dataset = path.parent.name
|
| 94 |
+
rows = json.loads(path.read_text(encoding="utf-8"))
|
| 95 |
+
for row in rows:
|
| 96 |
+
bucket = str(row.get("target_bucket", ""))
|
| 97 |
+
prompt = str(row.get("prompt", ""))
|
| 98 |
+
if dataset and bucket and prompt:
|
| 99 |
+
by_dataset_bucket_prompt[(dataset, bucket, prompt)].append(row)
|
| 100 |
+
return by_dataset_bucket_prompt
|
| 101 |
+
|
| 102 |
+
|
| 103 |
def resolve_source_video(
|
| 104 |
repo_root: Path,
|
| 105 |
sample_id: str,
|
| 106 |
raw_path: str,
|
| 107 |
+
target_path: str,
|
| 108 |
+
prompt: str,
|
| 109 |
source_roots: list[Path],
|
| 110 |
source_by_id: dict[str, Path],
|
| 111 |
source_by_key: dict[str, Path],
|
| 112 |
+
dataset_rows: dict[tuple[str, str, str], list[dict[str, Any]]],
|
| 113 |
) -> Path:
|
| 114 |
if sample_id in source_by_id:
|
| 115 |
return source_by_id[sample_id]
|
|
|
|
| 119 |
if raw_name in source_by_key:
|
| 120 |
return source_by_key[raw_name]
|
| 121 |
|
| 122 |
+
dataset = dataset_name_from_path(target_path) or dataset_name_from_path(raw_path)
|
| 123 |
+
bucket = target_bucket_from_path(target_path)
|
| 124 |
+
rows = dataset_rows.get((dataset, bucket, prompt), [])
|
| 125 |
+
if rows:
|
| 126 |
+
edit_index = edit_index_from_path(target_path)
|
| 127 |
+
if edit_index:
|
| 128 |
+
indexed_rows = [
|
| 129 |
+
row
|
| 130 |
+
for row in rows
|
| 131 |
+
if Path(str(row.get("high_materialized") or row.get("high_video_path") or row.get("high_rel") or "")).stem.endswith(
|
| 132 |
+
f"_{edit_index}"
|
| 133 |
+
)
|
| 134 |
+
]
|
| 135 |
+
if len(indexed_rows) == 1:
|
| 136 |
+
rows = indexed_rows
|
| 137 |
+
if len(rows) == 1:
|
| 138 |
+
manifest_source = rows[0].get("low_materialized") or rows[0].get("low_video_path")
|
| 139 |
+
if manifest_source:
|
| 140 |
+
source_from_manifest = Path(str(manifest_source))
|
| 141 |
+
if not source_from_manifest.is_absolute():
|
| 142 |
+
source_from_manifest = repo_root / source_from_manifest
|
| 143 |
+
return source_from_manifest
|
| 144 |
+
|
| 145 |
source_video = Path(raw_path)
|
| 146 |
if not source_video.is_absolute():
|
| 147 |
source_video = repo_root / source_video
|
|
|
|
| 174 |
source_roots: list[Path],
|
| 175 |
source_by_id: dict[str, Path],
|
| 176 |
source_by_key: dict[str, Path],
|
| 177 |
+
dataset_rows: dict[tuple[str, str, str], list[dict[str, Any]]],
|
| 178 |
) -> None:
|
| 179 |
samples = read_jsonl(samples_path)
|
| 180 |
output_path.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
| 188 |
repo_root,
|
| 189 |
sample_id,
|
| 190 |
str(sample["control_video"]),
|
| 191 |
+
str(sample.get("target_video", "")),
|
| 192 |
+
str(sample["prompt"]),
|
| 193 |
source_roots,
|
| 194 |
source_by_id,
|
| 195 |
source_by_key,
|
| 196 |
+
dataset_rows,
|
| 197 |
)
|
| 198 |
if not source_video.exists():
|
| 199 |
missing_sources.add(str(source_video))
|
|
|
|
| 245 |
"It can also contain old_path/old_video/control_video to map old names to current hashed paths."
|
| 246 |
),
|
| 247 |
)
|
| 248 |
+
parser.add_argument(
|
| 249 |
+
"--dataset-manifest",
|
| 250 |
+
type=Path,
|
| 251 |
+
action="append",
|
| 252 |
+
default=[],
|
| 253 |
+
help="Dataset manifest.json used to map eval_samples target_video/prompt back to hash low_materialized paths.",
|
| 254 |
+
)
|
| 255 |
args = parser.parse_args()
|
| 256 |
|
| 257 |
repo_root = args.repo_root.resolve()
|
| 258 |
base = repo_root / "out/edit_model_face_stage1"
|
| 259 |
output_dir = args.output_dir if args.output_dir.is_absolute() else repo_root / args.output_dir
|
| 260 |
source_by_id, source_by_key = load_source_maps(args.source_map, repo_root)
|
| 261 |
+
dataset_manifest_paths = args.dataset_manifest or [
|
| 262 |
+
Path("datas/ditto_face/manifest.json"),
|
| 263 |
+
Path("datas/ditto_face2/manifest.json"),
|
| 264 |
+
]
|
| 265 |
+
dataset_rows = load_dataset_manifests(dataset_manifest_paths, repo_root)
|
| 266 |
|
| 267 |
jobs = [
|
| 268 |
(
|
|
|
|
| 290 |
args.source_root,
|
| 291 |
source_by_id,
|
| 292 |
source_by_key,
|
| 293 |
+
dataset_rows,
|
| 294 |
)
|
| 295 |
|
| 296 |
|