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

Improved detect.py timing #4741

Merged
merged 6 commits into from
Sep 10, 2021
Merged

Improved detect.py timing #4741

merged 6 commits into from
Sep 10, 2021

Conversation

glenn-jocher
Copy link
Member

@glenn-jocher glenn-jocher commented Sep 10, 2021

Updated detect.py timing to match hub and val.py formats. Allows for simpler FPS calculation for students, i.e. #4737

$ python detect.py
YOLOv5 🚀 v5.0-419-gc5360f6 torch 1.9.0 CPU

Fusing layers... 
Model Summary: 224 layers, 7266973 parameters, 0 gradients
image 1/2 /Users/glennjocher/PycharmProjects/yolov5/data/images/bus.jpg: 640x480 4 persons, 1 bus, 1 fire hydrant, Done. (0.240s)
image 2/2 /Users/glennjocher/PycharmProjects/yolov5/data/images/zidane.jpg: 384x640 2 persons, 2 ties, Done. (0.191s)
Speed: 1.1ms pre-process, 215.5ms inference, 1.1ms NMS per image at shape (1, 3, 640, 640)  <------- NEW
Results saved to runs/detect/exp12

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Significant refactor of timing logic in inference scripts for enhanced transparency and clarity.

📊 Key Changes

  • Removed the global import of the time module in detect.py.
  • Introduced a local, more granular timing system that tracks three distinct stages.
  • Changed timing print statements to reflect only the time spent on the inference process, excluding pre- and post-processing times.
  • Standardized and cleaned up timing across both detect.py and val.py for consistency.

🎯 Purpose & Impact

  • The purpose of these changes is to provide users with more accurate and detailed insights into the model's inference performance 🚀.
  • Users will benefit from a clear understanding of where time is spent during model operation, allowing for better optimization and evaluation 🕒.
  • This level of detail is especially important for use cases where inference speed is critical, such as real-time applications 📈.

@glenn-jocher glenn-jocher linked an issue Sep 10, 2021 that may be closed by this pull request
@glenn-jocher
Copy link
Member Author

Divide 1000ms by the inference speed shown to arrive at a mean FPS for all images/frames run. In the above for example:

Speed: 1.1ms pre-process, 215.5ms inference, 1.1ms NMS per image at shape (1, 3, 640, 640)  <------- NEW

1000ms / 215.5ms = 4.7 FPS

@glenn-jocher glenn-jocher merged commit 7af1b4c into master Sep 10, 2021
@glenn-jocher glenn-jocher deleted the update/detect_time branch September 10, 2021 12:34
@glenn-jocher glenn-jocher mentioned this pull request Sep 10, 2021
@hiiksu hiiksu mentioned this pull request Sep 14, 2021
CesarBazanAV pushed a commit to CesarBazanAV/yolov5 that referenced this pull request Sep 29, 2021
* Improved detect.py timing

* Eliminate 1 time_sync() call

* Inference-only time

* dash

* #Save section

* Cleanup
@stccb
Copy link

stccb commented Oct 7, 2021

Sorry,Why the fps is 1000/inference_time is not (1000/(inference_time+NMS+prediction time))?

BjarneKuehl pushed a commit to fhkiel-mlaip/yolov5 that referenced this pull request Aug 26, 2022
* Improved detect.py timing

* Eliminate 1 time_sync() call

* Inference-only time

* dash

* #Save section

* Cleanup
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.

FPS measurement.
2 participants