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.59k stars 510 forks source link

YOLO-NAS save prediction under same file name or filename +pred, IMAGES :question: #1390

Closed 885narrow closed 1 year ago

885narrow commented 1 year ago

💡 Your Question

Is it possible in model.prediction to use the original file name to store ? when accessing prediction results and something was predicted I want to save to same file name.

https://github.com/Deci-AI/super-gradients/blob/classification_predict/documentation/source/ModelPredictions.md

out.save() they are stored with new names pred_1.jpg etc.

access original file name as well here!:

`for image_prediction in images_predictions: class_names = image_prediction.class_names labels = image_prediction.prediction.labels confidence = image_prediction.prediction.confidence bboxes = image_prediction.prediction.bboxes_xyxy

for i, (label, conf, bbox) in enumerate(zip(labels, confidence, bboxes)):
    print("prediction: ", i)
    print("label_id: ", label)
    print("label_name: ", class_names[int(label)])
    print("confidence: ", conf)
    print("bbox: ", bbox)
    print("--" * 10)

    # You can use the detection results for various tasks, such as:
    # - Filtering objects based on confidence scores or labels
    # - Analyzing object distributions within the images
    # - Calculating object dimensions or areas
    # - Implementing custom visualization techniques
    # - ...`

Thank you for your help and time.

Versions

No response

bit-scientist commented 1 year ago

I tested with some images by referring to the Using Pretrained Models for Predictions.

Take a look at this and let me know if it helps:

from super_gradients.common.object_names import Models
from super_gradients.training import models
import ntpath

model = models.get(Models.YOLO_NAS_L, pretrained_weights="coco")

IMAGES = [
    "D:/super-gradients/images/image_person.bmp",
    "D:/super-gradients/images/image_bus.jpg",
    "D:/super-gradients/images/122021417432646.bmp",
]

images_predictions = model.predict(IMAGES, iou=0.5, conf=0.7)

for i, prediction in enumerate(images_predictions):
    image_output_path = ntpath.join("output_folder", f"{ntpath.basename(IMAGES[i])}")
    prediction.save(output_path=image_output_path)
885narrow commented 1 year ago

Thank you very much, that's how it works.