From ef3d17fe7886a983e1699236af58d3649ab8c4a2 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Mon, 27 Jul 2026 21:06:03 -0500 Subject: [PATCH] fix: lexicographic file sort misorders numbered frames --- scripts/convert_to_lerobot.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/convert_to_lerobot.py b/scripts/convert_to_lerobot.py index d15ddbb..cfd987e 100644 --- a/scripts/convert_to_lerobot.py +++ b/scripts/convert_to_lerobot.py @@ -29,9 +29,14 @@ def get_subdirectories(path: Path) -> list[Path]: return sorted([p for p in path.iterdir() if p.is_dir()]) +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()]) + return sorted([p for p in path.iterdir() if p.is_file()], key=_natural_sort_key) # Read an image file into a numpy array. def load_image(file_path: Path) -> np.ndarray: