Skip to content

fix: lexicographic file sort misorders numbered frames - #54

Open
andrewwhitecdw wants to merge 1 commit into
NVlabs:mainfrom
andrewwhitecdw:bugfix/convert-to-lerobot-8257d421
Open

fix: lexicographic file sort misorders numbered frames#54
andrewwhitecdw wants to merge 1 commit into
NVlabs:mainfrom
andrewwhitecdw:bugfix/convert-to-lerobot-8257d421

Conversation

@andrewwhitecdw

Copy link
Copy Markdown

This PR addresses the following issue in scripts/convert_to_lerobot.py: lexicographic file sort misorders numbered frames.

Changes

  • scripts/convert_to_lerobot.py: lexicographic file sort misorders numbered frames.

Details

Before:

# Get the paths of files within a directory.
def get_files_in_dir(path: Path) -> list[Path]:
    return sorted([p for p in path.iterdir() if p.is_file()])

After:

import re

# Get the paths of files within a directory.
def _natural_sort_key(path: Path):
    return [int(s) if s.isdigit() else s.lower() for s in re.split(r"(\d+)", path.name)]

def get_files_in_dir(path: Path) -> list[Path]:
    return sorted([p for p in path.iterdir() if p.is_file()], key=_natural_sort_key)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant