图片人脸检测算子
输入列名 | 说明 |
|---|---|
images | 输入图片列,内容类型由 |
一个结构化结果数组,其中每个元素为图片中检测到的人脸边界框列表。
(x1, y1, x2, y2),表示左上角和右下角坐标。None。如参数没有默认值,则为必填参数
参数名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
model_path | str | "/opt/las/models" | 人脸检测模型的基础目录路径,用于 InsightFace 模型加载。 |
model_name | str | "insightface" | InsightFace 模型子目录名称,用于拼接实际模型路径 |
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]] │ # ╰────────────────────────────────┴──────────────────────╯