Code Monkey home page Code Monkey logo

Comments (5)

NatanBagrov avatar NatanBagrov commented on July 19, 2024 1

How to find the class names of the pre-trained model. Here the label is a numeric value.

Addressed in #930

from super-gradients.

dagshub avatar dagshub commented on July 19, 2024

Join the discussion on DagsHub!

from super-gradients.

Louis-Dupont avatar Louis-Dupont commented on July 19, 2024

Hi @ngocnd2402, when you run a prediction, you get an object which includes all the predictions of all the images/videos you processed. This object can easily be accessed like this:

# Download the video to the local file system.
with open(video_path, mode="wb") as f:
    response = requests.get("https://deci-pretrained-models.s3.amazonaws.com/sample_images/pose_elephant_flip.mp4")
    f.write(response.content)

video_predictions = model.predict(video_path)

for frame_prediction in video_predictions:
    image = frame_prediction.image
    labels = frame_prediction.prediction.labels
    confidence = frame_prediction.prediction.confidence
    bboxes = frame_prediction.prediction.bboxes_xyxy
    print(image.shape, labels.shape, confidence.shape, bboxes.shape)

This also applies to images:

IMAGES = [
    "../../../../documentation/source/images/examples/countryside.jpg",
    "../../../../documentation/source/images/examples/street_busy.jpg",
    "https://cdn-attachments.timesofmalta.com/cc1eceadde40d2940bc5dd20692901371622153217-1301777007-4d978a6f-620x348.jpg",
]
images_predictions = model.predict(IMAGES)

for image_prediction in images_predictions:
    image = image_prediction.image
    labels = image_prediction.prediction.labels
    confidence = image_prediction.prediction.confidence
    bboxes = image_prediction.prediction.bboxes_xyxy
    print(image.shape, labels.shape, confidence.shape, bboxes.shape)

Note that when working with a single image, you will still get the same prediction object (iterable of per-image prediction). To get this single image prediction you can do the following:

url = "https://cdn-attachments.timesofmalta.com/cc1eceadde40d2940bc5dd20692901371622153217-1301777007-4d978a6f-620x348.jpg"
images_predictions = model.predict(url)
image_prediction = next(iter(images_predictions))

image = image_prediction.image
labels = image_prediction.prediction.labels
confidence = image_prediction.prediction.confidence
bboxes = image_prediction.prediction.bboxes_xyxy
print(image.shape, labels.shape, confidence.shape, bboxes.shape)

And if you need per-box, you can iterate over labels/confidence/bboxes using zip:

for i, (label, conf, bbox) in enumerate(zip(labels, confidence, bboxes)):
    print("prediction: ", i)
    print("label: ", label)
    print("confidence: ", conf)
    print("bbox: ", bbox)
    print('--' * 10)

Hoping this helps :)

from super-gradients.

maninka123 avatar maninka123 commented on July 19, 2024

How to find the class names of the pre-trained model. Here the label is a numeric value.

from super-gradients.

Louis-Dupont avatar Louis-Dupont commented on July 19, 2024

Tutorial was released with answers to the questions mentioned in this issue, so I'm closing it :)

from super-gradients.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.