-
-
Notifications
You must be signed in to change notification settings - Fork 16.4k
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
Accelerate video inference #9487
Conversation
…lf.vid_stride * (self.frame + 1)) # read at vid_stride".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 Hello @mucunwuxian, thank you for submitting a YOLOv5 🚀 PR! To allow your work to be integrated as seamlessly as possible, we advise you to:
- ✅ Verify your PR is up-to-date with
ultralytics/yolov5
master
branch. If your PR is behind you can update your code by clicking the 'Update branch' button or by runninggit pull
andgit merge master
locally. - ✅ Verify all YOLOv5 Continuous Integration (CI) checks are passing.
- ✅ Reduce changes to the absolute minimum required for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." — Bruce Lee
@mucunwuxian thanks for the PR! Do you have any before and after results/profiling? |
@glenn-jocher |
@mucunwuxian oh that's strange. Are you sure it's not just faster because it's skipping more frames? |
@mucunwuxian I tested and it is much faster! 4.1s vs 6.6s on M2 CPU, probably even faster on GPU. |
@mucunwuxian I thought .grab() actually loaded the data though and was much slower than .retrieve(). Shouldn't we retreive multiple frames before grabbing the one we want for the fastest speed? EDIT: this is backwards. |
@glenn-jocher Wait a minute. |
@mucunwuxian I think we want the same behavior as the streamloader here, where it grabs every frame and only retreives frames when Lines 336 to 340 in 868c0e9
|
Signed-off-by: Glenn Jocher <[email protected]>
@mucunwuxian ok, I've aligned the behavior with LoadStreams. Same speed, slightly shorter code. |
@glenn-jocher |
@mucunwuxian PR is merged. Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐ |
@glenn-jocher By the way, I did same way in the beginning. So it's essentially correct, but different from the output of the original code. But if you the author are okay then I think it's okay. :-D |
@mucunwuxian oh got it! Yes this way may skip the first few frames rather than always using the first frame, but this is the behavior for LoadStreams so now they are both aligned. |
@glenn-jocher |
@mucunwuxian i appreciate your kind words! The YOLO community and the Ultralytics team have been invaluable in this endeavor. Feel free to reach out if you have any further questions or contributions. |
@glenn-jocher
I hope this PR finds you well.
I adjust code of reading video, using 'cap.grab()' and 'cap. retrieve'.
It's a small fix.
🛠️ PR Summary
Made with ❤️ by Ultralytics Actions
🌟 Summary
Improved video frame retrieval in data loading process for YOLOv5.
📊 Key Changes
cap.read()
call withcap.grab()
called in a loop, followed bycap.retrieve()
for video frames.cap.grab()
is called is determined byself.vid_stride
, ensuring that frames are skipped according to the stride specified.🎯 Purpose & Impact