Image face blur processing operator
Input column name | Note |
|---|---|
images | Input image column. Depending on the value of the |
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. |
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.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 |
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 |
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". |
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… │ # ╰────────────────────────────────┴────────────────────────────────────────────────────────────────────────────────────╯