From b7e913e855899c90c89eaa3f32d6156a8ffc6849 Mon Sep 17 00:00:00 2001 From: danellecline Date: Tue, 29 Oct 2024 08:33:31 -0700 Subject: [PATCH] perf: always run saliency on multiproc regardless of cpu or gpu as it is not gpu enabled --- sdcat/detect/commands.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/sdcat/detect/commands.py b/sdcat/detect/commands.py index 0a93a9d..84ae57f 100644 --- a/sdcat/detect/commands.py +++ b/sdcat/detect/commands.py @@ -210,7 +210,7 @@ def run_detect(show: bool, image_dir: str, save_dir: str, model: str, if num_images == 0: return - if device == 'cpu': + if not skip_saliency: # run_saliency_detect(spec_remove, scale_percent, images[0].as_posix(), (save_path_det_raw / f'{images[0].stem}.csv').as_posix(), clahe=clahe, show=True) # Do the work in parallel to speed up the processing on multicore machines num_processes = multiprocessing.cpu_count() @@ -218,25 +218,25 @@ def run_detect(show: bool, image_dir: str, save_dir: str, model: str, info(f'Using {num_processes} processes to compute {num_images} images 10 at a time ...') # # Run multiple processes in parallel num_cpu images at a time with multiprocessing.Pool(num_processes) as pool: - if not skip_saliency: - args = [(spec_remove, - scale_percent, - images[i:i + 1], - save_path_det_raw, - min_std, - block_size, - clahe, - show) - for i in range(0, num_images, 1)] - pool.starmap(run_saliency_detect_bulk, args) - pool.close() + args = [(spec_remove, + scale_percent, + images[i:i + 1], + save_path_det_raw, + min_std, + block_size, + clahe, + show) + for i in range(0, num_images, 1)] + pool.starmap(run_saliency_detect_bulk, args) + pool.close() + if device == 'cpu': with multiprocessing.Pool(num_processes) as pool: if not skip_sahi: # Run sahi detection on each image args = [(scale_percent, slice_size_width, slice_size_height, - images[i:i + 10], + [image], save_path_det_raw, detection_model, postprocess_match_metric, @@ -244,7 +244,7 @@ def run_detect(show: bool, image_dir: str, save_dir: str, model: str, overlap_height_ratio, allowable_classes, class_agnostic) - for i in range(0, num_images, 1)] + for image in images] pool.starmap(run_sahi_detect_bulk, args) pool.close() else: