Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion scripts/convert_to_lerobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,29 @@
def get_subdirectories(path: Path) -> list[Path]:
return sorted([p for p in path.iterdir() if p.is_dir()])


# Get the paths of files within a directory.
def _natural_sort_key(path: Path):
name = path.name
key = []
i = 0
while i < len(name):
if name[i].isdigit():
j = i
while j < len(name) and name[j].isdigit():
j += 1
key.append((0, int(name[i:j])))
i = j
else:
j = i
while j < len(name) and not name[j].isdigit():
j += 1
key.append((1, name[i:j].lower()))
i = j
return key

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:
Expand Down