Skip to content

Commit

Permalink
fix bug with short recs
Browse files Browse the repository at this point in the history
  • Loading branch information
gferraro committed May 9, 2023
1 parent 6ad1a06 commit e6cff71
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Melt/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def calc_cacophony_index(tracks, length):
# some recordings are 61 seconds just make last bin size slightly bigger
last_bin_size = length - period_length * (bins - 1)
last_bin = None
if last_bin_size < 2:
if bins > 1 and last_bin_size < 2:
bins -= 1
last_bin = length
percents = []
Expand Down
2 changes: 1 addition & 1 deletion Melt/identify_bird.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def load_samples(
end = segment_length
mel_samples = []
i = 0
while end < (length + stride):
while i == 0 or end < (length + stride):
if end > length:
# always use end ofr last sample
data = frames[-sample_size:]
Expand Down
11 changes: 11 additions & 0 deletions Melt/identify_species.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ def identify_species(recording, models):
sample = librosa.amplitude_to_db(sample, ref=np.max)
if sample.min() != 0:
sample = sample / abs(sample.min()) + 1.0
if sample.shape[1] < 60:
sample = np.pad(
sample,
(
(
0,
0,
),
(0, 60 - sample.shape[1]),
),
)
samples.append(sample.reshape(sample.shape + (1,)))
samples = np.array(samples)

Expand Down

0 comments on commit e6cff71

Please sign in to comment.