update DINO-X api usage to dds v2
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
# dds cloudapi for Grounding DINO 1.5
|
||||
# dds cloudapi for DINO-X - update to V2Task API
|
||||
from dds_cloudapi_sdk import Config
|
||||
from dds_cloudapi_sdk import Client
|
||||
from dds_cloudapi_sdk.tasks.dinox import DinoxTask
|
||||
from dds_cloudapi_sdk.tasks.types import DetectionTarget
|
||||
from dds_cloudapi_sdk import TextPrompt
|
||||
from dds_cloudapi_sdk.tasks.v2_task import V2Task
|
||||
|
||||
import os
|
||||
import cv2
|
||||
@@ -30,6 +28,7 @@ SAVE_TRACKING_RESULTS_DIR = "./tracking_results"
|
||||
API_TOKEN_FOR_DINOX = "Your API token"
|
||||
PROMPT_TYPE_FOR_VIDEO = "box" # choose from ["point", "box", "mask"]
|
||||
BOX_THRESHOLD = 0.2
|
||||
IOU_THRESHOLD = 0.8 # 添加IOU阈值参数
|
||||
|
||||
"""
|
||||
Step 1: Environment settings and model initialization for SAM 2
|
||||
@@ -98,22 +97,29 @@ config = Config(API_TOKEN_FOR_DINOX)
|
||||
# Step 2: initialize the client
|
||||
client = Client(config)
|
||||
|
||||
# Step 3: run the task by DetectionTask class
|
||||
# image_url = "https://algosplt.oss-cn-shenzhen.aliyuncs.com/test_files/tasks/detection/iron_man.jpg"
|
||||
# Step 3: run the task using V2Task class
|
||||
# if you are processing local image file, upload them to DDS server to get the image url
|
||||
image_url = client.upload_file(img_path)
|
||||
|
||||
task = DinoxTask(
|
||||
image_url=image_url,
|
||||
prompts=[TextPrompt(text=TEXT_PROMPT)],
|
||||
bbox_threshold=0.25,
|
||||
targets=[DetectionTarget.BBox],
|
||||
task = V2Task(
|
||||
api_path="/v2/task/dinox/detection",
|
||||
api_body={
|
||||
"model": "DINO-X-1.0",
|
||||
"image": image_url,
|
||||
"prompt": {
|
||||
"type": "text",
|
||||
"text": TEXT_PROMPT
|
||||
},
|
||||
"targets": ["bbox"],
|
||||
"bbox_threshold": BOX_THRESHOLD,
|
||||
"iou_threshold": IOU_THRESHOLD,
|
||||
}
|
||||
)
|
||||
|
||||
client.run_task(task)
|
||||
result = task.result
|
||||
|
||||
objects = result.objects # the list of detected objects
|
||||
objects = result["objects"] # the list of detected objects
|
||||
|
||||
|
||||
input_boxes = []
|
||||
@@ -121,9 +127,9 @@ confidences = []
|
||||
class_names = []
|
||||
|
||||
for idx, obj in enumerate(objects):
|
||||
input_boxes.append(obj.bbox)
|
||||
confidences.append(obj.score)
|
||||
class_names.append(obj.category)
|
||||
input_boxes.append(obj["bbox"])
|
||||
confidences.append(obj["score"])
|
||||
class_names.append(obj["category"])
|
||||
|
||||
input_boxes = np.array(input_boxes)
|
||||
|
||||
|
Reference in New Issue
Block a user