You need to enable JavaScript to run this app.
Lake AI Service

Lake AI Service

Copy page
Download PDF
Image processing
Image face detection
Copy page
Download PDF
Image face detection

Operator introduction

Description

Image face detection operator

Main features

  • Automatically detects faces in images and returns a list of bounding rectangles (x, y, w, h)
  • Supports multiple input methods including URL, local path, Base64, and binary
  • Outputs a list of face bounding rectangles
  • Can run in both CPU and GPU environments

Applicable scenarios

  • Privacy compliance: Desensitize and mask faces in images before publishing
  • Data preprocessing: Generate versions of training or evaluation datasets with face bounding rectangles
  • Content review/display: Automatically process images containing sensitive faces with bounding rectangles

Caution

  • If processing of a single sample fails, the result for that sample returns None and does not affect other samples in the same batch

Daft invocation

Operator parameters

Input

Input column name

Note

images

The input image column, with content type determined by image_src_type:

  • image_url: Each element is a string URL, local path, or TOS path
  • image_base64: Each element is a Base64-encoded string
  • image_binary: Each element is image binary data (bytes)

Output

A structured result array, where each element is a list of face bounding boxes detected in the image.

  • Each bounding box is a quadruple (x1, y1, x2, y2), representing the coordinates of the top-left and bottom-right corners.
  • If no face is detected in the image, the corresponding element is None.

Parameters

If a parameter does not have a default value, it is required

Parameter name

Type

Default value

Description

model_path

str

"/opt/las/models"

The base directory path of the face detection model, used for loading the InsightFace model.

model_name

str

"insightface"

The subdirectory name of the InsightFace model, used to concatenate the actual model path model_path/model_name.

image_src_type

str

"image_url"

The data type of the input image. Optional values: "image_url", "image_base64", "image_binary".

det_thresh

float

0.5

InsightFace face detection confidence threshold. Recommendation: For privacy masking scenarios, lower the threshold to reduce missed detections; for fine retouching, increase the threshold to reduce false detections.

det_size

tuple[int, int]

(640, 640)

InsightFace face detection input size (width, height). Use the default value for regular web images, avatars, and so on.

Examples

The following code demonstrates how to use daft to run the operator for face detection in images.

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.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]] │
    # ╰────────────────────────────────┴──────────────────────╯
Last updated: 2026.05.12 19:06:37