目标检测

Ready

使用 Detrium 运行目标检测,并从 Results.boxes 读取坐标、置信度与类别。

predictor.py

读取预测框

目标检测(detect)是 Detrium 当前完备实现的核心任务,统一覆盖 RT-DETRv2、D-FINE、DEIM 与 RT-DETRv4 四大架构。每次推理返回一个 Results 列表,其中的 result.boxes(Boxes)内部存储为 (N, 6) 张量 [x1, y1, x2, y2, conf, cls]。

from detrium import Detrium

model = Detrium("best.pt")
result = model("image.jpg", conf=0.3)[0]
print("像素坐标 xyxy:", result.boxes.xyxy)
print("归一化中心点 xywhn:", result.boxes.xywhn)
print("JSON 输出:", result.to_json())

Boxes 常用属性与方法

属性 / 方法 形状 / 返回类型 说明
boxes.xyxy (N, 4) Tensor 原图尺度左上角与右下角坐标 [x1, y1, x2, y2]
boxes.xywh (N, 4) Tensor 原图尺度中心点与宽高 [cx, cy, w, h]
boxes.xyxyn (N, 4) Tensor 按原图 (H, W) 归一化到 [0, 1] 的 xyxy
boxes.xywhn (N, 4) Tensor 按原图 (H, W) 归一化到 [0, 1] 的 xywh
boxes.conf (N,) Tensor 预测置信度分数
boxes.cls (N,) Tensor 预测类别索引(对应 result.names[int(c)])
boxes.numpy() np.ndarray 自动脱离计算图并移至 CPU 转 NumPy
result.to_json() str 序列化为标准 JSON 列表(含类别名、置信度与 box 坐标)

训练数据配置方法请查阅 YOLO 和 COCO 数据集格式。