You need to enable JavaScript to run this app.
AI 数据湖服务

AI 数据湖服务

复制全文
视频处理
视频安全性检测
复制全文
视频安全性检测

算子介绍

描述

视频安全性检测器 - 多源输入、统一帧采样与批量推理

核心功能

  • 基于预训练图像分类模型,对视频采样得到的帧进行 NSFW 概率检测,并按聚合策略输出最终分数。
  • 支持多种视频输入来源:
  • URL 路径 (video_url)
  • Base64 编码 (video_base64)
  • 二进制流 (video_binary)
  • 支持多种采样方式 (通过 VideoFrameSampler):
  • by_count_uniform / by_interval_time / by_interval_frames / by_fps / by_timestamps
  • 批量推理:
  • 可通过 batch_size 控制推理批量大小,提高吞吐性能。

适用场景

  • 内容安全审核:对用户上传视频进行 NSFW 风险评估。
  • 生产管线的预过滤:在后续处理前进行视频安全性筛查。

注意事项

  • 仅输出数值型 NSFW 置信度(0~1),不保存帧图片。

Daft 调用

算子参数

输入

输入列名

说明

videos

输入视频列,类型依据 video_src_type(url/base64/binary)

输出

一个结构化结果数组,其中每个元素为视频的 NSFW 置信度分数;采样/推理失败或无有效帧则为 None

参数

如参数没有默认值,则为必填参数

参数名称

类型

默认值

描述

video_src_type

str

"video_url"

输入视频的格式类型。可选值:["video_url", "video_base64", "video_binary"]

model_path

str

"/opt/las/models"

模型基础路径。

model_name

str

"Falconsai/nsfw_image_detection"

模型名称/子目录。可选值:["Falconsai/nsfw_image_detection"]

dtype

str

"float16"

模型推理精度选择。可选值:["float16", "float32"]

sample_mode

str

"by_count_uniform"

采样模式。可选值:["by_count_uniform", "by_interval_time", "by_interval_frames", "by_fps", "by_timestamps"]

start_time_sec

float

0.0

采样起始时间(秒)。

end_time_sec

float or None

None

采样结束时间(秒),None 表示到视频末尾。

count_k

int or None

None

均匀采样帧数(by_count_uniform 使用)。

interval_sec

float or None

None

时间间隔(秒,by_interval_time 使用)。

interval_frames

int or None

None

解码帧间隔(by_interval_frames 使用)。

target_fps

float or None

None

目标采样 FPS(by_fps 使用)。

timestamps_sec

list[float] or None

None

采样时间戳列表(秒,by_timestamps 使用)。

max_frames

int or None

None

返回帧上限,None 表示不限制。

reduce_mode

str

"avg"

多帧聚合策略。可选值:["avg", "max", "min"]

video_format

str

"mp4"

二进制/base64 输入的视频格式。

batch_size

int

16

批量推理的帧数量。

rank

int

0

GPU 编号。

调用示例

下面的代码展示了如何使用 Daft(适用于分布式)运行算子对视频进行安全性检测。

from __future__ import annotations

import os

import daft
from daft import col
from daft.las.functions.udf import las_udf
from daft.las.functions.video.video_nsfw_detect import VideoNsfwDetect

if __name__ == "__main__":
    if os.getenv("DAFT_RUNNER", "native") == "ray":
        import logging

        import ray

        def configure_logging():
            logging.basicConfig(
                level=logging.INFO,
                format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
                datefmt="%Y-%m-%d %H:%M:%S.%s".format(),
            )
            logging.getLogger("tracing.span").setLevel(logging.WARNING)
            logging.getLogger("daft_io.stats").setLevel(logging.WARNING)
            logging.getLogger("DaftStatisticsManager").setLevel(logging.WARNING)
            logging.getLogger("DaftFlotillaScheduler").setLevel(logging.WARNING)
            logging.getLogger("DaftFlotillaDispatcher").setLevel(logging.WARNING)

        ray.init(dashboard_host="0.0.0.0", runtime_env={"worker_process_setup_hook": configure_logging})
        daft.context.set_runner_ray()

    daft.set_execution_config(actor_udf_ready_timeout=600)
    daft.set_execution_config(min_cpu_per_task=0)

    tos_dir_url = os.getenv("TOS_DIR_URL", "las-cn-beijing-public-online.tos-cn-beijing.volces.com")
    samples = {
        "video_path": [
            f"https://{tos_dir_url}/public/shared_video_dataset/eating_56.mp4"
        ]
    }

    video_src_type = "video_url"
    model_path = os.getenv("MODEL_PATH", "/opt/las/models")
    model_name = "Falconsai/nsfw_image_detection"
    num_gpus = 0

    ds = daft.from_pydict(samples)
    ds = ds.with_column(
        "nsfw",
        las_udf(
            VideoNsfwDetect,
            construct_args={
                "model_path": model_path,
                "video_src_type": video_src_type,
                "sample_mode": "by_count_uniform",
                "count_k": 3,
            },
            num_gpus=num_gpus,
            batch_size=1,
            concurrency=1,
        )(col("video_path")),
    )

    ds.show()

    # ╭────────────────────────────────┬──────────╮
    # │ video_path                     ┆ nsfw     │
    # │ ---                            ┆ ---      │
    # │ Utf8                           ┆ Float64  │
    # ╞════════════════════════════════╪══════════╡
    # │ https://las-cn-beijing-public… ┆ 0.000684 │
    # ╰────────────────────────────────┴──────────╯
、、、
最近更新时间:2026.01.08 19:14:20
这个页面对您有帮助吗?
有用
有用
无用
无用