From 9caea73bc3263077e057886eee2ce2a95e1e139d Mon Sep 17 00:00:00 2001 From: danellecline Date: Mon, 29 Apr 2024 18:20:53 -0700 Subject: [PATCH] fix: sorted order needed to make start/end filtering work --- sdcat/cluster/commands.py | 3 +++ sdcat/detect/commands.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/sdcat/cluster/commands.py b/sdcat/cluster/commands.py index 51cc60e..742255e 100644 --- a/sdcat/cluster/commands.py +++ b/sdcat/cluster/commands.py @@ -89,6 +89,9 @@ def run_cluster(det_dir, save_dir, device, config_ini, alpha, cluster_selection_ err(f'Found {df["image_path"].isnull().sum()} detections with no image_path') return + # Sort the dataframe by image_path to make sure the images are in order for start_image and end_image filtering + df = df.sort_values(by='image_path') + # If start_image is set, find the index of the start_image in the list of images if start_image: start_image = Path(start_image) diff --git a/sdcat/detect/commands.py b/sdcat/detect/commands.py index 58f2446..8791f4e 100644 --- a/sdcat/detect/commands.py +++ b/sdcat/detect/commands.py @@ -150,9 +150,9 @@ def run_detect(show: bool, image_dir: str, save_dir: str, model: str, save_path_det_filtered.mkdir(parents=True, exist_ok=True) save_path_viz.mkdir(parents=True, exist_ok=True) - # Run on all images recursively + # Run on all images recursively. Sort the dataframe by image_path to make sure the images are in order for start_image and end_image filtering # Find all valid images - images = [file for file in images_path.rglob('*') + images = [file for file in sorted(images_path.rglob('*')) if file.as_posix().endswith(('jpeg', 'png', 'jpg', 'JPEG', 'PNG', 'JPG', 'tif', 'tiff'))] # If start_image is set, find the index of the start_image in the list of images