Skip to main content
The LeRobotDataset class is a PyTorch dataset for working with robot learning data in LeRobot. It supports loading existing datasets and recording new ones.

Class Definition

Location: src/lerobot/datasets/lerobot_dataset.py:566

Overview

LeRobotDataset provides:
  • Loading datasets from Hugging Face Hub or local storage
  • Recording new datasets from robot interactions
  • Video encoding/decoding for efficient storage
  • Episode-based data organization
  • Delta timestamps for temporal queries
  • Push/pull from Hugging Face Hub

Constructor

Parameters

str
required
Repository identifier in format {username}/{dataset_name} (e.g., lerobot/pusht).
str | Path | None
Local directory for dataset storage. Defaults to $HF_LEROBOT_HOME/repo_id.
list[int] | None
List of episode indices to load. If None, loads all episodes.
Callable | None
Torchvision transforms to apply to image modalities.
dict[str, list[float]] | None
Dictionary mapping keys to lists of time offsets for temporal queries.Example:
float
default:"1e-4"
Tolerance in seconds for timestamp validation.
str | None
Git revision (branch, tag, or commit hash) for Hugging Face Hub.
bool
default:"False"
If True, refresh local files from Hub even if already cached.
bool
default:"True"
Whether to download video files.
str | None
Video decoding backend: "torchcodec", "pyav", or "video_reader". Auto-detects if None.
int
default:"1"
Number of episodes to accumulate before encoding videos. Set to 1 for immediate encoding.
str
default:"libsvtav1"
Video codec: "h264", "hevc", "libsvtav1", "auto", or hardware-specific codecs.
bool
default:"False"
If True, encode video frames in real-time during capture instead of writing PNGs first.
int
default:"30"
Maximum frames to buffer per camera when using streaming encoding.
int | None
Number of threads per encoder. None uses codec default.

Properties

fps

int
Frames per second used during data collection.

num_frames

int
Number of frames in selected episodes.

num_episodes

int
Number of episodes selected.

features

dict[str, dict]
All features contained in the dataset with their metadata (dtype, shape, names).

Methods

getitem

Get a single frame from the dataset.
int
required
Frame index.
dict
Dictionary containing:
  • All observation keys (e.g., images, state)
  • action: Action taken at this timestep
  • episode_index: Episode this frame belongs to
  • frame_index: Index within the episode
  • timestamp: Time in seconds
  • task: Task description string
  • Delta timestamp queries if configured

push_to_hub

Upload dataset to Hugging Face Hub.
str | None
Git branch name. If None, pushes to main.
list | None
Tags to add to the dataset card.
str | None
default:"apache-2.0"
Dataset license.
bool
default:"True"
Whether to create a version tag.
bool
default:"True"
Whether to upload video files.
bool
default:"False"
Whether to create a private repository.

add_frame

Add a frame to the current episode buffer during recording.
dict
required
Dictionary containing observation and action data. Must include:
  • All keys from features
  • task: Task description string
  • Optional timestamp: Time in seconds (auto-generated if not provided)

finalize

Close parquet writers and finalize the dataset after recording. Must be called after data collection.

Creating a New Dataset

Use the create class method to initialize a new dataset:
str
required
Dataset identifier.
int
required
Frames per second.
dict
required
Dictionary defining dataset features.
str | None
Type of robot used for recording.
bool
default:"True"
Whether to encode images as videos.

Usage Examples

Loading an Existing Dataset

Using with PyTorch DataLoader

Recording a New Dataset

Dataset Structure

LeRobotDataset uses a chunked file structure:

See Also