Trex - Embedding Customization

The TRex Embedding Customization algorithm enables user customizing a visual embedding file from prompts on multiple images.

The embedding file then can be used to inference images by Trex Embedding Inference algorithm.

Usage Pattern

First of all, make sure you have installed this SDK by pip:

pip install dds-cloudapi-sdk

Then trigger the customization algorithm through TRexEmbdCustomize:

from dds_cloudapi_sdk import Config
from dds_cloudapi_sdk import Client
from dds_cloudapi_sdk import BatchRectPrompt
from dds_cloudapi_sdk import TRexEmbdCustomize

# Step 1: initialize the config
token = "Your API token here"
config = Config(token)

# Step 2: initialize the client
client = Client(config)

# Step 3: run the task by TRexEmbdCustomize class
image_url = "https://dev.deepdataspace.com/static/04_a.ae28c1d6.jpg"
# if you are processing local image file, upload them to DDS server to get the image url
# image_url = client.upload_file("/path/to/your/infer/image.png")

batch_prompts = [
    BatchRectPrompt(
        image=image_url,
        rects=[[475.18413597733706, 550.1983002832861, 548.1019830028329, 599.915014164306]]
    )
]
task = TRexEmbdCustomize(
    batch_prompts=batch_prompts
)

client.run_task(task)
embd_url = task.result.embd
print(embd_url)

API Reference

class TRexEmbdCustomize(batch_prompts)[source]

Trigger the Trex Embd Customization algorithm.

This task generates an embedding file from prompts on multiple images. However, all prompts are limited to one type, either point or rect.

The task is similar to TRexGenericInfer, but it leaves the infer image out for it is generating an embedding file instead of inferring.

Parameters:

batch_prompts (List[BatchRectPrompt] | List[BatchPointPrompt]) – list of BatchRectPrompt objects or BatchPointPrompt.

property result: TaskResult

Get the formatted TaskResult object.

class BatchPointPrompt(*, points, image=None, category_id=None)[source]

A batch of point prompts.

Parameters:
  • points (List[List[float]]) – a list of point locations in [[x1, y1], [x2, y2]]

  • image (str) – the image url the point prompts are acting on, if not provided, the infer image url in context will be used

  • category_id (int) – the category id of the points

points: List[List[float]]

a list of point locations in [[x1, y1], [x2, y2]]

image: str

the image url the point prompts are acting on

category_id: int

the category id of the points, only required for TRexInteractiveInfer task.

class BatchRectPrompt(*, rects, image=None, category_id=None)[source]

A batch of rectangle prompts.

Parameters:
  • rects (List[List[float]]) – a list of rect locations in [[[upper_left_x, upper_left_y, lower_right_x, lower_right_y], …]

  • image (str) – the image url the rectangle prompts are acting on

  • category_id (int) – the category id of the rects

rects: List[List[float]]

a list of rect locations in [[[upper_left_x, upper_left_y, lower_right_x, lower_right_y], …]

image: str

the image url the rectangle prompts are acting on, if not provided, the infer image url in context will be used

category_id: int

the category id of the rects, only required for TRexInteractiveInfer task.

class TaskResult(*, embd)[source]

The task result of TRexEmbdCustomize task.

Parameters:
  • embedding (visual) – the url of the embedding file

  • embd (str)

embd: str

the url of the visual embedding file