update DINO-X api usage to dds v2

This commit is contained in:
rentainhe
2025-04-20 01:04:26 +08:00
parent 3c5a4136d4
commit d49257700a
3 changed files with 43 additions and 33 deletions

View File

@@ -1,10 +1,7 @@
# dds cloudapi for Grounding DINO 1.5
# dds cloudapi for Grounding DINO 1.5 - 更新至V2Task API
from dds_cloudapi_sdk import Config
from dds_cloudapi_sdk import Client
from dds_cloudapi_sdk import DetectionTask
from dds_cloudapi_sdk import TextPrompt
from dds_cloudapi_sdk import DetectionModel
from dds_cloudapi_sdk import DetectionTarget
from dds_cloudapi_sdk.tasks.v2_task import V2Task
import os
import cv2
@@ -31,6 +28,7 @@ SAVE_TRACKING_RESULTS_DIR = "./tracking_results"
API_TOKEN_FOR_GD1_5 = "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
@@ -99,33 +97,38 @@ config = Config(API_TOKEN_FOR_GD1_5)
# 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 = DetectionTask(
image_url=image_url,
prompts=[TextPrompt(text=TEXT_PROMPT)],
targets=[DetectionTarget.BBox], # detect bbox
model=DetectionModel.GDino1_6_Pro, # detect with GroundingDino-1.5-Pro model
bbox_threshold=BOX_THRESHOLD,
task = V2Task(
api_path="/v2/task/grounding_dino/detection",
api_body={
"model": "GroundingDino-1.5-Pro",
"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 = []
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)