Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add print(results) override for PyTorch Hub results #7559

Merged
merged 1 commit into from
Apr 24, 2022
Merged

Conversation

glenn-jocher
Copy link
Member

@glenn-jocher glenn-jocher commented Apr 24, 2022

Usage example:

import torch

# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')  # or yolov5m, yolov5l, yolov5x, custom

# Images
img = 'https://ultralytics.com/images/zidane.jpg'  # or file, Path, PIL, OpenCV, numpy, list

# Inference
results = model(img)

# Results
results.print()
print(results)  # <---- NEW 

# image 1/1: 720x1280 2 persons, 2 ties
# Speed: 299.5ms pre-process, 319.2ms inference, 12.9ms NMS per image at shape (1, 3, 384, 640)

πŸ› οΈ PR Summary

Made with ❀️ by Ultralytics Actions

🌟 Summary

Improved usability of model results in Ultralytics YOLOv5 with new string representation.

πŸ“Š Key Changes

  • 🧩 Added an override of the __str__ method to the Results class.
  • πŸ–¨οΈ Modified the __len__ method comment for clarity.

🎯 Purpose & Impact

  • πŸ‘οΈβ€πŸ—¨οΈ Enhances the user's visibility of results by automatically printing when using the print() function on a Results object.
  • 🌐 Provides a more Pythonic usage experience, as users expect print(object) to display useful information.
  • πŸ†’ Potentially improves debugging and logging with minimal changes to existing codebases.

@glenn-jocher glenn-jocher self-assigned this Apr 24, 2022
@glenn-jocher glenn-jocher merged commit c16671f into master Apr 24, 2022
@glenn-jocher glenn-jocher deleted the update/hub branch April 24, 2022 19:07
BjarneKuehl pushed a commit to fhkiel-mlaip/yolov5 that referenced this pull request Aug 26, 2022
ctjanuhowski pushed a commit to ctjanuhowski/yolov5 that referenced this pull request Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant