Skip to content

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

Merged
glenn-jocher merged 1 commit intomasterfrom
update/hub
Apr 24, 2022
Merged

Add print(results) override for PyTorch Hub results#7559
glenn-jocher merged 1 commit intomasterfrom
update/hub

Conversation

@glenn-jocher
Copy link
Copy Markdown
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.

1 participant