Issue with inferencing results in JSON format

I have build an Object Detection Model. I am trying to test model and JSON values it returns using following ways.

  1. Try This model option on Dataset Version tab
  2. Try This Model Option from Deploy Tab
  3. Python Code
  1. when I use Try This model from Dataset Version Tab as in image 1 below


Image 1

I get JSON values as following (image 2)


Image 2

  1. But when I use Try This Model Option from Deploy tab there are different JSON values for the same image (in following image)


Image 3

  1. And the python code print(model.predict("/content/50.jpg", confidence=80, overlap=50).json()) also prints these same values (as in image 3)
{
  "predictions": [
    {
      "x": 428.0,
      "y": 294.5,
      "width": 280.0,
      "height": 395.0,
      "confidence": 0.9443135261535645,
      "class": "plant",
      "class_id": 0,
      "image_path": "50.jpg",
      "prediction_type": "ObjectDetectionModel"
    },
    {
      "x": 86.0,
      "y": 450.5,
      "width": 26.0,
      "height": 137.0,
      "confidence": 0.8782252073287964,
      "class": "ref_obj",
      "class_id": 1,
      "image_path": "50.jpg",
      "prediction_type": "ObjectDetectionModel"
    }
  ],
  "image": {
    "width": "800",
    "height": "800"
  }
}

Why there are different values? When I use any of these JSON values in my own python code to create bounding boxes, I always get wrong orientation. It means there is a bug in returning these JSON values.

see the following output from my code for creating bounding boxes using above JSON values.


Image 4

According to my calculation the roboflow python code and interface should return following JSON values for my image

{
  "predictions": [
    {
      "x": 288.0,
      "y": 97.5,
      "width": 280.0,
      "height": 395.0,
      "confidence": 0.9443135261535645,
      "class": "plant",
      "class_id": 0,
      "image_path": "50.jpg",
      "prediction_type": "ObjectDetectionModel"
    },
    {
      "x": 72.0,
      "y": 382.0,
      "width": 26.0,
      "height": 137.0,
      "confidence": 0.8782252073287964,
      "class": "ref_obj",
      "class_id": 1,
      "image_path": "50.jpg",
      "prediction_type": "ObjectDetectionModel"
    }
  ],
  "image": {
    "width": "800",
    "height": "800"
  }
}

then I’ll get correct bounding box by using these JSON values as following


Image 5

All the three JSON values that Roboflow interface gives is incorrect. Request you to please resolve this issue ASAP.

Hi @Timothy_Malche

Sorry to hear that you’re having trouble. The reason for the difference in your methods 1 & 2 is due to one running on your device (using roboflow.js) and the other running on our hosted inference API.

For method 3 (running in Python), there is no bug. Both our hosted inference and Python package return in the following format:

  • x = the horizontal center point of the detected object

  • y = the vertical center point of the detected object

  • width = the width of the bounding box

  • height = the height of the bounding box

  • class = the class label of the detected object

  • confidence = the model’s confidence that the detected object has the correct label and position coordinates

From the response object format section on our hosted API documentation

Note that it states x and y are the center points of the detected object. To learn how to properly visualize the bounding boxes from the inference prediction, take a look at that section on the documentation. If you are planning to do more visualization work, I recommend you use supervision and the annotators to help you visualize predictions.

1 Like

Thanks @leo. Sorry I could not pay attention that X, Y are the center coordinates. I have resolved my issue. Thanks a lot for fantastic explanation.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.