Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Top k predictions in output? #5

@mihow

Description

@mihow

Hello, thanks for the great library! Is it possible to return the top k predictions in the output for the ResNet18 image classification example? And is it possible to include their confidence score? This is what I am currently doing in PyTorch:

predict_values = model(input_object)
preds = torch.nn.functional.softmax(predict_values, dim=1)

# Get top 5 results
top_k = 5
top_preds_raw = preds.topk(top_k)

top_preds = [
    {"label": DEFAULT_MODEL_CLASSES[i], "score": float(score)}
    for i, score in zip(top_preds_raw.indices[0], top_preds_raw.values[0])
]

return top_preds

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions