Add unified pretrained metric scorers
Browse files
benchmarks/edit/code/OpenVE-3M/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
benchmarks/edit/code/OpenVE-3M/assets/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
benchmarks/edit/code/VE-Bench/assets/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
benchmarks/edit/run_traditional_metrics.py
CHANGED
|
@@ -1,5 +1,10 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
-
"""Run
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
from __future__ import annotations
|
| 5 |
|
|
@@ -31,6 +36,13 @@ CSV_FIELDS = [
|
|
| 31 |
"clip_t",
|
| 32 |
"clip_frame_consistency",
|
| 33 |
"clip_source_edit_similarity",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
"error",
|
| 35 |
]
|
| 36 |
|
|
@@ -183,6 +195,158 @@ class ClipMetrics:
|
|
| 183 |
}
|
| 184 |
|
| 185 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
def empty_result(row: dict[str, Any]) -> dict[str, Any]:
|
| 187 |
result = {field: "" for field in CSV_FIELDS}
|
| 188 |
for key in ("split", "sample_id", "method", "instruction", "source_video", "edited_video"):
|
|
@@ -197,8 +361,20 @@ def main() -> None:
|
|
| 197 |
parser.add_argument("--frames-per-video", type=int, default=16)
|
| 198 |
parser.add_argument("--resize", type=int, default=256, help="Resize sampled frames to square size before metrics; 0 disables.")
|
| 199 |
parser.add_argument("--clip-model-dir", type=Path, default=None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
parser.add_argument("--device", default="cpu")
|
| 201 |
parser.add_argument("--clip-batch-size", type=int, default=8)
|
|
|
|
|
|
|
| 202 |
args = parser.parse_args()
|
| 203 |
|
| 204 |
rows = read_jsonl(args.manifest)
|
|
@@ -207,6 +383,40 @@ def main() -> None:
|
|
| 207 |
clip = None
|
| 208 |
if args.clip_model_dir:
|
| 209 |
clip = ClipMetrics(args.clip_model_dir, args.device, args.clip_batch_size)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
|
| 211 |
with args.output.open("w", encoding="utf-8", newline="") as handle:
|
| 212 |
writer = csv.DictWriter(handle, fieldnames=CSV_FIELDS)
|
|
@@ -221,6 +431,14 @@ def main() -> None:
|
|
| 221 |
result.update(no_model_metrics(source_frames, edited_frames))
|
| 222 |
if clip is not None:
|
| 223 |
result.update(clip.compute(source_frames, edited_frames, str(row["instruction"])))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
except Exception as exc:
|
| 225 |
result["error"] = repr(exc)
|
| 226 |
writer.writerow(result)
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
+
"""Run traditional/pretrained metrics on six-method manifests.
|
| 3 |
+
|
| 4 |
+
Default metrics are no-model image/video statistics. Optional scorers are enabled
|
| 5 |
+
only when their CLI args are passed, so the script remains usable in lightweight
|
| 6 |
+
environments.
|
| 7 |
+
"""
|
| 8 |
|
| 9 |
from __future__ import annotations
|
| 10 |
|
|
|
|
| 36 |
"clip_t",
|
| 37 |
"clip_frame_consistency",
|
| 38 |
"clip_source_edit_similarity",
|
| 39 |
+
"dino_frame_consistency",
|
| 40 |
+
"laion_aesthetic",
|
| 41 |
+
"pyiqa_musiq",
|
| 42 |
+
"pyiqa_niqe",
|
| 43 |
+
"pyiqa_qalign_quality",
|
| 44 |
+
"pyiqa_qalign_aesthetic",
|
| 45 |
+
"lpips_source_edit",
|
| 46 |
"error",
|
| 47 |
]
|
| 48 |
|
|
|
|
| 195 |
}
|
| 196 |
|
| 197 |
|
| 198 |
+
class DinoMetrics:
|
| 199 |
+
def __init__(self, model_dir: Path, device: str, batch_size: int) -> None:
|
| 200 |
+
import torch
|
| 201 |
+
from transformers import AutoImageProcessor, AutoModel
|
| 202 |
+
|
| 203 |
+
self.torch = torch
|
| 204 |
+
self.device = device
|
| 205 |
+
self.batch_size = batch_size
|
| 206 |
+
self.processor = AutoImageProcessor.from_pretrained(str(model_dir))
|
| 207 |
+
self.model = AutoModel.from_pretrained(str(model_dir)).to(device)
|
| 208 |
+
self.model.eval()
|
| 209 |
+
|
| 210 |
+
def image_features(self, frames: list[Image.Image]):
|
| 211 |
+
chunks = []
|
| 212 |
+
with self.torch.inference_mode():
|
| 213 |
+
for start in range(0, len(frames), self.batch_size):
|
| 214 |
+
batch = frames[start : start + self.batch_size]
|
| 215 |
+
inputs = self.processor(images=batch, return_tensors="pt").to(self.device)
|
| 216 |
+
outputs = self.model(**inputs)
|
| 217 |
+
if getattr(outputs, "pooler_output", None) is not None:
|
| 218 |
+
feats = outputs.pooler_output
|
| 219 |
+
else:
|
| 220 |
+
feats = outputs.last_hidden_state[:, 0]
|
| 221 |
+
feats = feats / feats.norm(dim=-1, keepdim=True).clamp_min(1e-12)
|
| 222 |
+
chunks.append(feats)
|
| 223 |
+
return self.torch.cat(chunks, dim=0)
|
| 224 |
+
|
| 225 |
+
def compute(self, edited_frames: list[Image.Image]) -> dict[str, float | None]:
|
| 226 |
+
feats = self.image_features(edited_frames)
|
| 227 |
+
score = None
|
| 228 |
+
if feats.shape[0] >= 2:
|
| 229 |
+
score = float((feats[:-1] * feats[1:]).sum(dim=-1).mean().item() * 100.0)
|
| 230 |
+
return {"dino_frame_consistency": score}
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
class LaionAestheticMetrics:
|
| 234 |
+
def __init__(self, clip_model_dir: Path, predictor_path: Path, device: str, batch_size: int) -> None:
|
| 235 |
+
import torch
|
| 236 |
+
from transformers import CLIPModel, CLIPProcessor
|
| 237 |
+
|
| 238 |
+
self.torch = torch
|
| 239 |
+
self.device = device
|
| 240 |
+
self.batch_size = batch_size
|
| 241 |
+
self.processor = CLIPProcessor.from_pretrained(str(clip_model_dir))
|
| 242 |
+
self.clip = CLIPModel.from_pretrained(str(clip_model_dir)).to(device)
|
| 243 |
+
self.clip.eval()
|
| 244 |
+
|
| 245 |
+
state = torch.load(str(predictor_path), map_location="cpu")
|
| 246 |
+
if isinstance(state, dict) and "state_dict" in state:
|
| 247 |
+
state = state["state_dict"]
|
| 248 |
+
if isinstance(state, dict) and "model" in state:
|
| 249 |
+
state = state["model"]
|
| 250 |
+
weight = None
|
| 251 |
+
bias = None
|
| 252 |
+
if isinstance(state, dict):
|
| 253 |
+
for key, value in state.items():
|
| 254 |
+
if key.endswith("weight") and getattr(value, "ndim", 0) == 2:
|
| 255 |
+
weight = value
|
| 256 |
+
if key.endswith("bias") and getattr(value, "ndim", 0) == 1:
|
| 257 |
+
bias = value
|
| 258 |
+
if "weight" in state:
|
| 259 |
+
weight = state["weight"]
|
| 260 |
+
if "bias" in state:
|
| 261 |
+
bias = state["bias"]
|
| 262 |
+
if weight is None:
|
| 263 |
+
raise RuntimeError(f"cannot find linear weight in {predictor_path}")
|
| 264 |
+
self.linear = torch.nn.Linear(int(weight.shape[1]), int(weight.shape[0]))
|
| 265 |
+
self.linear.weight.data.copy_(weight.float())
|
| 266 |
+
if bias is not None:
|
| 267 |
+
self.linear.bias.data.copy_(bias.float())
|
| 268 |
+
self.linear = self.linear.to(device)
|
| 269 |
+
self.linear.eval()
|
| 270 |
+
|
| 271 |
+
def compute(self, edited_frames: list[Image.Image]) -> dict[str, float]:
|
| 272 |
+
scores = []
|
| 273 |
+
with self.torch.inference_mode():
|
| 274 |
+
for start in range(0, len(edited_frames), self.batch_size):
|
| 275 |
+
batch = edited_frames[start : start + self.batch_size]
|
| 276 |
+
inputs = self.processor(images=batch, return_tensors="pt").to(self.device)
|
| 277 |
+
feats = self.clip.get_image_features(**inputs)
|
| 278 |
+
feats = feats / feats.norm(dim=-1, keepdim=True).clamp_min(1e-12)
|
| 279 |
+
if feats.shape[-1] != self.linear.in_features:
|
| 280 |
+
raise RuntimeError(
|
| 281 |
+
f"aesthetic predictor expects {self.linear.in_features} features, "
|
| 282 |
+
f"but CLIP produced {feats.shape[-1]}"
|
| 283 |
+
)
|
| 284 |
+
values = self.linear(feats).reshape(-1)
|
| 285 |
+
scores.extend(values.detach().float().cpu().tolist())
|
| 286 |
+
return {"laion_aesthetic": float(np.mean(scores))}
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
class PyiqaMetrics:
|
| 290 |
+
def __init__(self, metric_names: list[str], device: str) -> None:
|
| 291 |
+
import pyiqa
|
| 292 |
+
import torch
|
| 293 |
+
|
| 294 |
+
self.torch = torch
|
| 295 |
+
self.metrics = {name: pyiqa.create_metric(name, device=device) for name in metric_names}
|
| 296 |
+
|
| 297 |
+
def frames_tensor(self, frames: list[Image.Image]):
|
| 298 |
+
arrays = [np.asarray(frame, dtype=np.float32) / 255.0 for frame in frames]
|
| 299 |
+
tensor = self.torch.from_numpy(np.stack(arrays, axis=0)).permute(0, 3, 1, 2).contiguous()
|
| 300 |
+
return tensor
|
| 301 |
+
|
| 302 |
+
def _score_plain(self, metric, frames):
|
| 303 |
+
tensor = self.frames_tensor(frames)
|
| 304 |
+
with self.torch.inference_mode():
|
| 305 |
+
value = metric(tensor)
|
| 306 |
+
return float(value.detach().float().mean().cpu().item())
|
| 307 |
+
|
| 308 |
+
def _score_qalign(self, metric, frames, task: str):
|
| 309 |
+
tensor = self.frames_tensor(frames)
|
| 310 |
+
with self.torch.inference_mode():
|
| 311 |
+
value = metric(tensor, task_=task)
|
| 312 |
+
return float(value.detach().float().mean().cpu().item())
|
| 313 |
+
|
| 314 |
+
def compute(self, edited_frames: list[Image.Image]) -> dict[str, float]:
|
| 315 |
+
result = {}
|
| 316 |
+
for name, metric in self.metrics.items():
|
| 317 |
+
if name == "qalign_quality":
|
| 318 |
+
result["pyiqa_qalign_quality"] = self._score_qalign(metric, edited_frames, "quality")
|
| 319 |
+
elif name == "qalign_aesthetic":
|
| 320 |
+
result["pyiqa_qalign_aesthetic"] = self._score_qalign(metric, edited_frames, "aesthetic")
|
| 321 |
+
else:
|
| 322 |
+
result[f"pyiqa_{name}"] = self._score_plain(metric, edited_frames)
|
| 323 |
+
return result
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
class LpipsMetrics:
|
| 327 |
+
def __init__(self, device: str, net: str) -> None:
|
| 328 |
+
import lpips
|
| 329 |
+
import torch
|
| 330 |
+
|
| 331 |
+
self.torch = torch
|
| 332 |
+
self.device = device
|
| 333 |
+
self.model = lpips.LPIPS(net=net).to(device)
|
| 334 |
+
self.model.eval()
|
| 335 |
+
|
| 336 |
+
def frames_tensor(self, frames: list[Image.Image]):
|
| 337 |
+
arrays = [np.asarray(frame, dtype=np.float32) / 127.5 - 1.0 for frame in frames]
|
| 338 |
+
tensor = self.torch.from_numpy(np.stack(arrays, axis=0)).permute(0, 3, 1, 2).contiguous()
|
| 339 |
+
return tensor.to(self.device)
|
| 340 |
+
|
| 341 |
+
def compute(self, source_frames: list[Image.Image], edited_frames: list[Image.Image]) -> dict[str, float]:
|
| 342 |
+
n = min(len(source_frames), len(edited_frames))
|
| 343 |
+
source = self.frames_tensor(source_frames[:n])
|
| 344 |
+
edited = self.frames_tensor(edited_frames[:n])
|
| 345 |
+
with self.torch.inference_mode():
|
| 346 |
+
values = self.model(source, edited).reshape(-1)
|
| 347 |
+
return {"lpips_source_edit": float(values.detach().float().mean().cpu().item())}
|
| 348 |
+
|
| 349 |
+
|
| 350 |
def empty_result(row: dict[str, Any]) -> dict[str, Any]:
|
| 351 |
result = {field: "" for field in CSV_FIELDS}
|
| 352 |
for key in ("split", "sample_id", "method", "instruction", "source_video", "edited_video"):
|
|
|
|
| 361 |
parser.add_argument("--frames-per-video", type=int, default=16)
|
| 362 |
parser.add_argument("--resize", type=int, default=256, help="Resize sampled frames to square size before metrics; 0 disables.")
|
| 363 |
parser.add_argument("--clip-model-dir", type=Path, default=None)
|
| 364 |
+
parser.add_argument("--dino-model-dir", type=Path, default=None)
|
| 365 |
+
parser.add_argument("--aesthetic-clip-model-dir", type=Path, default=None)
|
| 366 |
+
parser.add_argument("--aesthetic-predictor", type=Path, default=None)
|
| 367 |
+
parser.add_argument(
|
| 368 |
+
"--pyiqa-metrics",
|
| 369 |
+
default="",
|
| 370 |
+
help="Comma-separated pyiqa metrics: musiq,niqe,qalign_quality,qalign_aesthetic.",
|
| 371 |
+
)
|
| 372 |
+
parser.add_argument("--lpips", action="store_true", help="Compute LPIPS between source and edited frames.")
|
| 373 |
+
parser.add_argument("--lpips-net", default="alex", choices=("alex", "vgg", "squeeze"))
|
| 374 |
parser.add_argument("--device", default="cpu")
|
| 375 |
parser.add_argument("--clip-batch-size", type=int, default=8)
|
| 376 |
+
parser.add_argument("--dino-batch-size", type=int, default=8)
|
| 377 |
+
parser.add_argument("--aesthetic-batch-size", type=int, default=8)
|
| 378 |
args = parser.parse_args()
|
| 379 |
|
| 380 |
rows = read_jsonl(args.manifest)
|
|
|
|
| 383 |
clip = None
|
| 384 |
if args.clip_model_dir:
|
| 385 |
clip = ClipMetrics(args.clip_model_dir, args.device, args.clip_batch_size)
|
| 386 |
+
dino = None
|
| 387 |
+
if args.dino_model_dir:
|
| 388 |
+
dino = DinoMetrics(args.dino_model_dir, args.device, args.dino_batch_size)
|
| 389 |
+
aesthetic = None
|
| 390 |
+
if args.aesthetic_clip_model_dir or args.aesthetic_predictor:
|
| 391 |
+
if not args.aesthetic_clip_model_dir or not args.aesthetic_predictor:
|
| 392 |
+
raise ValueError("--aesthetic-clip-model-dir and --aesthetic-predictor must be passed together")
|
| 393 |
+
aesthetic = LaionAestheticMetrics(
|
| 394 |
+
args.aesthetic_clip_model_dir,
|
| 395 |
+
args.aesthetic_predictor,
|
| 396 |
+
args.device,
|
| 397 |
+
args.aesthetic_batch_size,
|
| 398 |
+
)
|
| 399 |
+
pyiqa_metrics = None
|
| 400 |
+
requested_pyiqa = [name.strip() for name in args.pyiqa_metrics.split(",") if name.strip()]
|
| 401 |
+
if requested_pyiqa:
|
| 402 |
+
metric_names = ["qalign" if name.startswith("qalign_") else name for name in requested_pyiqa]
|
| 403 |
+
deduped = []
|
| 404 |
+
for name in metric_names:
|
| 405 |
+
if name not in deduped:
|
| 406 |
+
deduped.append(name)
|
| 407 |
+
pyiqa_metrics = PyiqaMetrics(deduped, args.device)
|
| 408 |
+
# Keep the user's requested qalign task variants while sharing one metric instance.
|
| 409 |
+
pyiqa_metrics.metrics = {
|
| 410 |
+
("qalign_quality" if name == "qalign" and "qalign_quality" in requested_pyiqa else name): metric
|
| 411 |
+
for name, metric in pyiqa_metrics.metrics.items()
|
| 412 |
+
}
|
| 413 |
+
if "qalign_aesthetic" in requested_pyiqa and "qalign_quality" in pyiqa_metrics.metrics:
|
| 414 |
+
pyiqa_metrics.metrics["qalign_aesthetic"] = pyiqa_metrics.metrics["qalign_quality"]
|
| 415 |
+
elif "qalign_aesthetic" in requested_pyiqa and "qalign" in pyiqa_metrics.metrics:
|
| 416 |
+
pyiqa_metrics.metrics["qalign_aesthetic"] = pyiqa_metrics.metrics.pop("qalign")
|
| 417 |
+
lpips_metric = None
|
| 418 |
+
if args.lpips:
|
| 419 |
+
lpips_metric = LpipsMetrics(args.device, args.lpips_net)
|
| 420 |
|
| 421 |
with args.output.open("w", encoding="utf-8", newline="") as handle:
|
| 422 |
writer = csv.DictWriter(handle, fieldnames=CSV_FIELDS)
|
|
|
|
| 431 |
result.update(no_model_metrics(source_frames, edited_frames))
|
| 432 |
if clip is not None:
|
| 433 |
result.update(clip.compute(source_frames, edited_frames, str(row["instruction"])))
|
| 434 |
+
if dino is not None:
|
| 435 |
+
result.update(dino.compute(edited_frames))
|
| 436 |
+
if aesthetic is not None:
|
| 437 |
+
result.update(aesthetic.compute(edited_frames))
|
| 438 |
+
if pyiqa_metrics is not None:
|
| 439 |
+
result.update(pyiqa_metrics.compute(edited_frames))
|
| 440 |
+
if lpips_metric is not None:
|
| 441 |
+
result.update(lpips_metric.compute(source_frames, edited_frames))
|
| 442 |
except Exception as exc:
|
| 443 |
result["error"] = repr(exc)
|
| 444 |
writer.writerow(result)
|
benchmarks/edit/traditional_eval_notes.md
CHANGED
|
@@ -423,38 +423,188 @@ PY
|
|
| 423 |
|
| 424 |
本地 reference 没有完整 VEditBench official eval code。需要另配 Q-Align/OneAlign scorer 后,再接入统一 manifest。
|
| 425 |
|
| 426 |
-
##
|
| 427 |
|
| 428 |
- `build_six_method_manifest.py`: 为 val20/val100 构建统一 manifest。
|
| 429 |
-
- `run_traditional_metrics.py`: 默认跑 no-model metrics;
|
| 430 |
|
| 431 |
-
|
| 432 |
|
| 433 |
```bash
|
| 434 |
-
cd /
|
| 435 |
|
| 436 |
python3 reference/benchmarks/edit/build_six_method_manifest.py \
|
| 437 |
--repo-root . \
|
| 438 |
--output-dir out/edit_model_face_stage1/traditional_eval_manifests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 439 |
|
| 440 |
python3 reference/benchmarks/edit/run_traditional_metrics.py \
|
| 441 |
--manifest out/edit_model_face_stage1/traditional_eval_manifests/val20.jsonl \
|
| 442 |
-
--output out/edit_model_face_stage1/traditional_eval_metrics/
|
| 443 |
-
--frames-per-video 16
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 444 |
|
| 445 |
python3 reference/benchmarks/edit/run_traditional_metrics.py \
|
| 446 |
--manifest out/edit_model_face_stage1/traditional_eval_manifests/val100.jsonl \
|
| 447 |
-
--output out/edit_model_face_stage1/traditional_eval_metrics/
|
| 448 |
-
--frames-per-video 16
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 449 |
```
|
| 450 |
|
| 451 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 452 |
|
| 453 |
```bash
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 454 |
python3 reference/benchmarks/edit/run_traditional_metrics.py \
|
| 455 |
--manifest out/edit_model_face_stage1/traditional_eval_manifests/val100.jsonl \
|
| 456 |
-
--output out/edit_model_face_stage1/traditional_eval_metrics/
|
| 457 |
--frames-per-video 16 \
|
| 458 |
-
--
|
| 459 |
-
--device cuda
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 460 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 423 |
|
| 424 |
本地 reference 没有完整 VEditBench official eval code。需要另配 Q-Align/OneAlign scorer 后,再接入统一 manifest。
|
| 425 |
|
| 426 |
+
## Run Unified Metrics on val20 / val100
|
| 427 |
|
| 428 |
- `build_six_method_manifest.py`: 为 val20/val100 构建统一 manifest。
|
| 429 |
+
- `run_traditional_metrics.py`: 默认跑 no-model metrics;按参数额外启用 CLIP、DINO、LAION aesthetic、pyiqa、LPIPS。
|
| 430 |
|
| 431 |
+
### 1. 生成 manifest
|
| 432 |
|
| 433 |
```bash
|
| 434 |
+
cd /inspire/hdd/project/intelligentcreativedesign/dangshengqi-253114050252/z-anna/low-high-new
|
| 435 |
|
| 436 |
python3 reference/benchmarks/edit/build_six_method_manifest.py \
|
| 437 |
--repo-root . \
|
| 438 |
--output-dir out/edit_model_face_stage1/traditional_eval_manifests
|
| 439 |
+
```
|
| 440 |
+
|
| 441 |
+
### 2. 主环境一次性跑 CLIP / DINO / LAION / MUSIQ / NIQE / LPIPS
|
| 442 |
+
|
| 443 |
+
这些指标可以在主环境跑。如果 `pyiqa` 或 `lpips` 没装,先安装:
|
| 444 |
+
|
| 445 |
+
```bash
|
| 446 |
+
python3 -m pip install pyiqa lpips imageio imageio-ffmpeg
|
| 447 |
+
```
|
| 448 |
+
|
| 449 |
+
运行 `val20`:
|
| 450 |
+
|
| 451 |
+
```bash
|
| 452 |
+
cd /inspire/hdd/project/intelligentcreativedesign/dangshengqi-253114050252/z-anna/low-high-new
|
| 453 |
+
|
| 454 |
+
mkdir -p out/edit_model_face_stage1/traditional_eval_metrics
|
| 455 |
+
export TORCH_HOME="$PWD/models/torch_cache"
|
| 456 |
+
export HF_HOME="$PWD/models/hf_cache"
|
| 457 |
+
export XDG_CACHE_HOME="$PWD/models/cache"
|
| 458 |
|
| 459 |
python3 reference/benchmarks/edit/run_traditional_metrics.py \
|
| 460 |
--manifest out/edit_model_face_stage1/traditional_eval_manifests/val20.jsonl \
|
| 461 |
+
--output out/edit_model_face_stage1/traditional_eval_metrics/val20_metrics_full.csv \
|
| 462 |
+
--frames-per-video 16 \
|
| 463 |
+
--resize 256 \
|
| 464 |
+
--device cuda:0 \
|
| 465 |
+
--clip-model-dir models/openai_clip-vit-large-patch14 \
|
| 466 |
+
--dino-model-dir models/facebook_dino-vitb16 \
|
| 467 |
+
--aesthetic-clip-model-dir models/openai_clip-vit-large-patch14 \
|
| 468 |
+
--aesthetic-predictor models/laion_aesthetic/sa_0_4_vit_l_14_linear.pth \
|
| 469 |
+
--pyiqa-metrics musiq,niqe \
|
| 470 |
+
--lpips \
|
| 471 |
+
--clip-batch-size 8 \
|
| 472 |
+
--dino-batch-size 8 \
|
| 473 |
+
--aesthetic-batch-size 8
|
| 474 |
+
```
|
| 475 |
+
|
| 476 |
+
运行 `val100`:
|
| 477 |
+
|
| 478 |
+
```bash
|
| 479 |
+
cd /inspire/hdd/project/intelligentcreativedesign/dangshengqi-253114050252/z-anna/low-high-new
|
| 480 |
+
|
| 481 |
+
mkdir -p out/edit_model_face_stage1/traditional_eval_metrics
|
| 482 |
+
export TORCH_HOME="$PWD/models/torch_cache"
|
| 483 |
+
export HF_HOME="$PWD/models/hf_cache"
|
| 484 |
+
export XDG_CACHE_HOME="$PWD/models/cache"
|
| 485 |
|
| 486 |
python3 reference/benchmarks/edit/run_traditional_metrics.py \
|
| 487 |
--manifest out/edit_model_face_stage1/traditional_eval_manifests/val100.jsonl \
|
| 488 |
+
--output out/edit_model_face_stage1/traditional_eval_metrics/val100_metrics_full.csv \
|
| 489 |
+
--frames-per-video 16 \
|
| 490 |
+
--resize 256 \
|
| 491 |
+
--device cuda:0 \
|
| 492 |
+
--clip-model-dir models/openai_clip-vit-large-patch14 \
|
| 493 |
+
--dino-model-dir models/facebook_dino-vitb16 \
|
| 494 |
+
--aesthetic-clip-model-dir models/openai_clip-vit-large-patch14 \
|
| 495 |
+
--aesthetic-predictor models/laion_aesthetic/sa_0_4_vit_l_14_linear.pth \
|
| 496 |
+
--pyiqa-metrics musiq,niqe \
|
| 497 |
+
--lpips \
|
| 498 |
+
--clip-batch-size 8 \
|
| 499 |
+
--dino-batch-size 8 \
|
| 500 |
+
--aesthetic-batch-size 8
|
| 501 |
```
|
| 502 |
|
| 503 |
+
输出 CSV 包含:
|
| 504 |
+
|
| 505 |
+
| Column | 指标来源 / 含义 | 方向 |
|
| 506 |
+
|---|---|---|
|
| 507 |
+
| `pixel_mse` | FiVE MSE / 全图像素差近似 | 低更好 |
|
| 508 |
+
| `pixel_psnr` | FiVE PSNR 全图近似 | 高更好 |
|
| 509 |
+
| `source_edit_l1` | 源/编辑视频全图 L1 差异 | 低更好 |
|
| 510 |
+
| `global_ssim` | VEditBench / FiVE SSIM 全图近似 | 高更好 |
|
| 511 |
+
| `edited_frame_diff_mae` | IVE temporal flickering 原始帧间差 | 低更好 |
|
| 512 |
+
| `temporal_flicker_score` | `(255-frame_diff_mae)/255` | 高更好 |
|
| 513 |
+
| `clip_t` | CLIP edited frame - instruction similarity | 高更好 |
|
| 514 |
+
| `clip_frame_consistency` | CLIP edited frame cross-frame consistency | 高更好 |
|
| 515 |
+
| `clip_source_edit_similarity` | CLIP source/edit semantic similarity | 高更好 |
|
| 516 |
+
| `dino_frame_consistency` | DINO edited frame cross-frame consistency | 高更好 |
|
| 517 |
+
| `laion_aesthetic` | LAION aesthetic predictor | 高更好 |
|
| 518 |
+
| `pyiqa_musiq` | MUSIQ image quality, frame average | 高更好 |
|
| 519 |
+
| `pyiqa_niqe` | NIQE no-reference quality, frame average | 低更好 |
|
| 520 |
+
| `lpips_source_edit` | LPIPS source/edit perceptual distance | 低更好 |
|
| 521 |
+
|
| 522 |
+
### 3. 单独环境跑 Q-Align / OneAlign 分数
|
| 523 |
+
|
| 524 |
+
Q-Align/OneAlign 建议用 `lowhigh-qalign` 环境,避免和主训练环境的 `numpy>=2`、`bitsandbytes` 冲突。先确保环境已创建并能加载 `qalign`:
|
| 525 |
|
| 526 |
```bash
|
| 527 |
+
cd /inspire/hdd/project/intelligentcreativedesign/dangshengqi-253114050252/z-anna/low-high-new
|
| 528 |
+
|
| 529 |
+
conda activate lowhigh-qalign
|
| 530 |
+
|
| 531 |
+
python3 -m pip install imageio imageio-ffmpeg pyiqa
|
| 532 |
+
python3 -m pip uninstall -y bitsandbytes || true
|
| 533 |
+
|
| 534 |
+
export TORCH_HOME="$PWD/models/torch_cache"
|
| 535 |
+
export HF_HOME="$PWD/models/hf_cache"
|
| 536 |
+
export XDG_CACHE_HOME="$PWD/models/cache"
|
| 537 |
+
|
| 538 |
+
python3 reference/benchmarks/edit/run_traditional_metrics.py \
|
| 539 |
+
--manifest out/edit_model_face_stage1/traditional_eval_manifests/val20.jsonl \
|
| 540 |
+
--output out/edit_model_face_stage1/traditional_eval_metrics/val20_metrics_qalign.csv \
|
| 541 |
+
--frames-per-video 16 \
|
| 542 |
+
--resize 256 \
|
| 543 |
+
--device cuda:0 \
|
| 544 |
+
--pyiqa-metrics qalign_quality,qalign_aesthetic
|
| 545 |
+
|
| 546 |
python3 reference/benchmarks/edit/run_traditional_metrics.py \
|
| 547 |
--manifest out/edit_model_face_stage1/traditional_eval_manifests/val100.jsonl \
|
| 548 |
+
--output out/edit_model_face_stage1/traditional_eval_metrics/val100_metrics_qalign.csv \
|
| 549 |
--frames-per-video 16 \
|
| 550 |
+
--resize 256 \
|
| 551 |
+
--device cuda:0 \
|
| 552 |
+
--pyiqa-metrics qalign_quality,qalign_aesthetic
|
| 553 |
+
```
|
| 554 |
+
|
| 555 |
+
Q-Align 输出列:
|
| 556 |
+
|
| 557 |
+
| Column | 含义 | 方向 |
|
| 558 |
+
|---|---|---|
|
| 559 |
+
| `pyiqa_qalign_quality` | Q-Align / OneAlign image quality scorer | 高更好 |
|
| 560 |
+
| `pyiqa_qalign_aesthetic` | Q-Align / OneAlign aesthetic scorer | 高更好 |
|
| 561 |
+
|
| 562 |
+
### 4. 汇总每个 method 的均值
|
| 563 |
+
|
| 564 |
+
```bash
|
| 565 |
+
cd /inspire/hdd/project/intelligentcreativedesign/dangshengqi-253114050252/z-anna/low-high-new
|
| 566 |
+
|
| 567 |
+
python3 - <<'PY'
|
| 568 |
+
import csv
|
| 569 |
+
from collections import defaultdict
|
| 570 |
+
from pathlib import Path
|
| 571 |
+
|
| 572 |
+
paths = [
|
| 573 |
+
Path("out/edit_model_face_stage1/traditional_eval_metrics/val20_metrics_full.csv"),
|
| 574 |
+
Path("out/edit_model_face_stage1/traditional_eval_metrics/val100_metrics_full.csv"),
|
| 575 |
+
Path("out/edit_model_face_stage1/traditional_eval_metrics/val20_metrics_qalign.csv"),
|
| 576 |
+
Path("out/edit_model_face_stage1/traditional_eval_metrics/val100_metrics_qalign.csv"),
|
| 577 |
+
]
|
| 578 |
+
|
| 579 |
+
for path in paths:
|
| 580 |
+
if not path.exists():
|
| 581 |
+
continue
|
| 582 |
+
rows = list(csv.DictReader(path.open()))
|
| 583 |
+
by_method = defaultdict(list)
|
| 584 |
+
for row in rows:
|
| 585 |
+
by_method[row["method"]].append(row)
|
| 586 |
+
|
| 587 |
+
print("====", path)
|
| 588 |
+
print("rows", len(rows), "errors", sum(1 for row in rows if row.get("error")))
|
| 589 |
+
fields = [f for f in rows[0].keys() if f not in {"split", "sample_id", "method", "instruction", "source_video", "edited_video", "error"}]
|
| 590 |
+
for method in sorted(by_method):
|
| 591 |
+
print("--", method, "n", len(by_method[method]))
|
| 592 |
+
for field in fields:
|
| 593 |
+
values = []
|
| 594 |
+
for row in by_method[method]:
|
| 595 |
+
value = row.get(field, "")
|
| 596 |
+
if value and value not in {"None", "inf"}:
|
| 597 |
+
try:
|
| 598 |
+
values.append(float(value))
|
| 599 |
+
except ValueError:
|
| 600 |
+
pass
|
| 601 |
+
if values:
|
| 602 |
+
print(field, sum(values) / len(values))
|
| 603 |
+
PY
|
| 604 |
```
|
| 605 |
+
|
| 606 |
+
### 5. 为什么 CoTracker / GroundingDINO 不在统一脚本默认跑
|
| 607 |
+
|
| 608 |
+
- `CoTracker3` 已下载,但 FiVE/IVE 的 motion fidelity 不是简单逐帧 cosine;需要轨迹采样、遮挡处理和 benchmark 自己的 matching/aggregation 逻辑。可以后续单独接一个 `run_cotracker_metrics.py`,不建议混进当前轻量 CSV 脚本。
|
| 609 |
+
- `GroundingDINO` 的 Quantity Accuracy 需要每条样本的 `target_span` 和目标数量。当前 `val20/val100` manifest 只有 `instruction/source_video/edited_video`,没有结构化数量字段,所以不能可靠跑 IVE 的 QA。
|
| 610 |
+
- `CLIPS.edit`、FiVE background preservation 的正式版本需要 edit mask。当前 manifest 没有 mask,只能跑全图近似 PSNR/LPIPS/MSE/SSIM。
|