[refactor] eval: drop dead batch_unit and trial_forward across metrics
The Evaluator's calibrate() is gone, so batch_unit class attrs and trial_forward() method overrides have no callers — pure cruft from the old auto-calibration design. Mechanical removal across 15 metric files. Internal time-dim chunking (the part of batching that actually does work) lives on as metric-owned _chunk_size constants set in __init__, unaffected by this change. Five files (color/multiple_objects/object_class/spatial_relationship/ optical_flow metrics) skipped — they have dataloader's in-flight modifications uncommitted; left for that branch's cleanup pass. Parity verified on fs-mbz-gpu-085: results byte-identical to v3 baseline.
This commit is contained in:
@@ -14,7 +14,6 @@ class LPIPSMetric(BaseMetric):
|
||||
higher_is_better = False
|
||||
needs_gpu = True
|
||||
dependencies = ["lpips"]
|
||||
batch_unit = "frame"
|
||||
|
||||
def __init__(self, net: str = "alex") -> None:
|
||||
super().__init__()
|
||||
@@ -34,11 +33,6 @@ class LPIPSMetric(BaseMetric):
|
||||
self._model = lpips_lib.LPIPS(net=self.net).to(self.device)
|
||||
self._model.eval()
|
||||
|
||||
def trial_forward(self, batch_size, *, height, width, num_frames):
|
||||
dummy = torch.randn(batch_size, 3, height, width, device=self.device) * 2 - 1
|
||||
with torch.no_grad():
|
||||
self._model(dummy, dummy)
|
||||
|
||||
def compute(self, sample: dict) -> list[MetricResult]:
|
||||
if self._model is None:
|
||||
self.setup()
|
||||
|
||||
@@ -52,16 +52,11 @@ class SSIMMetric(BaseMetric):
|
||||
requires_reference = True
|
||||
higher_is_better = True
|
||||
needs_gpu = False
|
||||
batch_unit = "frame"
|
||||
|
||||
def __init__(self, window_size: int = 11) -> None:
|
||||
super().__init__()
|
||||
self.window_size = window_size
|
||||
|
||||
def trial_forward(self, batch_size, *, height, width, num_frames):
|
||||
dummy = torch.randn(batch_size, 3, height, width, device=self.device)
|
||||
_ssim_per_frame(dummy, dummy, self.window_size)
|
||||
|
||||
def compute(self, sample: dict) -> list[MetricResult]:
|
||||
gen = sample["video"].float() # (B, T, C, H, W)
|
||||
ref = sample["reference"].float() # (B, T, C, H, W)
|
||||
|
||||
@@ -22,7 +22,6 @@ class PhysicsIQMetric(BaseMetric):
|
||||
name = "physics_iq"
|
||||
requires_reference = True
|
||||
higher_is_better = True
|
||||
batch_unit = "video"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -48,15 +47,6 @@ class PhysicsIQMetric(BaseMetric):
|
||||
self._spatial_iou = SpatialIoUMetric(**self._prep_kwargs)
|
||||
self._weighted_spatial_iou = WeightedSpatialIoUMetric(**self._prep_kwargs)
|
||||
|
||||
def trial_forward(self, batch_size: int, *, height: int, width: int, num_frames: int) -> None:
|
||||
sample = {
|
||||
"video": torch.rand(batch_size, num_frames, 3, height, width, device=self.device),
|
||||
"reference": torch.rand(batch_size, num_frames, 3, height, width, device=self.device),
|
||||
"reference_take2": torch.rand(batch_size, num_frames, 3, height, width, device=self.device),
|
||||
}
|
||||
with torch.no_grad():
|
||||
self.compute(sample)
|
||||
|
||||
@staticmethod
|
||||
def _extract_payload(result: MetricResult | Mapping[str, Any]) -> Mapping[str, Any]:
|
||||
if isinstance(result, MetricResult):
|
||||
|
||||
@@ -38,7 +38,6 @@ class AestheticQualityMetric(BaseMetric):
|
||||
requires_reference = False
|
||||
higher_is_better = True
|
||||
needs_gpu = True
|
||||
batch_unit = "frame"
|
||||
dependencies = ["clip"]
|
||||
backbone = "clip_vit_l14"
|
||||
|
||||
@@ -80,13 +79,6 @@ class AestheticQualityMetric(BaseMetric):
|
||||
self._aesthetic_head.to(self.device)
|
||||
self._aesthetic_head.eval()
|
||||
|
||||
def trial_forward(self, batch_size, *, height, width, num_frames):
|
||||
dummy = torch.randn(batch_size, 3, 224, 224, device=self.device)
|
||||
with torch.no_grad():
|
||||
feats = self._clip_model.encode_image(dummy).float()
|
||||
feats = F.normalize(feats, dim=-1, p=2)
|
||||
self._aesthetic_head(feats)
|
||||
|
||||
@torch.no_grad()
|
||||
def compute(self, sample: dict) -> list[MetricResult]:
|
||||
video = sample["video"] # (B, T, C, H, W)
|
||||
|
||||
@@ -34,7 +34,6 @@ class AppearanceStyleMetric(BaseMetric):
|
||||
requires_reference = False
|
||||
higher_is_better = True
|
||||
needs_gpu = True
|
||||
batch_unit = "frame"
|
||||
dependencies = ["clip"]
|
||||
backbone = "clip_vit_b32"
|
||||
|
||||
@@ -60,11 +59,6 @@ class AppearanceStyleMetric(BaseMetric):
|
||||
)
|
||||
self._model.eval()
|
||||
|
||||
def trial_forward(self, batch_size, *, height, width, num_frames):
|
||||
dummy = torch.randn(batch_size, 3, 224, 224, device=self.device)
|
||||
with torch.no_grad():
|
||||
self._model.encode_image(dummy)
|
||||
|
||||
@torch.no_grad()
|
||||
def compute(self, sample: dict) -> list[MetricResult]:
|
||||
import clip
|
||||
|
||||
@@ -36,7 +36,6 @@ class BackgroundConsistencyMetric(BaseMetric):
|
||||
requires_reference = False
|
||||
higher_is_better = True
|
||||
needs_gpu = True
|
||||
batch_unit = "frame"
|
||||
dependencies = ["clip"]
|
||||
backbone = "clip_vit_b32"
|
||||
|
||||
@@ -63,11 +62,6 @@ class BackgroundConsistencyMetric(BaseMetric):
|
||||
model.eval()
|
||||
self._model = model
|
||||
|
||||
def trial_forward(self, batch_size, *, height, width, num_frames):
|
||||
dummy = torch.randn(batch_size, 3, 224, 224, device=self.device)
|
||||
with torch.no_grad():
|
||||
self._model.encode_image(dummy)
|
||||
|
||||
@torch.no_grad()
|
||||
def compute(self, sample: dict) -> list[MetricResult]:
|
||||
video = sample["video"] # (B, T, C, H, W)
|
||||
|
||||
@@ -25,7 +25,6 @@ class DynamicDegreeMetric(BaseMetric):
|
||||
higher_is_better = True
|
||||
needs_gpu = True
|
||||
dependencies = ["easydict"]
|
||||
batch_unit = "frame_pair"
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
@@ -59,18 +58,6 @@ class DynamicDegreeMetric(BaseMetric):
|
||||
model.eval()
|
||||
self._model = model
|
||||
|
||||
def trial_forward(self, batch_size, *, height, width, num_frames):
|
||||
from vbench.third_party.RAFT.core.utils_core.utils import InputPadder
|
||||
# RAFT's CorrBlock creates a (B*H*W, 1, H, W) correlation volume.
|
||||
# Cap resolution to avoid integer overflow at large batch sizes.
|
||||
h, w = min(height, 256), min(width, 256)
|
||||
img1 = torch.randn(batch_size, 3, h, w, device=self.device)
|
||||
img2 = torch.randn(batch_size, 3, h, w, device=self.device)
|
||||
padder = InputPadder(img1.shape)
|
||||
img1, img2 = padder.pad(img1, img2)
|
||||
with torch.no_grad():
|
||||
self._model(img1, img2, iters=20, test_mode=True)
|
||||
|
||||
def _get_score(self, flow: torch.Tensor) -> float:
|
||||
"""Top-5% mean flow magnitude (matching VBench dynamic_degree.get_score)."""
|
||||
flo = flow.permute(1, 2, 0).cpu().numpy()
|
||||
|
||||
@@ -48,7 +48,6 @@ class HumanActionMetric(BaseMetric):
|
||||
requires_reference = False
|
||||
higher_is_better = True
|
||||
needs_gpu = True
|
||||
batch_unit = "video"
|
||||
dependencies = ["timm"]
|
||||
|
||||
def __init__(self) -> None:
|
||||
@@ -97,11 +96,6 @@ class HumanActionMetric(BaseMetric):
|
||||
self._model.to(self.device)
|
||||
self._model.eval()
|
||||
|
||||
def trial_forward(self, batch_size, *, height, width, num_frames):
|
||||
dummy = torch.randn(batch_size, 3, 16, 224, 224, device=self.device)
|
||||
with torch.no_grad():
|
||||
self._model(dummy)
|
||||
|
||||
@torch.no_grad()
|
||||
def compute(self, sample: dict) -> list[MetricResult]:
|
||||
video = sample["video"] # (B, T, C, H, W) float [0, 1]
|
||||
|
||||
@@ -21,7 +21,6 @@ class ImagingQualityMetric(BaseMetric):
|
||||
requires_reference = False
|
||||
higher_is_better = True
|
||||
needs_gpu = True
|
||||
batch_unit = "frame"
|
||||
dependencies = ["pyiqa"]
|
||||
|
||||
def __init__(self) -> None:
|
||||
@@ -41,15 +40,6 @@ class ImagingQualityMetric(BaseMetric):
|
||||
self._model = pyiqa.create_metric("musiq-spaq", device=self.device)
|
||||
self._model.eval()
|
||||
|
||||
def trial_forward(self, batch_size, *, height, width, num_frames):
|
||||
h, w = min(height, 512), min(width, 512)
|
||||
if max(height, width) > 512:
|
||||
scale = 512.0 / max(height, width)
|
||||
h, w = int(height * scale), int(width * scale)
|
||||
dummy = torch.randn(batch_size, 3, h, w, device=self.device)
|
||||
with torch.no_grad():
|
||||
self._model(dummy)
|
||||
|
||||
@torch.no_grad()
|
||||
def compute(self, sample: dict) -> list[MetricResult]:
|
||||
video = sample["video"] # (B, T, C, H, W)
|
||||
|
||||
@@ -25,7 +25,6 @@ class MotionSmoothnessMetric(BaseMetric):
|
||||
requires_reference = False
|
||||
higher_is_better = True
|
||||
needs_gpu = True
|
||||
batch_unit = "frame_pair"
|
||||
dependencies = ["omegaconf"]
|
||||
|
||||
def __init__(self) -> None:
|
||||
@@ -87,14 +86,6 @@ class MotionSmoothnessMetric(BaseMetric):
|
||||
scale = 1 / np.floor(1 / np.sqrt(scale) * 16) * 16
|
||||
return float(scale)
|
||||
|
||||
def trial_forward(self, batch_size, *, height, width, num_frames):
|
||||
h, w = min(height, 512), min(width, 512)
|
||||
img0 = torch.randn(batch_size, 3, h, w, device=self.device)
|
||||
img1 = torch.randn(batch_size, 3, h, w, device=self.device)
|
||||
embt = self._embt.expand(batch_size, -1, -1, -1)
|
||||
with torch.no_grad():
|
||||
self._model(img0, img1, embt, scale_factor=1.0, eval=True)
|
||||
|
||||
@torch.no_grad()
|
||||
def compute(self, sample: dict) -> list[MetricResult]:
|
||||
from vbench.third_party.amt.utils.utils import (
|
||||
|
||||
@@ -34,7 +34,6 @@ class OverallConsistencyMetric(BaseMetric):
|
||||
requires_reference = False
|
||||
higher_is_better = True
|
||||
needs_gpu = True
|
||||
batch_unit = "video"
|
||||
dependencies = ["timm", "einops", "clip"]
|
||||
backbone = "viclip"
|
||||
|
||||
@@ -73,11 +72,6 @@ class OverallConsistencyMetric(BaseMetric):
|
||||
self._model.to(self.device)
|
||||
self._model.eval()
|
||||
|
||||
def trial_forward(self, batch_size, *, height, width, num_frames):
|
||||
dummy = torch.randn(batch_size, 8, 3, 224, 224, device=self.device)
|
||||
with torch.no_grad():
|
||||
self._model.encode_vision(dummy, test=True)
|
||||
|
||||
@torch.no_grad()
|
||||
def compute(self, sample: dict) -> list[MetricResult]:
|
||||
video = sample["video"] # (B, T, C, H, W)
|
||||
|
||||
@@ -37,7 +37,6 @@ class SceneMetric(BaseMetric):
|
||||
requires_reference = False
|
||||
higher_is_better = True
|
||||
needs_gpu = True
|
||||
batch_unit = "video"
|
||||
dependencies = ["transformers", "qwen_omni_utils"]
|
||||
backbone = "avocado"
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ class SubjectConsistencyMetric(BaseMetric):
|
||||
requires_reference = False
|
||||
higher_is_better = True
|
||||
needs_gpu = True
|
||||
batch_unit = "frame"
|
||||
backbone = "dino_vitb16"
|
||||
|
||||
def __init__(self) -> None:
|
||||
@@ -49,11 +48,6 @@ class SubjectConsistencyMetric(BaseMetric):
|
||||
model.eval()
|
||||
self._model = model
|
||||
|
||||
def trial_forward(self, batch_size, *, height, width, num_frames):
|
||||
dummy = torch.randn(batch_size, 3, 224, 224, device=self.device)
|
||||
with torch.no_grad():
|
||||
self._model(dummy)
|
||||
|
||||
@torch.no_grad()
|
||||
def compute(self, sample: dict) -> list[MetricResult]:
|
||||
video = sample["video"] # (B, T, C, H, W)
|
||||
|
||||
@@ -21,7 +21,6 @@ class TemporalFlickeringMetric(BaseMetric):
|
||||
requires_reference = False
|
||||
higher_is_better = True
|
||||
needs_gpu = False
|
||||
batch_unit = "video"
|
||||
|
||||
@torch.no_grad()
|
||||
def compute(self, sample: dict) -> list[MetricResult]:
|
||||
|
||||
@@ -148,7 +148,6 @@ class VideoScore2Metric(BaseMetric):
|
||||
higher_is_better = True
|
||||
needs_gpu = True
|
||||
dependencies = ["transformers", "qwen_vl_utils"]
|
||||
batch_unit = "video"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user