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

Lake AI Service

Copy page
Download PDF
Image vectorization
Image embedding (ViT series models)
Copy page
Download PDF
Image embedding (ViT series models)

Operator introduction

Description

ViT image semantic embedding processor, suitable for image similarity search, content retrieval, and related scenarios.

Key features

  • Multi-model support:
    • Google official ViT models
    • Meta DINOv2 vision models
  • Feature extraction modes:
    • CLS token embedding vector
    • Global average pooling
  • Input format compatibility:
    • URL
    • Base64 encoding
    • Binary stream
  • Performance optimization:
    • FP16 inference acceleration
    • Multi-GPU parallel computation

Fault tolerance mechanism

  • Returns an all-zero vector when extraction fails

  • google/vit-base-patch16-224-in21k (768 dimensions)
  • google/vit-large-patch16-224-in21k (1024 dimensions)
  • facebook/dinov2-base (768 dimensions)
  • facebook/dinov2-large (1024 dimensions)

Daft invocation

Operator parameters

Input

Input column name

Description

images

An array containing image data. The element type can be image URL, Base64 encoding, or binary data

Output

An array containing feature vectors. Each element is a nested array of float type,
The array dimensions are determined by the model output

Parameters

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

Parameter name

Type

Default value

Description

image_src_type

str

image_url

Input image format type. Supported types: - tos/http address (image_url) - base64 encoding (image_base64) - binary stream (image_binary) Optional values: ["image_url", "image_base64", "image_binary"] Default value: "image_url"

dtype

str

float32

Model inference precision selection: - bfloat16: balances precision and speed (faster on TPU) - float16: faster inference speed - float32: highest precision but maximum memory consumption Optional values: ["bfloat16", "float16", "float32"] Default value: "float16"

batch_size

int

32

Batch size. Default value: 32

model_path

str

/opt/las/models

Model file storage path. Default value: "/opt/las/models"

model_name

str

facebook/dinov2-large

Name of the image vector model used. Optional values: [ "google/vit-base-patch16-224-in21k", "google/vit-large-patch16-224-in21k", "facebook/dinov2-base", "facebook/dinov2-large" ] Default value: "facebook/dinov2-large"

use_cls_token_embedding

bool

True

Whether to use CLS token features. Default value: True

rank

int

0

Specify the GPU device number to use (effective in multi-card environments). For example: 0 indicates the first GPU, 1 indicates the second GPU. Default value: 0

Examples

The following code demonstrates how to use daft to run the operator and compute image embeddings.

from __future__ import annotations

import logging
import os

import ray

import daft
from daft import col
from daft.las.functions.image.embedding.image_vit_embedding import ImageViTEmbedding
from daft.las.functions.udf import las_udf

if __name__ == "__main__":

    if os.getenv("DAFT_RUNNER", "ray") == "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)

        import ray

        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": [
            f"https://{tos_dir_url}/public/shared_image_dataset/cat_ip_adapter.jpeg"
        ]
    }

    image_src_type = "image_url"
    batch_size = 64
    model_path = os.getenv("MODEL_PATH", "/opt/las/models")
    model_name = "google/vit-base-patch16-224-in21k"
    dtype = "float32"
    use_cls_token_embedding = True
    rank = 0
    num_gpus = 1

    ds = daft.from_pydict(samples)
    ds = ds.with_column(
        "embedding",
        las_udf(
            ImageViTEmbedding,
            construct_args={
                "image_src_type": image_src_type,
                "batch_size": batch_size,
                "model_path": model_path,
                "model_name": model_name,
                "dtype": dtype,
                "use_cls_token_embedding": use_cls_token_embedding,
                "rank": rank,
            },
            num_gpus=num_gpus,
            batch_size=1,
        )(col("image")),
    )

    ds.show()

    # ╭────────────────────────────────┬────────────────────────────────╮
    # │ image                          ┆ embedding                      │
    # │ ---                            ┆ ---                            │
    # │ Utf8                           ┆ List[Float32]                  │
    # ╞════════════════════════════════╪════════════════════════════════╡
    # │ tos://las-cn-beijing-public-o… ┆[-0.011575016, -0.019808339, …  │
    # ╰────────────────────────────────┴────────────────────────────────╯
Last updated: 2026.05.12 19:06:31