从 YOLOv8 推理中获取边界框详细信息

问题描述 投票:0回答:1

我正在运行一个 YOLOv8x 模型,该模型已经过自定义数据的训练。我想以与此类似的方式获得推理结果。以下代码片段是在 Roboflow 上运行推理的输出:

{
  "predictions": [
    {
      "x": 2200.5,
      "y": 1563,
      "width": 1073,
      "height": 1194,
      "confidence": 0.899,
      "class": "Sport"
    }
  ]
}

目前我正在运行如下代码,这是我在 Ultralytics 的文档中找到的:

model = YOLO('/content/drive/MyDrive/yolov8x_mymodel.pt')

source = Image.open('/content/drive/MyDrive/test_images/image(14).png')

results = model.predict(source, save = True, conf =0.5)

boxes = results[0].boxes

box=boxes[0]
box.xyxy

print(box)
print(box.boxes)
print(type(box))

代码的输出如下所示:

0: 480x640 1 Dach Schwarz, 3446.3ms
Speed: 6.4ms preprocess, 3446.3ms inference, 1.4ms postprocess per image at shape (1, 3, 480, 640)
Results saved to runs/detect/predict12
WARNING ⚠️ 'Boxes.boxes' is deprecated. Use 'Boxes.data' instead.
WARNING ⚠️ 'Boxes.boxes' is deprecated. Use 'Boxes.data' instead.
ultralytics.engine.results.Boxes object with attributes:

boxes: tensor([[458.7760, 160.1197, 825.7375, 444.8633,   0.8278,   2.0000]])
cls: tensor([2.])
conf: tensor([0.8278])
data: tensor([[458.7760, 160.1197, 825.7375, 444.8633,   0.8278,   2.0000]])
id: None
is_track: False
orig_shape: (768, 1024)
shape: torch.Size([1, 6])
xywh: tensor([[642.2567, 302.4915, 366.9615, 284.7436]])
xywhn: tensor([[0.6272, 0.3939, 0.3584, 0.3708]])
xyxy: tensor([[458.7760, 160.1197, 825.7375, 444.8633]])
xyxyn: tensor([[0.4480, 0.2085, 0.8064, 0.5792]])
tensor([[458.7760, 160.1197, 825.7375, 444.8633,   0.8278,   2.0000]])
<class 'ultralytics.engine.results.Boxes'>

Roboflow 推理的结果非常不同,因为它们在不同的图像上运行,但我仍然希望有一个看起来与它们非常相似的输出。我怎样才能实现它?

python object-detection yolo bounding-box yolov8
1个回答
0
投票

你能解决这个问题吗?

© www.soinside.com 2019 - 2024. All rights reserved.