Skip to content

Conversation

glenn-jocher
Copy link
Member

@glenn-jocher glenn-jocher commented May 24, 2021

Replace with torch.no_grad(): statement with @torch.no_grad() decorator.

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Enhancement of the inference and testing code in the YOLOv5 project for better readability and performance.

📊 Key Changes

  • Applied the @torch.no_grad() decorator to the detect() and test() functions in detect.py and test.py.
  • Removed nested with torch.no_grad(): blocks inside these functions.
  • Simplified conditional logic in detect.py for updating models.

🎯 Purpose & Impact

  • 🚀 Increases efficiency: Disabling gradient computations globally with the @torch.no_grad() decorator to avoid redundancy.
  • 📖 Improves code readability: By removing nested with torch.no_grad():, the code structure is simplified making it easier to read and understand.
  • 🛠️ Enhances maintainability: Simplified conditionals reduce complexity, making it easier to maintain and update the code.
  • 🌍 User experience: These changes aim to streamline the inference and test processes, potentially improving execution time and lowering resource consumption, which benefits all users.

@glenn-jocher glenn-jocher changed the title @torch.no_grad() decorator Implement @torch.no_grad() decorator May 24, 2021
@glenn-jocher glenn-jocher merged commit 61ea23c into master May 24, 2021
@glenn-jocher glenn-jocher deleted the glenn-jocher-patch-1 branch May 24, 2021 11:23
Lechtr pushed a commit to Lechtr/yolov5 that referenced this pull request Jul 20, 2021
* `@torch.no_grad()` decorator

* Update detect.py

(cherry picked from commit 61ea23c)
BjarneKuehl pushed a commit to fhkiel-mlaip/yolov5 that referenced this pull request Aug 26, 2022
* `@torch.no_grad()` decorator

* Update detect.py
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