-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add LeRobot v3 dataset import support #268
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
Merged
+413
−4
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0615de9
feat: add LeRobot v3 dataset import support
rikunosuke d3303df
fix wrong comments, create a episode map out of loop scope
rikunosuke d928047
fix create_episode_zip docstring to match actual ZIP structure
rikunosuke 681bb56
add missing column guard in _convert_episode_frames
rikunosuke 6cddb65
fix get_camera_dirs to use full content name and validate prefix
rikunosuke 8612de4
fix: version up flake8 and fix codes
rikunosuke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| """ | ||
| Import a LeRobot dataset into a FastLabel robotics project. | ||
|
|
||
| Requires: pip install fastlabel[robotics] | ||
|
|
||
| Supports LeRobot v3 dataset format only. | ||
| v3: data/chunk-*/file-*.parquet, videos/.../chunk-*/file-*.mp4 | ||
| """ | ||
|
|
||
| from fastlabel import Client | ||
|
|
||
| client = Client() | ||
|
|
||
| # Import all episodes | ||
| results = client.import_lerobot( | ||
| project="your-project-slug", | ||
| lerobot_data_path="/path/to/lerobot/dataset", | ||
| ) | ||
|
|
||
| # Import specific episodes by index | ||
| results = client.import_lerobot( | ||
| project="your-project-slug", | ||
| lerobot_data_path="/path/to/lerobot/dataset", | ||
| episode_indices=[0, 1, 2], | ||
| ) |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| from fastlabel.exceptions import FastLabelInvalidException | ||
| from fastlabel.lerobot import v3 | ||
| from fastlabel.lerobot.common import ( | ||
| check_dependencies, | ||
| detect_version, | ||
| format_episode_name, | ||
| get_camera_dirs, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "build_episode_map", | ||
| "get_episode_indices", | ||
| "create_episode_zip", | ||
| "format_episode_name", | ||
| "get_camera_dirs", | ||
| ] | ||
|
|
||
|
|
||
| def get_episode_indices(lerobot_data_path): | ||
| """Get all episode indices from a LeRobot v3 dataset.""" | ||
| check_dependencies() | ||
| version = detect_version(lerobot_data_path) | ||
| if version == "v2": | ||
| raise FastLabelInvalidException( | ||
| "LeRobot dataset v2 is not supported. Please convert to v3.", | ||
| 422, | ||
| ) | ||
|
Comment on lines
+23
to
+27
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. まずはメインで使われている v3 をサポートしています。 |
||
| return v3.get_episode_indices(lerobot_data_path) | ||
|
|
||
|
|
||
| def build_episode_map(lerobot_data_path): | ||
| """Build episode map from dataset. Returns a dict keyed by episode index.""" | ||
| check_dependencies() | ||
| version = detect_version(lerobot_data_path) | ||
| if version == "v2": | ||
| raise FastLabelInvalidException( | ||
| "LeRobot dataset v2 is not supported. Please convert to v3.", | ||
| 422, | ||
| ) | ||
| return v3._build_episode_map(lerobot_data_path) | ||
|
|
||
|
|
||
| def create_episode_zip(lerobot_data_path, episode_index, episode_map=None): | ||
| """Create a ZIP file for a single episode in the format expected by FastLabel. | ||
|
|
||
| Supports LeRobot dataset v3 only. | ||
|
|
||
| ZIP structure (files at root, ZIP name = episode name): | ||
| {content_name}.mp4 (one per camera) | ||
| {episode_name}.json (frame data) | ||
|
|
||
| Returns the path to the created ZIP file. | ||
| The caller is responsible for cleaning up the returned ZIP file. | ||
| """ | ||
| check_dependencies() | ||
| version = detect_version(lerobot_data_path) | ||
| if version == "v2": | ||
| raise FastLabelInvalidException( | ||
| "LeRobot dataset v2 is not supported. Please convert to v3.", | ||
| 422, | ||
| ) | ||
| return v3.create_episode_zip(lerobot_data_path, episode_index, episode_map) | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| from pathlib import Path | ||
|
|
||
| from fastlabel.exceptions import FastLabelInvalidException | ||
|
|
||
|
|
||
| def check_dependencies(): | ||
| try: | ||
| import pandas # noqa: F401 | ||
| import pyarrow # noqa: F401 | ||
| except ImportError: | ||
| raise FastLabelInvalidException( | ||
| "pandas and pyarrow are required for LeRobot support. " | ||
| "Install them with: pip install fastlabel[robotics]", | ||
| 422, | ||
| ) | ||
|
|
||
|
|
||
| def detect_version(lerobot_data_path: Path) -> str: | ||
| """Detect LeRobot dataset version (v2 or v3). | ||
|
|
||
| Both versions use data/chunk-XXX/ directories. | ||
| v2: data/chunk-XXX/episode_YYYYYY.parquet | ||
| v3: data/chunk-XXX/file-YYY.parquet | ||
| """ | ||
| data_dir = lerobot_data_path / "data" | ||
| if not data_dir.exists(): | ||
| raise FastLabelInvalidException(f"Data directory not found: {data_dir}", 422) | ||
|
|
||
| for chunk_dir in data_dir.iterdir(): | ||
| if not chunk_dir.is_dir() or not chunk_dir.name.startswith("chunk-"): | ||
| continue | ||
| for f in chunk_dir.iterdir(): | ||
| if f.suffix != ".parquet": | ||
| continue | ||
| if f.stem.startswith("episode_"): | ||
| return "v2" | ||
| if f.stem.startswith("file-"): | ||
| return "v3" | ||
|
|
||
| raise FastLabelInvalidException( | ||
| "Could not detect LeRobot dataset version. " | ||
| "Expected data/chunk-XXX/episode_*.parquet (v2) " | ||
| "or data/chunk-XXX/file-*.parquet (v3).", | ||
| 422, | ||
| ) | ||
|
|
||
|
|
||
| def format_episode_name(episode_index: int) -> str: | ||
| return f"episode_{episode_index:06d}" | ||
|
|
||
|
|
||
| def get_camera_dirs(lerobot_data_path: Path) -> list: | ||
| """Get camera directories and their content names. | ||
| Returns [(camera_dir, content_name), ...]. | ||
| e.g. observation.images.top -> content_name = "images_top" | ||
| """ | ||
| videos_dir = lerobot_data_path / "videos" | ||
| if not videos_dir.exists(): | ||
| return [] | ||
|
|
||
| results = [] | ||
| for obs_dir in sorted(videos_dir.iterdir()): | ||
| if not obs_dir.is_dir(): | ||
| continue | ||
| parts = obs_dir.name.split(".") | ||
| if parts[0] != "observation": | ||
| raise FastLabelInvalidException( | ||
| f"Unexpected camera dir name: {obs_dir.name}" | ||
| ) | ||
|
|
||
| content_name = "_".join(parts[1:]) | ||
| results.append((obs_dir, content_name)) | ||
| return results |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.