# C401 Lesson 4: Training Formats

> The fourth lesson of the C401 processing course: why a training format differs from a recording container, how LeRobotDataset v3.0 stores episodes, features and video, why finalize() matters, when MCAP, HDF5, Zarr or WebDataset fit better, how human egocentric data becomes states and actions, and where calibration goes.

Page: https://egocam.ai/university/c401/lesson-4-training-formats/

The last step of the pipeline writes what lessons 1 to 3 produced into files a data loader can read. This lesson covers the formats current egocentric releases use, with LeRobotDataset v3.0 in most detail because the lab exports to it. The full treatment is on [Training Formats: LeRobot, RLDS and Friends](https://egocam.ai/processing/training-formats-lerobot-rlds/).

## Terms used in this lesson

See also the [glossary's datasets and formats section](https://egocam.ai/reference/glossary/#datasets-formats-and-storage).

| Term | Meaning |
|---|---|
| Episode | One continuous recording of a task from start to finish: a sequence of time-aligned observations and actions |
| Shard | One large file that packs many episodes, so storage handles fewer, larger files |
| Feature | A named per-frame field with a dtype and shape, such as `observation.state` or `observation.images.<camera>` |
| `observation.state` | A per-frame vector describing the agent: joint angles for a robot; wrist pose and finger joints for a human hand |
| `action` | The command or motion target at a timestep, absolute (a target pose) or relative (a delta) |
| MCAP | An open container for timestamped publish/subscribe messages with embedded schemas and an index |

## Recording containers and training formats

A [recording container](https://egocam.ai/capture-ops/recording-formats-vrs-mcap-gpmf/) is built for capture: it appends time-stamped packets in arrival order. A training format is built for learning: it organises many episodes so a loader can sample random frames, slice short time windows and normalise states and actions without opening millions of small files ([Training Formats](https://egocam.ai/processing/training-formats-lerobot-rlds/)).

Current public egocentric releases often ship both. Lightwheel publishes its datasets as MCAP and as LeRobot, and both cards warn: "LeRobot and MCAP are alternative representations of the same episodes and must not be counted as additional hours" ([EgoStandard card](https://huggingface.co/datasets/LightwheelAI/EgoStandard)).

## LeRobotDataset v3.0

LeRobotDataset is Hugging Face's dataset format for the lerobot library. States, actions and timestamps go in Parquet tables, camera frames in MP4, and metadata in JSON and Parquet. In v2.1 every episode had its own files; v3.0 concatenates many episodes into each file. The [v3.0 docs](https://huggingface.co/docs/lerobot/lerobot-dataset-v3) explain: "To scale to millions of episodes, tabular rows and video frames from multiple episodes are concatenated into larger files."

> **Diagram:** Why LeRobotDataset v3.0 changed the layout. In v2.1 every episode has its own Parquet file and one MP4 per camera, so the file count grows with episodes times cameras. In v3.0 many episodes are concatenated into each Parquet shard and each camera's MP4 shard, and a row in meta/episodes records each episode's length, task and offsets, which locate it as a row range in the data and a time range in the video. Shard sizes are lerobot's defaults. Sources: the LeRobotDataset v3.0 docs and lerobot's datasets/utils.py (v0.3.3 for v2.1, main for v3.0).

What to know before writing one ([LeRobotDataset](https://egocam.ai/processing/training-formats-lerobot-rlds/#lerobotdataset)):

- **The schema lives in `meta/info.json`**, with the feature names, dtypes and shapes, the frame rate and the path templates. Normalisation statistics live in `meta/stats.json`.
- **Cameras are features** named `observation.images.<camera>`, with dtype `video`.
- **There is no field for camera intrinsics or extrinsics.** Egocentric releases add their own files under `meta/`; MundoAI's sample puts "camera intrinsics + head-to-camera offset, keyed by device" in a calibration file there ([MundoAI-Robotics-Sample](https://huggingface.co/datasets/thomasmundo/MundoAI-Robotics-Sample/blob/main/README.md)).
- **Call `finalize()`.** v3.0 writes Parquet incrementally: "When creating or recording datasets, you must call dataset.finalize() to properly close parquet writers." Without it the files are incomplete and the dataset will not load ([v3.0 docs](https://huggingface.co/docs/lerobot/lerobot-dataset-v3)).
- **Timestamps come from the frame rate.** In lerobot 0.7.0, `add_frame()` computes each frame's timestamp as its index divided by the dataset's fps, and the caller must not supply one ([`dataset_writer.py`](https://github.com/huggingface/lerobot/blob/v0.7.0/src/lerobot/datasets/dataset_writer.py)). Frames you add must therefore be evenly spaced at that rate.

## The other formats, and when they fit

| Downstream use | Export | Why |
|---|---|---|
| PyTorch imitation learning, VLA training, Hub release | LeRobotDataset v3.0 | Few large files; time windows, streaming and GPU augmentation built in |
| Inspection, curation, ROS 2 / Foxglove / FiftyOne | MCAP | Keeps native sensor rates, embedded schemas and calibration attachments |
| Dense per-frame skeletons, depth, SLAM | MP4 + HDF5, or Zarr | Video stays hardware-decodable; arrays stay in one indexed file or store |
| Video-only pretraining at 10,000+ hours | WebDataset | Sequential streaming of `.tar` shards with little metadata overhead |

The table is the field guide's [which format to export](https://egocam.ai/processing/training-formats-lerobot-rlds/#which-format-to-export). MCAP keeps every stream at its own rate, where LeRobot flattens an episode into fixed-rate rows aligned to video frames ([MCAP as a distribution and curation format](https://egocam.ai/processing/training-formats-lerobot-rlds/#mcap-as-a-distribution-and-curation-format)). Several egocentric releases keep video as MP4 and put the kinematics in HDF5: EgoDex pairs each MP4 with an HDF5 file holding camera intrinsics and extrinsics and upper-body joint poses ([HDF5 layouts](https://egocam.ai/processing/training-formats-lerobot-rlds/#hdf5-robomimic-act-and-egocentric-datasets)).

## Human data as states and actions

In a teleoperated robot dataset, state and action come from the robot. Human capture has no robot. As RoboX's card puts it: "No robot retargeting is applied. target_embodiment is null and no robot telemetry is present" ([RoboX lerobot-dataset](https://huggingface.co/datasets/RoboXTechnologies/lerobot-dataset)). Pipelines build proxy states and actions from hand pose, world-space hand tracking and SLAM head poses. Three details recur in the published schemas ([representing human egocentric data](https://egocam.ai/processing/training-formats-lerobot-rlds/#representing-human-egocentric-data-as-states-and-actions)):

1. **Remove head motion from hand actions.** Hand poses from a head camera are in a moving frame. EgoMimic and EgoVerse use the SLAM poses to express every future hand pose in the camera frame at the current time.
2. **Do not subtract quaternions.** RoboX's action uses "a 3-D relative rotation vector rotvec(q[t+1] . inverse(q[t])) rather than a quaternion subtraction", and it excludes the quaternion indices from mean/std normalisation, which would break their unit norm.
3. **Match human and robot speed.** People move faster than teleoperated robots, so a chunk of fixed length would cover more of the task in human data than in robot data. EgoVerse resamples a 1-second human window and a 1.5-second robot window to 100 steps each, and normalises each embodiment separately ([Matching human and robot speed](https://egocam.ai/processing/training-formats-lerobot-rlds/#matching-human-and-robot-speed)).

> **Diagram:** Why hand actions from a head camera need the camera's SLAM poses. If the wearer turns their head while the hand stays still, hand positions left in each frame's own camera coordinates appear to move, so head motion leaks into the action. Re-expressing every future hand pose in the camera frame at the current time t, using the SLAM poses as EgoMimic and EgoVerse do, puts a still hand at the same point and gives a zero action. Schematic, top-down.

Turning these into robot policies is course C402. For this course, the rule is simpler: whatever you export, write down which frame each pose is in, its units, and its rotation convention.

## Self-check

1. You record a ROS 2 bag with images at 30 Hz and an IMU at 200 Hz. Why might you ship MCAP alongside a LeRobot export?
2. Your conversion script runs without errors, but the dataset will not load. What is the first thing to check in a v3.0 export?
3. Where do the camera intrinsics go in a LeRobotDataset?
4. Your tracker produced no pose for 40 frames in the middle of an episode. Why can you not simply skip them when calling `add_frame()`?
5. Why does RoboX exclude its quaternion components from mean/std normalisation?

### Answers

1. LeRobot flattens an episode into fixed-rate rows aligned to video frames; MCAP keeps every stream at its own rate, with embedded schemas, for inspection and curation. If you ship both, say on the card that they are the same episodes.
2. Whether `finalize()` was called after the last `save_episode()`; without it the Parquet files are incomplete.
3. There is no standard field. Add a file under `meta/`, as egocentric releases do, and describe it on the card.
4. lerobot computes timestamps from the frame index and fps, so skipped frames would shift every later frame's timestamp. End the episode at the gap or fill it by a documented method.
5. Mean/std scaling would break a quaternion's unit norm.

## Sources

- Field guide: [Training Formats: LeRobot, RLDS and Friends](https://egocam.ai/processing/training-formats-lerobot-rlds/), [Recording Containers: VRS, MCAP and GPMF](https://egocam.ai/capture-ops/recording-formats-vrs-mcap-gpmf/), [glossary](https://egocam.ai/reference/glossary/#datasets-formats-and-storage).
- Hugging Face: [LeRobotDataset v3.0 docs](https://huggingface.co/docs/lerobot/lerobot-dataset-v3); [lerobot v0.7.0 `dataset_writer.py`](https://github.com/huggingface/lerobot/blob/v0.7.0/src/lerobot/datasets/dataset_writer.py) (Apache-2.0).
- Dataset cards: [LightwheelAI/EgoStandard](https://huggingface.co/datasets/LightwheelAI/EgoStandard), [MundoAI-Robotics-Sample](https://huggingface.co/datasets/thomasmundo/MundoAI-Robotics-Sample/blob/main/README.md), [RoboXTechnologies/lerobot-dataset](https://huggingface.co/datasets/RoboXTechnologies/lerobot-dataset).
- [EgoVerse](https://arxiv.org/abs/2604.07607) (2026). arXiv.
- Kareer et al. (2024). [EgoMimic](https://arxiv.org/html/2410.24221v1). arXiv.
- Hoque et al. (2025). [EgoDex](https://arxiv.org/pdf/2505.11709). arXiv.
