From c7b110feebff0bb7fcde361484435b9bd809687a Mon Sep 17 00:00:00 2001 From: mbsantiago Date: Tue, 12 Aug 2025 19:06:44 +0100 Subject: [PATCH] Limit number of parallel processes to match predictions and annotations --- src/batdetect2/train/callbacks.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/batdetect2/train/callbacks.py b/src/batdetect2/train/callbacks.py index aeeb819..edaf064 100644 --- a/src/batdetect2/train/callbacks.py +++ b/src/batdetect2/train/callbacks.py @@ -1,3 +1,4 @@ +import os from functools import partial from multiprocessing import Pool from typing import List, Optional, Tuple @@ -171,7 +172,8 @@ def _match_all_collected_examples( ) -> List[MatchEvaluation]: logger.info("Matching all annotations and predictions") - with Pool() as p: + cpu_count = os.cpu_count() or 1 + with Pool(processes=min(cpu_count, 4)) as p: matches = p.starmap( partial( match_sound_events_and_raw_predictions,