[Experimental] Optimizes the save_episode() - #4
Draft
masafumi-airoa wants to merge 5 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
This PR experimentally improves the performance of the
save_episode()function.The
encode_episode_videos()previously saved images as.pngimages, asynchronously loaded them as PIL images, converted them to RGB images, and created a video from the PIL images with PyAV. This process was the biggest bottleneck, accounting for approximately 56% of the total runtime (for converting 11 rosbags in my environment).The new pipeline stores the images as
np.ndarrayin memory and directly inputs them to PyAV whenframe_staging = "memory". This pipeline shortcuts the above process and reduces about 50% of the total execution time.debug_data)How it was tested
Visually checked the generated videos.
hand
https://github.com/user-attachments/assets/9261391e-d0dc-4aab-8e2f-2cbe6de86648
head
https://github.com/user-attachments/assets/5f495929-62ce-4bdd-bb6c-529696323f1c
How to checkout & try? (for the reviewer)
We can measure the execution time by running these commands in the PR's branch after downloading
debug_datadataset from AWS,uv sync --reinstall-package lerobot uv add pyinstrument uv run pyinstrument -r html -o profile.html -m hsr_data_converter.rosbag2lerobot.main --raw_dir {path to the debug_data directory} --out_dir ./datasets --fps 10 --robot_type hsr --conversion_type aggregate --separate_per_primitive false