From 1be45ef2db75354110b3c0f757c3b79ce2ca6718 Mon Sep 17 00:00:00 2001 From: gferraro Date: Thu, 10 Jun 2021 13:49:44 +1200 Subject: [PATCH] avoid nan error --- Melt/identify_species.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Melt/identify_species.py b/Melt/identify_species.py index da75ef5..607a28c 100644 --- a/Melt/identify_species.py +++ b/Melt/identify_species.py @@ -144,8 +144,10 @@ def identify_species(recording, metadata, models): start = limit - slices_per_sample start_times.append(start / slices_per_second) sample = npspec[:, start:limit] + sample = librosa.amplitude_to_db(sample, ref=np.max) - sample = sample / abs(sample.min()) + 1.0 + if sample.min() != 0: + sample = sample / abs(sample.min()) + 1.0 samples.append(sample.reshape(sample.shape + (1,))) samples = np.array(samples)