xpark.dataset.VideoNSFWScore#
- class xpark.dataset.VideoNSFWScore(_local_model: str = 'Falconsai/nsfw_image_detection', num_frames: int | None = None, fps: int | None = None, keyframes_only: bool = True, start_time: float = 0.0, end_time: float | None = None, reduce_mode: Literal['avg', 'max', 'min'] = 'max')#
Video NSFW score processor.
Extracts frames from video, scores each frame with ViT-based NSFW detector, then aggregates frame scores into a single video-level NSFW score.
NSFW score is a value between 0 and 1, with higher scores indicating higher probability of NSFW content.
- Parameters:
_local_model – The NSFW model name. default: “Falconsai/nsfw_image_detection” available models: [‘Falconsai/nsfw_image_detection’]
num_frames – Number of frames to extract uniformly. Default 5 (when fps is also None).
fps – Extract frames at this frame rate, int type (mutually exclusive with num_frames).
keyframes_only – Only extract keyframes (I-frames). Default True. Keyframes are inherently representative of scene changes, providing the most discriminative frames with minimal decoding overhead.
start_time – Start time in seconds for frame extraction. Default 0.0.
end_time – End time in seconds for frame extraction. Default None (end of video).
reduce_mode – Aggregation method for frame scores (“avg”, “max”, “min”). Default “max”. For NSFW detection, “max” is recommended as it captures the worst-case frame, ensuring that even a single NSFW frame flags the entire video.
Examples
from xpark.dataset.expressions import col from xpark.dataset import VideoNSFWScore, from_items ds = from_items([{"video": "/path/to/video.mp4"}]) ds = ds.with_column( "nsfw_score", VideoNSFWScore(num_frames=5, reduce_mode="max") .options(num_workers={"GPU": 1}, batch_size=2) .with_column(col("video")), ) print(ds.take(1))
Methods
__call__(videos)Call self as a function.
options(**kwargs)with_column(videos)- __call__(videos: pa.ChunkedArray) pa.Array#
Call self as a function.
- options(**kwargs: Unpack[ExprUDFOptions]) Self#
- with_column(videos: pa.ChunkedArray) pa.Array#