Frame prediction averaging

From wenmin-wu/ds-skills · View interactive version

Frame prediction averaging is an AI agent skill from the GitHub repository wenmin-wu/ds-skills. Average per-frame sigmoid predictions across sampled video frames to produce a stable video-level classification probability

How to use this skill

Skill file

Frame Prediction Averaging

Overview

Video classification models often process individual frames independently. Averaging the sigmoid outputs across all sampled frames reduces noise from individual frame variability (occlusion, motion blur, detection failures) and produces a more stable video-level prediction. This is simpler and often competitive with temporal models like LSTMs for binary classification tasks.

Quick Start

import torch
import numpy as np

def predict_video(model, frames, device="cuda"):
    model.eval()
    batch = torch.stack(frames).to(device)
    with torch.no_grad():
        logits = model(batch).squeeze()
        probs = torch.sigmoid(logits)
    return probs.mean().item()

# frames: list of N preprocessed tensors from sampled video frames
video_prob = predict_video(model, face_tensors)

Workflow

  1. Sample N frames from the video (typically 15-20)
  2. Extract and preprocess face crops from each frame
  3. Run each frame through the classifier to get sigmoid probabilities
  4. Average all per-frame probabilities for the final video-level score
  5. Optionally clip to [0.05, 0.95] to avoid extreme predictions from single-frame errors

Key Decisions

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.