From 44efd36bdc58ac079b8ee0c4cc5387a82c1e928b Mon Sep 17 00:00:00 2001 From: Kentaro Wada Date: Sun, 31 Dec 2023 13:44:03 +0900 Subject: [PATCH] Refactor regex filename search --- labelme/app.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/labelme/app.py b/labelme/app.py index 8a82d6510..b378c14d1 100644 --- a/labelme/app.py +++ b/labelme/app.py @@ -2069,13 +2069,14 @@ def importDirImages(self, dirpath, pattern=None, load=True): self.lastOpenDir = dirpath self.filename = None self.fileListWidget.clear() - for filename in self.scanAllImages(dirpath): - if pattern and pattern not in filename: - try: - if not re.search(pattern, filename): - continue - except re.error: - pass + + filenames = self.scanAllImages(dirpath) + if pattern: + try: + filenames = [f for f in filenames if re.search(pattern, f)] + except re.error: + pass + for filename in filenames: label_file = osp.splitext(filename)[0] + ".json" if self.output_dir: label_file_without_path = osp.basename(label_file)