Deci-AI / super-gradients

Easily train or fine-tune SOTA computer vision models with one open source training library. The home of Yolo-NAS.
https://www.supergradients.com
Apache License 2.0
4.54k stars 496 forks source link

TypeError: 'ImageDetectionPrediction' object is not iterable #1796

Closed rvryan67 closed 8 months ago

rvryan67 commented 8 months ago

🐛 Describe the bug

I'm getting the following error with latest version 3.6.

I wasn't getting this error in version 3.5

TypeError: 'ImageDetectionPrediction' object is not iterable

model_predictions = yolo_nas.predict(url, conf=0.5, iou=0.1, fuse_model=False) for p in model_predictions: bboxes = p.prediction.bboxes_xyxy


TypeError Traceback (most recent call last) Cell In[36], line 33 29 model_predictions = yolo_nas.predict(url, conf=conf, iou=0.1, fuse_model=False) 31 print(type(model_predictions)) ---> 33 for p in model_predictions: 34 bboxes = p.prediction.bboxes_xyxy 36 print (model_predictions)

TypeError: 'ImageDetectionPrediction' object is not iterable

<class 'super_gradients.training.utils.predict.prediction_results.ImageDetectionPrediction'>

Versions

-

BloodAxe commented 8 months ago

Since 3.6 when input is a single image, the prediction result is not iterable object anymore. No need in for p in model_predictions:

model_predictions = yolo_nas.predict(url, conf=conf, iou=0.1, fuse_model=False)
model_predictions.prediction.bboxes_xyxy
ZIDANE2003 commented 8 months ago

How do I get detected labels in print format,as in 3.5 version we can use loop to get that but In latest version it is producing an error using loop so how we can get detected objects in output format

BloodAxe commented 8 months ago

https://github.com/Deci-AI/super-gradients/issues/1801#issuecomment-1916521475 Please see the solution here

usmanyaqoob49 commented 6 months ago

anyone who have solved it>??

teux4545 commented 5 months ago

I don't know if it useful or not, but I was having same error and surrounded with try except worked for me:

for image_name, image in ds.images.items():
  try:
    result = best_model.predict(image, conf=CONFIDENCE_TRESHOLD, fuse_model=False)
  except ImageDetectionPrediction as ecc:
    print("ERROR: ", ecc)
  detections = sv.Detections(
      xyxy=result.prediction.bboxes_xyxy,
      confidence=result.prediction.confidence,
      class_id=result.prediction.labels.astype(int)
  )
  predictions[image_name] = detections