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

Lake AI Service

Copy page
Download PDF
Image processing
Image face blur
Copy page
Download PDF
Image face blur

Operator introduction

Description

Image face blur processing operator

Main features

  • Automatically detects faces in images and applies blur processing
  • Supports multiple blur types (mean, box, Gaussian)
  • Supports multiple input methods, including URL, local path, Base64, and binary
  • Optionally outputs the Base64 encoding of the blurred image and the path where it is saved
  • Can run in both CPU and GPU environments

Applicable scenarios

  • Privacy compliance: Anonymize and blur faces in images before publishing
  • Data preprocessing: Generate versions of training or evaluation datasets with blurred faces
  • Content review/display: Automatically blur faces in images with sensitive faces

Caution

  • If processing fails for a single sample, the result for that item returns {"base64": None, "image_path": None}, and other samples in the same batch are not affected
  • When output_dir is configured, the blurred images will be uploaded to the specified TOS directory or saved to the local directory

Daft invocation

Operator parameters

Input

Input column name

Note

images

Input image column. Depending on the value of the image_src_type parameter, the content can be an image URL/path, Base64 string, or binary data.

images_name

Optional column, the logical name or identifier of the image, used as the prefix for the output file name; the suffix does not need to be included.

Output

An array of processing results, where each element includes:

  • base64 (str | None): Base64 encoding of the blurred image.
  • image_path (str | None): Local or TOS path of the blurred image; if saving fails or saving is not configured, returns None.
  • face_bounding_boxes (list[tuple[int, int, int, int]] | None): List of detected face bounding boxes (x, y, w, h); returns None if no faces are detected or processing fails.

Parameters

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

Parameter name

Type

Default value

Description

output_dir

str

""

The TOS directory or local path where the blurred images are saved, format: "tos://bucket/path/" or "/local/path/".

model_path

str

"/opt/las/models"

Base directory path of the face detection model.

model_name

str

"insightface"

Subdirectory name of the InsightFace model, combined with model_path to form the complete path.

image_src_type

str

"image_url"

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

blur_type

str

"gaussian"

Blur method for the face region. Optional values: "mean", "box", "gaussian".

radius

float

10.0

Blur radius, used in "box" and "gaussian" modes. Requires radius >= 0.

det_thresh

float

0.5

Face detection confidence threshold.

det_size

tuple[int, int]

(640, 640)

Input size (width, height) for face detection.

return_base64

bool

False

Whether to include the Base64 encoding of the image in the output.

return_image_format

str

"png"

Output image format. Optional values: "png", "jpg", "jpeg".

Examples

The following code demonstrates how to use daft to run the operator and blur faces in images.

from __future__ import annotations

import os

import daft
from daft import col
from daft.las.functions.image import ImageFaceBlur
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,
        "blur_type": "gaussian",
        "radius": 20.0,
        "return_base64": True
    }

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

    ds.show()

    # ╭────────────────────────────────┬────────────────────────────────────────────────────────────────────────────────────╮
    # │ image_path                     ┆ results                                                                            │
    # │ ---                            ┆ ---                                                                                │
    # │ String                         ┆ Struct[base64: String, image_path: String, face_bounding_boxes: List[List[Int32]]] │
    # ╞════════════════════════════════╪════════════════════════════════════════════════════════════════════════════════════╡
    # │https://las-cn-beijing-public…  ┆ {base64: iVBORw0KGgoAAAANSUhE…                                                     │
    # ╰────────────────────────────────┴────────────────────────────────────────────────────────────────────────────────────╯
Last updated: 2026.05.12 19:06:37