Trex - Embedding Inference¶
The TRex Embedding Inference algorithm enables user inferring image and get the boxes and scores on the same image by embd files
they trained from the Embedding Customization
.
This algorithm supports batch inference for multiple images, and for every image, multiple embeddings are supported.
Usage Pattern¶
First of all, make sure you have installed this SDK by pip:
pip install dds-cloudapi-sdk
Then trigger the customization algorithm by TRexEmbdInfer:
from dds_cloudapi_sdk import Client
from dds_cloudapi_sdk import Config
from dds_cloudapi_sdk import BatchEmbdInfer
from dds_cloudapi_sdk import BatchEmbdPrompt
from dds_cloudapi_sdk import TRexEmbdInfer
token = "You API token here"
config = Config(token)
client = Client(config)
image_url = "https://dev.deepdataspace.com/static/04_a.ae28c1d6.jpg"
embd_url = "https://url/to/your/embd/url.file" # the embd url trained from TRexEmbdCustomize Task
infer_1 = BatchEmbdInfer(
image=image_url,
prompts=[
BatchEmbdPrompt(embd=embd_url, category_id=1)
]
)
task = TRexEmbdInfer([infer_1])
client.run_task(task)
for image_objects in task.result.object_batches:
for obj in image_objects:
print(obj.score)
print(obj.bbox)
print(obj.category_id)
break
break
API Reference¶
- class TRexEmbdInfer(batch_infers)[source]¶
Trigger the Trex Embedding Inference algorithm.
This task can process prompts from multiple images, and each image can have several embedding prompts.
- Parameters:
batch_infers (List[BatchEmbdInfer]) – list of
BatchPointInfer
objects orBatchRectInfer
.
- property result: TaskResult¶
Get the formatted
TaskResult
object.
- class BatchEmbdInfer(*, image, prompts)[source]¶
An infer image with batch embd prompts.
- Parameters:
image (str) – the image url to be inferred on
prompts (List[BatchEmbdPrompt]) – a list of
BatchEmbdPrompt
- image: str¶
the image url to be inferred on
- prompts: List[BatchEmbdPrompt]¶
a list of
BatchEmbdPrompt
- class BatchEmbdPrompt(*, embd=None, category_id)[source]¶
A batch of embd prompts.
- Parameters:
embd (str) – the embedding file url
category_id (int) – the category id of the rects
- embd: str¶
the embedding file url
- category_id: int¶
the category id of the objects inferred by this embedding file
- class TaskResult(*, object_batches)[source]¶
The task result of TRexInteractiveInfer task.
- Parameters:
object_batches (List[List[TRexObject]]) – a 2D list of detected objects of
TRexObject
, each inner list is the detected objects of one image
- object_batches: List[List[TRexObject]]¶
a 2D list of detected objects of
TRexObject
, each inner list is the detected objects of one image
- class TRexObject(*, score, bbox, category_id)[source]¶
The object detected by TRexEmbdInfer task.
- Parameters:
score (float) – the prediction score
bbox (List[float]) – the bounding box, [upper_left_x, upper_left_y, lower_right_x, lower_right_y]
category_id (int) – the category id of the object
- score: float¶
the prediction score
- bbox: List[float]¶
the bounding box, [upper_left_x, upper_left_y, lower_right_x, lower_right_y]
- category_id: int¶
the category id of the object