Skip to content

Commit e2fa413

Browse files
committed
fix: resolve ruff lint warnings in vjepa scripts
1 parent b6e565d commit e2fa413

9 files changed

Lines changed: 16 additions & 36 deletions

File tree

src/sailsprep/action_model_testing/vjepa/clips_fixed_length/vjepa_clip_level_ablation.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
11
"""
22
VJEPA2 Clip-Level Classification — Head Ablation
33
=================================================
4-
Same clip-level pipeline as vjepa_clip_level.py (SlowFast-style chunking,
5-
no NA class), but adds --head to ablate five classification heads:
64
75
linear : mean-pool tokens -> single Linear layer
86
mlp_small : mean-pool -> LayerNorm -> 512-dim MLP -> classifier
97
mlp_large : mean-pool -> LayerNorm -> 1024 -> 512-dim MLP -> classifier
108
attentive : cross-attention query token -> Linear (original)
119
transformer : 2-layer Transformer encoder -> CLS token -> Linear
1210
13-
Features are extracted ONCE per (label, run) and cached to disk.
14-
Each head is then trained & evaluated independently.
15-
16-
Clipping rules (mirrors SlowFast exactly):
17-
< 15 frames -> skip
18-
15-44 frames -> 1 clip
19-
45-59 frames -> 2 clips
20-
>= 60 frames -> 30-frame chunks (last kept if >= 15 frames)
21-
22-
NA frames break a run. NA is NOT a class.
23-
2411
Usage:
2512
# Single head
2613
python vjepa_clip_level_ablation.py --label loco --head attentive
@@ -32,8 +19,6 @@
3219
# Skip encoder inference if features already cached
3320
python vjepa_clip_level_ablation.py --label loco --head all --skip_extraction
3421
35-
CSV columns expected:
36-
video_path, label_path, interpolated_anno_h5, split
3722
"""
3823

3924
import argparse
@@ -530,7 +515,7 @@ def run_inference(probe, te_feats, test_samples, label_map, device,
530515
rows = []
531516
idx = 0
532517

533-
for feats, labels in loader:
518+
for feats, _labels in loader:
534519
probs = softmax(probe(feats.to(device)))
535520
for i in range(probs.shape[0]):
536521
top = int(probs[i].argmax().item())
@@ -642,7 +627,8 @@ def main():
642627
labels = sorted({s["label_str"] for s in all_s})
643628
lmap = {lab: i for i, lab in enumerate(labels)}
644629
print(f"\nLabel map: {lmap}")
645-
json.dump(lmap, open(os.path.join(base_dir, "label_mapping.json"), "w"), indent=2)
630+
with open(os.path.join(base_dir, "label_mapping.json"), "w") as f:
631+
json.dump(lmap, f, indent=2)
646632
pd.DataFrame(test_s).to_csv(os.path.join(base_dir, "test_split.csv"), index=False)
647633

648634
# Inverse-frequency class weights from train split

src/sailsprep/action_model_testing/vjepa/clips_without_coi_crop/extract_features.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
try:
2222
from decord import VideoReader, cpu
23-
except ImportError:
24-
raise ImportError("Please install decord: pip install eva-decord")
23+
except ImportError as e:
24+
raise ImportError("Please install decord: pip install eva-decord") from e
2525

2626
# ============================================================
2727
# CONFIG

src/sailsprep/action_model_testing/vjepa/clips_without_coi_crop/rmm/extract_features.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
try:
2525
from decord import VideoReader, cpu
26-
except ImportError:
27-
raise ImportError("Please install decord: pip install eva-decord")
26+
except ImportError as e:
27+
raise ImportError("Please install decord: pip install eva-decord") from e
2828

2929
# ============================================================
3030
# CONFIG

src/sailsprep/action_model_testing/vjepa/clips_without_coi_crop/rmm/train_probe_ablation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ def main():
392392
print(f" Clips : {len(labels)}", flush=True)
393393
print(f" Labels : {label_map}", flush=True)
394394

395-
json.dump(label_map,
396-
open(os.path.join(seed_dir, "label_mapping.json"), "w"), indent=2)
395+
with open(os.path.join(seed_dir, "label_mapping.json"), "w") as f:
396+
json.dump(label_map, f, indent=2)
397397

398398
# --- Train / test split (identical to original train_probe.py) ---
399399
indices = np.arange(len(labels))

src/sailsprep/action_model_testing/vjepa/clips_without_coi_crop/train_probe_ablation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def run_inference(probe, test_features, test_labels_enc, original_labels,
298298
loader = DataLoader(dataset, batch_size=BATCH_SIZE, shuffle=False)
299299

300300
results, idx = [], 0
301-
for feats, labels in loader:
301+
for feats, _labels in loader:
302302
probs = softmax(probe(feats.to(device)))
303303
for i in range(probs.shape[0]):
304304
top = int(probs[i].argmax().item())
@@ -381,8 +381,8 @@ def main():
381381
print(f" Clips : {len(labels)}")
382382
print(f" Labels : {label_map}")
383383

384-
json.dump(label_map,
385-
open(os.path.join(seed_dir, "label_mapping.json"), "w"), indent=2)
384+
with open(os.path.join(seed_dir, "label_mapping.json"), "w") as f:
385+
json.dump(label_map, f, indent=2)
386386

387387
# --- Train / test split (same logic as train_probe.py) ---
388388
indices = np.arange(len(labels))

src/sailsprep/action_model_testing/vjepa/coi_crop/finetune_vjepa2_h5bbox.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
"""End-to-end V-JEPA 2 fine-tuning on H5-bbox-cropped action segments.
22
3-
Mirrors the SlowFast pipeline:
4-
- Same split CSV (video_path, label_path, h5_file_path)
5-
- Same on-the-fly bbox crop from interpolated H5
6-
- Same action segment extraction (label runs >= MIN_RUN frames)
7-
- Same stratified split, class weights, metrics
8-
9-
Default mode: frozen encoder + attentive probe (recommended for small data).
3+
Default mode: frozen encoder + attentive probe.
104
Use --full_finetune to unfreeze the encoder.
115
"""
126

src/sailsprep/action_model_testing/vjepa/full_video/train_probe_framelevel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def run_inference_per_video(probe, splits_csv, task_column,
303303
)
304304

305305
rows = []
306-
for windows, labels, lbl_strs, frame_idxs in vid_loader:
306+
for windows, _labels, lbl_strs, frame_idxs in vid_loader:
307307
windows = windows.to(device)
308308
logits = probe(windows)
309309
probs = softmax(logits)

src/sailsprep/action_model_testing/vjepa/full_video/train_probe_framelevel_hierarchical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def run_inference_per_video(probe, splits_csv, task_column,
344344
)
345345

346346
rows = []
347-
for windows, s1_lbls, s2_lbls, lbl_strs, frame_idxs in vid_loader:
347+
for windows, _s1_lbls, _s2_lbls, lbl_strs, frame_idxs in vid_loader:
348348
windows = windows.to(device)
349349
l1, l2 = probe(windows)
350350
p1 = softmax(l1)

src/sailsprep/action_model_testing/vjepa/full_video/two_stage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def run_inference(probe, test_windows_raw, stage1_map, stage2_map,
384384
loader = DataLoader(dataset, batch_size=BATCH_SIZE, shuffle=False)
385385

386386
rows = []
387-
for feats, s1_lbls, s2_lbls, lbl_strs in loader:
387+
for feats, _s1_lbls, _s2_lbls, lbl_strs in loader:
388388
feats = feats.to(device)
389389

390390
logits1, logits2 = probe(feats)

0 commit comments

Comments
 (0)