ultralytics / ultralytics

NEW - YOLOv8 🚀 in PyTorch > ONNX > OpenVINO > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
23.76k stars 4.74k forks source link

cant get bounding box cords while using sahi only without #11649

Open mohammdkaraca opened 1 week ago

mohammdkaraca commented 1 week ago

Search before asking

Question

hi, im really new to this so im sorry if this is a dumb question. I am trying to print the cords of the bounding boxes of each object detected but it wont work with sahi im getting this eror"'PredictionResult' object is not subscriptable" I can print out the cords fine without it but it wont work while using it again im sorry if its a dumb question thanks in advanced.(I added the code in a txt file) github_question.txt

Additional

No response

github-actions[bot] commented 1 week ago

👋 Hello @mohammdkaraca, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users.

Install

Pip install the ultralytics package including all requirements in a Python>=3.8 environment with PyTorch>=1.8.

pip install ultralytics

Environments

YOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

glenn-jocher commented 1 week ago

Hello! No question is a dumb question here, we're all learning! 😊 The error you're seeing, "'PredictionResult' object is not subscriptable," usually means that you are trying to access the results in a way that the object type does not support.

When using YOLOv8 with SAHI, make sure you are accessing the properties of the PredictionResult correctly. For instance, if you are trying to access the bounding box coordinates, you should utilize the methods provided by the PredictionResult object to pull these details, rather than directly indexing the object like a list or dictionary.

Here's a generic example of how you might retrieve bbox coordinates from a YOLOv8 prediction result:

# Assuming 'results' is your PredictionResult object
for detection in results.detections:
    print("Bounding Box:", detection.bbox)
    print("Confidence:", detection.confidence)
    print("Class ID:", detection.class_id)

Make sure to replace results.detections with the actual attribute or method your 'results' object provides for accessing detections. Each detection typically has attributes like bbox, confidence, and class_id.

If you need more specific help, please provide the snippet of your code where you handle the result processing, and we can give more targeted advice!