From 69839fcd580a66d2710b27a113745e93f601a2b9 Mon Sep 17 00:00:00 2001 From: Cedric Spindler Date: Sun, 10 Dec 2023 21:34:42 +0100 Subject: [PATCH] Don't regenerate files if they exist --- batdetect2_gui/generate_data.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/batdetect2_gui/generate_data.py b/batdetect2_gui/generate_data.py index cde4130..cd0998b 100644 --- a/batdetect2_gui/generate_data.py +++ b/batdetect2_gui/generate_data.py @@ -68,9 +68,12 @@ def compute_image_data(audio_raw, sampling_rate, spec_params, reference): segment_width = spec.shape[1] // n_segments dims = (spec.shape[0], spec.shape[1]) - os.makedirs("data", exist_ok=True) + if os.path.exists(f'data/{os.path.basename(reference)}_15.jpg'): + print("Spectrogram already generated.") + return [f'data/{os.path.basename(reference)}_{i}.jpg' for i in range(n_segments)], dims # split spec into multiple parts along the x axis + os.makedirs("data", exist_ok=True) im_paths = [] for i in range(n_segments): start = i * segment_width