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

AttributeError: 'DetectionPrediction' object has no attribute 'class_names' #1680

Closed amans30 closed 10 months ago

amans30 commented 10 months ago

🐛 Describe the bug


AttributeError Traceback (most recent call last) in <cell line: 10>() 8 bboxes = prediction.bboxes_xyxy # [[Xmin,Ymin,Xmax,Ymax],..] list of all annotation(s) for detected object(s) 9 bboxes = prediction.bboxes_xyxy # [[Xmin,Ymin,Xmax,Ymax],..] list of all annotation(s) for detected object(s) ---> 10 class_names = prediction.class_names # ['Class1', 'Class2', ...] List of the class names 11 class_name_indexes = prediction.labels.astype(int) # [2, 3, 1, 1, 2, ....] Index of each detected object in class_names(corresponding to each bounding box) 12 confidences = prediction.confidence.astype(float) # [0.3, 0.1, 0.9, ...] Confidence value(s) in float for each bounding boxes

AttributeError: 'DetectionPrediction' object has no attribute 'class_names'

@BloodAxe @avideci @spsancti @shaydeci @Louis-Dupont @hakuryuu96

Versions

import super_gradients

yolo_nas = super_gradients.training.models.get("yolo_nas_l", pretrained_weights="coco") model_predictions = yolo_nas.predict("https://deci-pretrained-models.s3.amazonaws.com/sample_images/beatles-abbeyroad.jpg")

prediction = model_predictions[0].prediction # One prediction per image - Here we work with 1 image so we get the first.

bboxes = prediction.bboxes_xyxy # [[Xmin,Ymin,Xmax,Ymax],..] list of all annotation(s) for detected object(s) bboxes = prediction.bboxes_xyxy # [[Xmin,Ymin,Xmax,Ymax],..] list of all annotation(s) for detected object(s) class_names = prediction.class_names # ['Class1', 'Class2', ...] List of the class names class_name_indexes = prediction.labels.astype(int) # [2, 3, 1, 1, 2, ....] Index of each detected object in class_names(corresponding to each bounding box) confidences = prediction.confidence.astype(float) # [0.3, 0.1, 0.9, ...] Confidence value(s) in float for each bounding boxes

BloodAxe commented 10 months ago

This is because you are overwriting variable and prediction = model_predictions[0].prediction

model_predictions = model.predict(...)
p = model_predictions[0] # Single image

p.class_names            # Class names
p.prediction.bboxes_xyxy # Yes, prediction.prediction looks silly but this is how it's done now
amans30 commented 10 months ago

Why p.class_names is giving the list of all the class. I want the list of the class names which model has detected in the image.

['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush']

BloodAxe commented 10 months ago

Class names here correspond to all available classes the model was trained on. Just iterate over detection labels and take name at corresponding indexes.