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

PyTorch Hub and autoShape update #1415

Merged
merged 3 commits into from
Nov 16, 2020
Merged

PyTorch Hub and autoShape update #1415

merged 3 commits into from
Nov 16, 2020

Conversation

glenn-jocher
Copy link
Member

@glenn-jocher glenn-jocher commented Nov 16, 2020

This PR pushes the autoShape concept further with a Detections() class produced by YOLOv5 inference now when using .autoShape(). PyTorch Hub tutorial updated also, and we are also finalizing an official submission to https://github.com/pytorch/hub.

Everything works super simply. To see a preview simply run $ python hubconf.py. Example:

import torch
from PIL import Image

# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True).autoshape()  # for PIL/cv2/np inputs and NMS

# Images
img = Image.open('zidane.jpg')  # PIL image

# Inference
results = model(img)  # includes NMS

# View
results.show()  # .show() results, .save() jpgs, or .print() to screen

# Data
results.xyxy  # x1, y1, x2, y2 (pixels) format
results.xyxyn  # x1, y1, x2, y2 (normalized) format
results.xywh  # x_center, y_center, width, height (pixels) format
results.xywhn  # x_center, y_center, width, height (normalized) format

results2

results1

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Enhancements to YOLOv5 inference and image processing.

📊 Key Changes

  • 🧹 Simplified conditional checks (e.g., if len(det) instead of if det is not None and len(det)).
  • 🎨 Integrated the Pillow (PIL) library for image handling, expanding dependency list to include pillow.
  • 🖼️ Modified autoShape and Detections classes to improve image input handling, normalization, and post-processing.
  • 🚀 Introduced a new Detections class to encapsulate detection results with various output functions (print, show, save).
  • 🛠️ Minor code refactors and consistency improvements (e.g., replaced cloning tensors instead of creating new ones for shape manipulations).

🎯 Purpose & Impact

  • 📈 Improved code readability and maintainability by removing unnecessary checks and clarifying comments.
  • Pillow integration aims to enhance image operations and make the library more user-friendly for image-related tasks.
  • 🌐 The new Detections class provides a standard way to interact with inference outputs, easing the display and interpretation of results for users.
  • 🏗️ Refactoring contributes to more consistent and efficient codebase, potentially leading to fewer bugs and better performance.
  • Overall, these changes should provide a smoother user experience and facilitate easier integration and use of YOLOv5 in image detection tasks.

@glenn-jocher glenn-jocher merged commit f542926 into master Nov 16, 2020
@glenn-jocher glenn-jocher deleted the hub_update branch November 16, 2020 22:09
glenn-jocher added a commit that referenced this pull request Nov 16, 2020
glenn-jocher added a commit that referenced this pull request Nov 16, 2020
glenn-jocher added a commit that referenced this pull request Nov 16, 2020
glenn-jocher added a commit that referenced this pull request Nov 16, 2020
@glenn-jocher glenn-jocher changed the title Hub update PyTorch Hub and autoShape update Nov 16, 2020
burglarhobbit pushed a commit to burglarhobbit/yolov5 that referenced this pull request Jan 1, 2021
* PyTorch Hub and autoShape update

* comment x for imgs

* reduce comment
burglarhobbit pushed a commit to burglarhobbit/yolov5 that referenced this pull request Jan 1, 2021
burglarhobbit pushed a commit to burglarhobbit/yolov5 that referenced this pull request Jan 1, 2021
burglarhobbit pushed a commit to burglarhobbit/yolov5 that referenced this pull request Jan 1, 2021
burglarhobbit pushed a commit to burglarhobbit/yolov5 that referenced this pull request Jan 1, 2021
KMint1819 pushed a commit to KMint1819/yolov5 that referenced this pull request May 12, 2021
* PyTorch Hub and autoShape update

* comment x for imgs

* reduce comment
KMint1819 pushed a commit to KMint1819/yolov5 that referenced this pull request May 12, 2021
KMint1819 pushed a commit to KMint1819/yolov5 that referenced this pull request May 12, 2021
KMint1819 pushed a commit to KMint1819/yolov5 that referenced this pull request May 12, 2021
KMint1819 pushed a commit to KMint1819/yolov5 that referenced this pull request May 12, 2021
BjarneKuehl pushed a commit to fhkiel-mlaip/yolov5 that referenced this pull request Aug 26, 2022
* PyTorch Hub and autoShape update

* comment x for imgs

* reduce comment
BjarneKuehl pushed a commit to fhkiel-mlaip/yolov5 that referenced this pull request Aug 26, 2022
BjarneKuehl pushed a commit to fhkiel-mlaip/yolov5 that referenced this pull request Aug 26, 2022
BjarneKuehl pushed a commit to fhkiel-mlaip/yolov5 that referenced this pull request Aug 26, 2022
BjarneKuehl pushed a commit to fhkiel-mlaip/yolov5 that referenced this pull request Aug 26, 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