Skip to content

feat(dataset tools): add trim_episode_start operation#3096

Open
pkooij wants to merge 1 commit intomainfrom
feat/trim-episode-start-main
Open

feat(dataset tools): add trim_episode_start operation#3096
pkooij wants to merge 1 commit intomainfrom
feat/trim-episode-start-main

Conversation

@pkooij
Copy link
Member

@pkooij pkooij commented Mar 6, 2026

Title

feat(datasets): add trim_episode_start edit operation

Type / Scope

  • Type: Feature
  • Scope: datasets, scripts

Summary / Motivation

This PR adds a new dataset edit operation, trim_episode_start, to remove the first N seconds from episodes while keeping dataset invariants intact (frame indices, global indices, episode metadata, and stats). This is useful for removing startup/warm-up frames from collected data without manual dataset surgery. It also skips episodes that are too short to trim, so one short episode does not fail the full run.

Related issues

  • Fixes / Closes: N/A
  • Related: N/A

What changed

  • Added trim_episode_start(...) in src/lerobot/datasets/dataset_tools.py.
  • Added trim_episode_start operation wiring in src/lerobot/scripts/lerobot_edit_dataset.py.
  • Added parser coverage for the new operation in tests/scripts/test_edit_dataset_parsing.py.
  • Added trim behavior tests in tests/datasets/test_dataset_tools.py:
    • metadata/index consistency after trimming,
    • skipping too-short episodes,
    • failure when all selected episodes are too short.
  • Video behavior: this operation currently performs logical trimming for videos by updating per-episode video timestamps in metadata; it does not re-encode/cut MP4 files.

Breaking changes: none.

How was this tested (or how to run locally)

  • Tests added:

    • tests/datasets/test_dataset_tools.py
    • tests/scripts/test_edit_dataset_parsing.py
  • Syntax checks run:

    python -m py_compile src/lerobot/datasets/dataset_tools.py src/lerobot/scripts/lerobot_edit_dataset.py tests/datasets/test_dataset_tools.py tests/scripts/test_edit_dataset_parsing.py
  • Suggested local test run:

    pytest -q tests/scripts/test_edit_dataset_parsing.py tests/datasets/test_dataset_tools.py -k trim_episode_start
  • Example CLI usage:

    python -m lerobot.scripts.lerobot_edit_dataset \
      --repo_id lerobot-data-collection/level2_final_quality3 \
      --new_repo_id lerobot-data-collection/level2_final_quality3_trim3s \
      --operation.type trim_episode_start \
      --operation.seconds 3.0

Checklist (required before merge)

  • Linting/formatting run (pre-commit run -a)
  • All tests pass locally (pytest)
  • Documentation updated
  • CI is green

Reviewer notes

  • Please focus review on trim_episode_start index/metadata invariants and the skip-too-short behavior.
  • Video handling is metadata-based (no video re-encoding); this preserves correctness for loading but does not reduce video file size.
  • Anyone in the community is free to review the PR.

Add a dataset edit operation to trim the first N seconds from episodes while rebuilding frame and episode indices and metadata consistently. Skip episodes that are too short to trim and cover parsing plus metadata invariants with focused tests.

Made-with: Cursor
@github-actions github-actions bot added dataset Issues regarding data inputs, processing, or datasets tests Problems with test coverage, failures, or improvements to testing labels Mar 6, 2026
@pkooij pkooij requested a review from CarolinePascal March 6, 2026 14:08
@pkooij pkooij self-assigned this Mar 6, 2026
@s1lent4gnt
Copy link
Member

It might be worth checking this work as well since it has the same intended use: #3024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dataset Issues regarding data inputs, processing, or datasets tests Problems with test coverage, failures, or improvements to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants