LeRobot 文件
使用數據集工具
並獲得增強的文件體驗
開始使用
使用數據集工具
本指南涵蓋了 LeRobot 中用於修改和編輯現有數據集的數據集工具公用程式。
概覽
LeRobot 提供了多種操作數據集的公用程式:
- 刪除劇集 (Delete Episodes) - 從數據集中移除特定劇集
- 分割數據集 (Split Dataset) - 將一個數據集分割成多個較小的數據集
- 合併數據集 (Merge Datasets) - 將多個數據集合併為一個。數據集必須具有相同的特徵,且劇集會依照
repo_ids中指定的順序進行串接。 - 新增特徵 (Add Features) - 為數據集新增特徵
- 移除特徵 (Remove Features) - 從數據集中移除特徵
- 轉換為影片 (Convert to Video) - 將基於影像的數據集轉換為影片格式,以實現更高效的儲存
- 顯示數據集資訊 (Show the Info of Datasets) - 顯示數據集摘要資訊,例如劇集數量等。
核心實作位於 lerobot.datasets.dataset_tools 中。詳細說明如何使用工具 API 的範例腳本可在 examples/dataset/use_dataset_tools.py 中找到。
命令列工具:lerobot-edit-dataset
lerobot-edit-dataset 是一個用於編輯數據集的命令列腳本。它可用於刪除劇集、分割數據集、合併數據集、新增特徵、移除特徵,以及將影像數據集轉換為影片格式。
執行 lerobot-edit-dataset --help 以獲取關於每個操作配置的更多資訊。
使用範例
刪除劇集
從數據集中移除特定劇集。這對於篩選出不需要的數據非常有用。
# Delete episodes 0, 2, and 5 (modifies original dataset)
lerobot-edit-dataset \
--repo_id lerobot/pusht \
--operation.type delete_episodes \
--operation.episode_indices "[0, 2, 5]"
# Delete episodes and save to a new dataset (preserves original dataset)
lerobot-edit-dataset \
--repo_id lerobot/pusht \
--new_repo_id lerobot/pusht_after_deletion \
--operation.type delete_episodes \
--operation.episode_indices "[0, 2, 5]"分割數據集
將數據集分割成多個子集。
# Split by fractions (e.g. 80% train, 20% test, 20% val)
lerobot-edit-dataset \
--repo_id lerobot/pusht \
--operation.type split \
--operation.splits '{"train": 0.8, "test": 0.2, "val": 0.2}'
# Split by specific episode indices
lerobot-edit-dataset \
--repo_id lerobot/pusht \
--operation.type split \
--operation.splits '{"task1": [0, 1, 2, 3], "task2": [4, 5]}'分割名稱沒有限制,可由使用者自訂。產生的數據集會儲存在 repo id 下,並附加分割名稱,例如 lerobot/pusht_train、lerobot/pusht_task1、lerobot/pusht_task2。
合併數據集
將多個數據集合併為單一數據集。
# Merge train and validation splits back into one dataset
lerobot-edit-dataset \
--repo_id lerobot/pusht_merged \
--operation.type merge \
--operation.repo_ids "['lerobot/pusht_train', 'lerobot/pusht_val']"移除特徵
從數據集中移除特徵。
# Remove a camera feature
lerobot-edit-dataset \
--repo_id lerobot/pusht \
--operation.type remove_feature \
--operation.feature_names "['observation.images.top']"轉換為影片
將基於影像的數據集轉換為影片格式,建立一個新的 LeRobotDataset,其中影像以影片方式儲存。這對於減少儲存需求和提高數據載入效能非常有用。新數據集將與原始數據集具有完全相同的結構,但影像會以適當的 LeRobot 格式編碼為 MP4 影片。
# Local-only: Save to a custom output directory (no hub push)
lerobot-edit-dataset \
--repo_id lerobot/pusht_image \
--operation.type convert_image_to_video \
--operation.output_dir /path/to/output/pusht_video
# Save with new repo_id (local storage)
lerobot-edit-dataset \
--repo_id lerobot/pusht_image \
--new_repo_id lerobot/pusht_video \
--operation.type convert_image_to_video
# Convert and push to Hugging Face Hub
lerobot-edit-dataset \
--repo_id lerobot/pusht_image \
--new_repo_id lerobot/pusht_video \
--operation.type convert_image_to_video \
--push_to_hub true
# Convert with custom video codec and quality settings
lerobot-edit-dataset \
--repo_id lerobot/pusht_image \
--operation.type convert_image_to_video \
--operation.output_dir outputs/pusht_video \
--operation.vcodec libsvtav1 \
--operation.pix_fmt yuv420p \
--operation.g 2 \
--operation.crf 30
# Convert only specific episodes
lerobot-edit-dataset \
--repo_id lerobot/pusht_image \
--operation.type convert_image_to_video \
--operation.output_dir outputs/pusht_video \
--operation.episode_indices "[0, 1, 2, 5, 10]"
# Convert with multiple workers for parallel processing
lerobot-edit-dataset \
--repo_id lerobot/pusht_image \
--operation.type convert_image_to_video \
--operation.output_dir outputs/pusht_video \
--operation.num_workers 8
# For memory-constrained systems, users can now specify limits:
lerobot-edit-dataset \
--repo_id lerobot/pusht_image \
--operation.type convert_to_video \
--operation.max_episodes_per_batch 50 \
--operation.max_frames_per_batch 10000參數數量
output_dir:自訂輸出目錄(選填 - 預設使用new_repo_id或{repo_id}_video)vcodec:使用的影片編碼器 - 選項:h264,hevc,libsvtav1(預設:libsvtav1)pix_fmt:像素格式 - 選項:yuv420p,yuv444p(預設:yuv420p)g:圖片群組 (GOP) 大小 - 較小的值可獲得更好的畫質但檔案較大(預設:2)crf:恆定速率因子 (Constant rate factor) - 較小的值可獲得更好的畫質但檔案較大,0 為無損(預設:30)fast_decode:快速解碼調整選項(預設:0)episode_indices:要轉換的特定劇集清單(預設:所有劇集)num_workers:處理的並行工作數(預設:4)
注意: 產生的數據集將成為一個完整的 LeRobotDataset,所有攝影機影像都會編碼為影片並儲存在 videos/ 目錄中,Parquet 檔案將僅包含元數據(不包含原始影像數據)。所有劇集、統計數據和任務皆會被保留。
顯示數據集資訊
顯示數據集資訊,例如劇集數量、影格數量、檔案大小等。此操作不會對數據集進行任何更改。
# Show dataset information without feature details
lerobot-edit-dataset \
--repo_id lerobot/pusht_image \
--operation.type info \
# Show dataset information with feature details
lerobot-edit-dataset \
--repo_id lerobot/pusht_image \
--operation.type info \
--operation.show_features true
參數數量
parameters:控制是否顯示包含特徵細節的數據集資訊的旗標。(預設=false)
推送到 Hub
在任何命令中加入 --push_to_hub true 旗標,即可自動將產生的數據集上傳至 Hugging Face Hub。
lerobot-edit-dataset \
--repo_id lerobot/pusht \
--new_repo_id lerobot/pusht_after_deletion \
--operation.type delete_episodes \
--operation.episode_indices "[0, 2, 5]" \
--push_to_hub true還有一個用於為數據集新增特徵的工具,目前尚未包含在 lerobot-edit-dataset 中。
數據集視覺化
線上視覺化
當您使用 lerobot 錄製數據集時,除非另有指定,否則它會自動上傳到 Hugging Face Hub。若要線上檢視數據集,請使用我們的 LeRobot 數據集視覺化工具,網址為:https://huggingface.co/spaces/lerobot/visualize_dataset
本地視覺化
您也可以使用我們的命令列工具在本地視覺化數據集中的劇集。
從 Hugging Face Hub:
lerobot-dataset-viz \
--repo-id lerobot/pusht \
--episode-index 0從本地資料夾: 加入 --root 選項並設定 --mode local。例如,若要搜尋 ./my_local_data_dir/lerobot/pusht
lerobot-dataset-viz \
--repo-id lerobot/pusht \
--root ./my_local_data_dir \
--mode local \
--episode-index 0執行後,該工具會開啟 rerun.io 並顯示所選劇集的攝影機串流、機器人狀態和動作。
若要進行進階使用(包括視覺化儲存在遠端伺服器上的數據集),請執行:
lerobot-dataset-viz --help