0

I am running a YOLOv8x model which has been trained on custom data. I want to get the inference results in a way which looks similar to this. The below snippet is an output from running an inference on Roboflow:

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

Currently i am running the code as below, which i found on the Docs from 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))

The output from the code looks like this :

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'>

The results from the Roboflow inference are quite different as they have been run on a different image, but i would still like to have an output that looks quite similar to them. How can I achieve it?

Shonith
  • 1
  • 2

0 Answers0