Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Datajuicer Data juicer VideoMotionScoreRaftFilter

From Leeroopedia
Knowledge Sources
Domains Data_Quality, Filtering
Last Updated 2026-02-14 16:00 GMT

Overview

Concrete tool for filtering data samples based on video motion score (RAFT) provided by Data-Juicer.

Description

VideoMotionScoreRaftFilter is a filter operator that keeps samples where the video motion score computed using the RAFT (Recurrent All-Pairs Field Transforms) optical flow model from torchvision falls within a specified range. It extends VideoMotionScoreFilter and uses torchvision's RAFT model (based on https://arxiv.org/abs/2003.12039) to estimate optical flow between consecutive frames. Preprocesses frames with normalization and BGR-to-RGB conversion, runs RAFT inference, and computes mean flow magnitude. Automatically detects and uses CUDA if available. Supports all parent class features including FPS sampling and relative normalization.

Usage

Import when filtering based on RAFT-based video motion score. Configure in YAML or Python.

Code Reference

Source Location

Signature

@OPERATORS.register_module("video_motion_score_raft_filter")
class VideoMotionScoreRaftFilter(VideoMotionScoreFilter):
    def __init__(self, min_score: float = 1.0, max_score: float = sys.float_info.max, frame_field: Optional[str] = None, sampling_fps: PositiveFloat = 2, size: Union[PositiveInt, Tuple[PositiveInt], Tuple[PositiveInt, PositiveInt], None] = None, max_size: Optional[PositiveInt] = None, divisible: PositiveInt = 8, relative: bool = False, any_or_all: str = "any", if_output_optical_flow: bool = False, optical_flow_key: str = MetaKeys.video_optical_flow, *args, **kwargs):

Import

from data_juicer.ops.filter.video_motion_score_raft_filter import VideoMotionScoreRaftFilter

I/O Contract

Inputs

Name Type Required Description
min_score float No Minimum motion score (default: 1.0)
max_score float No Maximum motion score (default: sys.float_info.max)
sampling_fps PositiveFloat No Sampling rate in frames per second (default: 2)
divisible PositiveInt No Frame dimensions must be divisible by this (default: 8)
relative bool No Normalize flow relative to frame diagonal (default: False)
any_or_all str No Keep strategy: "any" or "all" (default: "any")

Outputs

Name Type Description
samples Dict Filtered samples with video_motion_score stat computed

Usage Examples

YAML Configuration

process:
  - video_motion_score_raft_filter:
      min_score: 1.0
      sampling_fps: 2

Python API

from data_juicer.ops.filter.video_motion_score_raft_filter import VideoMotionScoreRaftFilter
op = VideoMotionScoreRaftFilter(min_score=1.0, sampling_fps=2)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment