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

AI 数据湖服务

复制全文
图片处理
图片人脸检测
复制全文
图片人脸检测

算子介绍

描述

图片人脸检测算子

主要功能

  • 自动检测图片中的人脸并返回矩形框列表 (x, y, w, h)
  • 支持 URL、本地路径、Base64、二进制等多种输入方式
  • 输出人脸矩形框列表
  • cpu 和 gpu 环境均可运行

适用场景

  • 隐私合规:发布前对图片中的人脸进行脱敏打码
  • 数据预处理:为训练/评测数据集生成带人脸矩形框的版本
  • 内容审核/展示:对涉及敏感人脸的图片进行自动矩形框处理

注意事项

  • 单条样本处理失败时,该条结果返回 None,不影响同一批次内其他样本

Daft 调用

算子参数

输入

输入列名

说明

images

输入图片列,内容类型由 image_src_type 决定:
- image_url: 每个元素为字符串 URL/本地路径/TOS 路径
- image_base64: 每个元素为 Base64 编码字符串
- image_binary: 每个元素为图片二进制数据(bytes)

输出

一个结构化结果数组,其中每个元素为图片中检测到的人脸边界框列表。

  • 每个边界框为一个四元组 (x1, y1, x2, y2),表示左上角和右下角坐标。
  • 如果图片中未检测到人脸,则对应元素为 None

参数

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

参数名称

类型

默认值

描述

model_path

str

"/opt/las/models"

人脸检测模型的基础目录路径,用于 InsightFace 模型加载。

model_name

str

"insightface"

InsightFace 模型子目录名称,用于拼接实际模型路径 model_path/model_name

image_src_type

str

"image_url"

输入图片的数据类型。可选值:"image_url"、"image_base64"、"image_binary"。

det_thresh

float

0.5

InsightFace 人脸检测置信度阈值。建议:隐私打码场景可适当降低以减少漏检,精细修图可提高以减少误检。

det_size

tuple[int, int]

(640, 640)

InsightFace 人脸检测输入尺寸 (width, height)。普通网络图片/头像等使用默认值即可。

调用示例

下面的代码展示了如何使用 daft 运行算子对图像中的人脸做检测。

from __future__ import annotations

import os

import daft
from daft import col
from daft.las.functions.image import ImageFaceDetect
from daft.las.functions.udf import las_udf

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 = {"image_path": [f"https://{tos_dir_url}/public/shared_image_dataset/mengnalisa.png"]}
    ds = daft.from_pydict(samples)

    model_path = os.getenv("MODEL_PATH", "/opt/las/models")
    constructor_kwargs = {
        "model_path": model_path,
    }

    ds = ds.with_column(
        "face_bounding_boxes",
        las_udf(
            ImageFaceDetect,
            construct_args=constructor_kwargs,
            num_gpus=0,
            batch_size=1,
            concurrency=1,
        )(col("image_path")),
    )

    ds.show()

    # ╭────────────────────────────────┬──────────────────────╮
    # │ image_path                     ┆ face_bounding_boxes  │
    # │ ---                            ┆ ---                  │
    # │ String                         ┆ List[List[Int32]]    │
    # ╞════════════════════════════════╪══════════════════════╡
    # │ https://las-cn-beijing-public… ┆ [[99, 36, 166, 116]] │
    # ╰────────────────────────────────┴──────────────────────╯
最近更新时间:2026.01.15 18:06:19
这个页面对您有帮助吗?
有用
有用
无用
无用