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
18 changes: 16 additions & 2 deletions labelme/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import webbrowser

import imgviz
import natsort
from natsort import os_sorted
import numpy as np
from loguru import logger
from numpy.typing import NDArray
Expand Down Expand Up @@ -2206,6 +2206,16 @@ def importDirImages(self, dirpath, pattern=None, load=True):
self.fileListWidget.addItem(item)
self.openNextImg(load=load)

def custom_natsorted(self, items):
"""
custom sort function for file path with @ symbol
"""
def key_func(item):
# @ symbol to separate other characters
return tuple(int(c) if c.isdigit() else c for c in re.split(r'(@)', str(item)))

return sorted(items, key=key_func)

def scanAllImages(self, folderPath):
extensions = [
f".{fmt.data().decode().lower()}"
Expand All @@ -2218,5 +2228,9 @@ def scanAllImages(self, folderPath):
if file.lower().endswith(tuple(extensions)):
relativePath = os.path.normpath(osp.join(root, file))
images.append(relativePath)
images = natsort.os_sorted(images)
try:
images = os_sorted(images)
except Exception as e:
logger.debug(f"natsort's sort failed, falling back to the custom sort method: {e}")
images = self.custom_natsorted(images)
return images