Image face detection operator
Input column name | Note |
|---|---|
images | The input image column, with content type determined by
|
A structured result array, where each element is a list of face bounding boxes detected in the image.
(x1, y1, x2, y2), representing the coordinates of the top-left and bottom-right corners.None.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 |
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. |
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]] │ # ╰────────────────────────────────┴──────────────────────╯