You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
dynamic thresholding -> threshold based, yields a sequence of non-overlapping segments
continuous element -> sequence of segments that possibly overlap in time. This starts with dynamic thresholding and then does some additional steps that I think are basically image segmenting?
what I think of as the "simplest" algorithm, as implemented in evfuncs:
I guess this is technically hresholding; it operates on the smoothed rectified audio waveform but the same logic can be applied to the spectral power (as if it were an audio amplitude trace)
Looks like they segment the spectrogram, i.e. summing spectral power in each time bin then thresholding that.
Interesting that they use multiple thresholds to find local maxima and minima. I wonder if that's more robust.
But the function uses a helper function get_spec so the caller has no control over how the spectrogram gets made.
Also there's a bunch of parameters hidden inside a dict p that gets passed to the function, can't say I'm crazy about that.
E.g., min_syl_dur and max_syl_dur that get unpacked from p.
Better to just make those explicit parameters of the function itself.
Otherwise it's not even obvious the function has that functionality.
Of course there's probably a reason that made sense at the time -- maybe it's a "config" that gets passed in from somewhere else?
But in that case you could do segment(**p) and unpack the args into the function.
Regardless (sorry for the impromptu code review) this is helpful to see. I bet segmenting from spectrograms is less variable than from audio
No problem @NickleDave - super helpful to hear your take on this! I’ve also been wondering/worrying about whether segmenting the spectrogram is better or worse than segmenting audio, but agree that segmenting from spectrograms is probably less variable.
Good idea, thank you @nickjourjine I should have thought to look at scikit-maad.
They have refs to papers in their docstrings, which is helpful for trying to figure out what algorithms come from where.
Interesting that find_rois_cwt uses wavelets, lets you specify flim, and returns segments as a dataframe ... those are three unrelated things, but I'm just trying to think about "what's the most useful API look like".
For both that and the 2d functions, I'm not crazy about hiding a plot function inside of another function, would rather have a plot module with classes for each plot that call their respective business logic functions. E.g., a vocalpy.plot.Rois2d would call a vocalpy.seg.2d.rois under the hood.
The data that I use to train tweetynet for segmentation is actually just simple amplitude thresholding, but I review the syllable boundaries manually and and/remove or adjust them so that syllables are being segmented consistently within and across birds. I do this with the evsonganaly GUI for MATLAB. I really only coded up MFCC derivative and RMSE derivative segmentation as something to benchmark the tweetynet segmentation against, and in terms of recapitulating those manually corrected amplitude-based segmentations tweetynet does do much better than either of those methods. Does that help?
Yes, that's all correct. I mean, I don't know if ZBs are the hardest, but they can be messier than people give them credit for. I haven't looked in detail at the implementation of amplitude thresholding in evsonganaly or your evfuncs, but my understanding is that RMSE is conceptually exactly the same as amplitude thresholding. I find that using the first derivative of RMSE is better than just using RMSE when it comes to syllable onsets, but it doesn't work great for syllable offsets, so using that method I include the subsequent silent gap in with the syllable (which isn't ideal for training tweetynet or doing any timing related analysis, but it can be good enough to cluster the syllables and get unsupervised labels). In my hands, MFCC derivative is more accurate than RMSE derivative but I have to admit I don't have a super strong grasp on why that is.
my understanding is that RMSE is conceptually exactly the same as amplitude thresholding
Not sure how much it matters but evsonganaly uses audio not a spectrogram, and it smooths then rectifies the waveform. Also not sure if it this helps with offsets, but agree that offsets are generally noisier (for BF song at least), because the amplitude tends to trail off instead of having a sharp offset. I blame the syrinx.
In my hands, MFCC derivative is more accurate than RMSE derivative but I have to admit I don't have a super strong grasp on why that is.
This is captured somewhat above but there's basically two main aspects of thresholding algorithms that might matter:
is it 1d or 2d, i.e. does it operate on the audio waveform or the spectrogram
does it use a fixed threshold or is it adaptive/dynamic
Anything else I'm missing?
E.g., Otsu's method is adaptive, like most segmenting methods adopted from imaging that use a watershed-type approach NickleDave/songdkl#58
Questions a practicioner might have is:
which ones are more reliable
for which setting / analysis?
e.g. for recording multiple animals housed in a group cage where the analysis focuses on calls, adaptive spectrogram thresholding might be most reliable
conversely for a single songbird isolated in a small soundbox with a mic directly over the cage where the analysis focuses on song elements, a fixed threshold method may be more reliable. Or not! If the bird moves around a lot
Activity
NickleDave commentedon Aug 10, 2022
Original algorithm (according to Fukuzawa): Rabiner and Sambur 1975 -- thresholds amplitude envelope, fine tunes using zero crossings.
Attached, Matlab implementation from https://www.mathworks.com/matlabcentral/fileexchange/70424-voice-activity-detection-vad-rabiner1975
upload.zip
NickleDave commentedon Aug 10, 2022
Note that @dgmets said in discussion with @sthaar and @yangzheng-121 that a similar approach that worked well was:
NickleDave commentedon Aug 10, 2022
The next algorithm after Rabiner + Sambur according to Fukuzawa is Harma
https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.217.9793&rep=rep1&type=pdf
A method tailored to birdsong that models syllables as sinusoidal
Matlab implementation here:
https://www.mathworks.com/matlabcentral/fileexchange/29261-harma-syllable-segmentation
Python implementation by Fukuzawa here:
https://github.com/fzyukio/koe/blob/1e490317a0a427a8a418bdbab61e3c0cda4bf55d/koe/management/commands/use_segmentation_harma.py
NickleDave commentedon Aug 18, 2022
Talking with @nickjourjine who mentioned they are using the segmentation functions built into AVA.
I'm guessing that it's similar to what's in
evfuncsbut it's always helpful to see multiple implementations -- and we might learn something?@nickjourjine can you post a link to that function?
If you find the code on
ava's GitHub repo, you can click on the line number to the left of the function signature and a context box with an ellipsis will pop up, that gives you the option to "copy permalink", as described here:https://docs.github.com/en/repositories/working-with-files/using-files/getting-permanent-links-to-files
For example here's a link to the segmenting code in
evfuncs:https://github.com/NickleDave/evfuncs/blob/fb4c71b845b3d0274848ab134b4c587578401775/src/evfuncs/evfuncs.py#L333
(which is literally
https://github.com/NickleDave/evfuncs/blob/fb4c71b845b3d0274848ab134b4c587578401775/src/evfuncs/evfuncs.py#L333before the GitHub UI converts it to a link)nickjourjine commentedon Aug 18, 2022
This is
ava's amplitude segmentation functionget_onsets_offsets: https://github.com/pearsonlab/autoencoded-vocal-analysis/blob/fac3b53280bdac95dd9fb5ab8e276fdb90dab1e3/ava/segmenting/amplitude_segmentation.py#L19NickleDave commentedon Aug 22, 2022
Thank you @nickjourjine
Looks like they segment the spectrogram, i.e. summing spectral power in each time bin then thresholding that.
Interesting that they use multiple thresholds to find local maxima and minima. I wonder if that's more robust.
But the function uses a helper function
get_specso the caller has no control over how the spectrogram gets made.Also there's a bunch of parameters hidden inside a dict
pthat gets passed to the function, can't say I'm crazy about that.E.g.,
min_syl_durandmax_syl_durthat get unpacked fromp.Better to just make those explicit parameters of the function itself.
Otherwise it's not even obvious the function has that functionality.
Of course there's probably a reason that made sense at the time -- maybe it's a "config" that gets passed in from somewhere else?
But in that case you could do
segment(**p)and unpack the args into the function.Regardless (sorry for the impromptu code review) this is helpful to see. I bet segmenting from spectrograms is less variable than from audio
nickjourjine commentedon Aug 30, 2022
No problem @NickleDave - super helpful to hear your take on this! I’ve also been wondering/worrying about whether segmenting the spectrogram is better or worse than segmenting audio, but agree that segmenting from spectrograms is probably less variable.
nickjourjine commentedon Aug 30, 2022
This package might be worth considering too: https://github.com/scikit-maad/scikit-maad
Intended for eco-acoustics but seems to have segmenting functions that could be broadly useful:
https://github.com/scikit-maad/scikit-maad/blob/46fd849679746fa4215bf899972507b2ac76e7c0/maad/rois/rois_1d.py#L4
https://github.com/scikit-maad/scikit-maad/blob/46fd849679746fa4215bf899972507b2ac76e7c0/maad/rois/rois_2d.py#L3
NickleDave commentedon Aug 30, 2022
Good idea, thank you @nickjourjine I should have thought to look at
scikit-maad.They have refs to papers in their docstrings, which is helpful for trying to figure out what algorithms come from where.
Interesting that
find_rois_cwtuses wavelets, lets you specifyflim, and returns segments as a dataframe ... those are three unrelated things, but I'm just trying to think about "what's the most useful API look like".For both that and the 2d functions, I'm not crazy about hiding a plot function inside of another function, would rather have a
plotmodule with classes for each plot that call their respective business logic functions. E.g., avocalpy.plot.Rois2dwould call avocalpy.seg.2d.roisunder the hood.NickleDave commentedon Sep 7, 2022
Adding one more:
@sthaar asked when we met last what @theresekoch is using to segment zebra finch song before training
tweetynet(@theresekoch apologies in advance for dragging you into a random github issue but please do feel free to chime in)
From the
avndocs, looks like the default method is MFCC derivative threshold segmentationhttps://avn.readthedocs.io/en/latest/tutorial.html#Simple-Segmentation
The first derivative of the MFCC looks something like this (again from the

avndocs)(from https://avn.readthedocs.io/en/latest/tutorial.html#Manual-Threshold-Selection)
@arnavraha you may also want to try this.
Looks like there is also functionality to optimize the threshold and compute metrics like F1
theresekoch commentedon Sep 7, 2022
The data that I use to train tweetynet for segmentation is actually just simple amplitude thresholding, but I review the syllable boundaries manually and and/remove or adjust them so that syllables are being segmented consistently within and across birds. I do this with the evsonganaly GUI for MATLAB. I really only coded up MFCC derivative and RMSE derivative segmentation as something to benchmark the tweetynet segmentation against, and in terms of recapitulating those manually corrected amplitude-based segmentations tweetynet does do much better than either of those methods. Does that help?
NickleDave commentedon Sep 8, 2022
Yes, very much so, thank you for letting us know @theresekoch
To make sure I understand:
https://github.com/NickleDave/evfuncs/blob/fb4c71b845b3d0274848ab134b4c587578401775/src/evfuncs/evfuncs.py#L333
Did you find that the MFCC and RMSE derivatives were any more consistent then good ol' amplitude thresholding?
theresekoch commentedon Sep 8, 2022
Yes, that's all correct. I mean, I don't know if ZBs are the hardest, but they can be messier than people give them credit for. I haven't looked in detail at the implementation of amplitude thresholding in evsonganaly or your evfuncs, but my understanding is that RMSE is conceptually exactly the same as amplitude thresholding. I find that using the first derivative of RMSE is better than just using RMSE when it comes to syllable onsets, but it doesn't work great for syllable offsets, so using that method I include the subsequent silent gap in with the syllable (which isn't ideal for training tweetynet or doing any timing related analysis, but it can be good enough to cluster the syllables and get unsupervised labels). In my hands, MFCC derivative is more accurate than RMSE derivative but I have to admit I don't have a super strong grasp on why that is.
NickleDave commentedon Sep 8, 2022
Very helpful to know, thank you.
Not sure how much it matters but evsonganaly uses audio not a spectrogram, and it smooths then rectifies the waveform. Also not sure if it this helps with offsets, but agree that offsets are generally noisier (for BF song at least), because the amplitude tends to trail off instead of having a sharp offset. I blame the syrinx.
Interesting. I wonder if it's because the MFCC is supposed to better capture slower varying lower frequencies? (I'm pretending I understand how they work, nota bene).
For future reference, good post here:
http://practicalcryptography.com/miscellaneous/machine-learning/guide-mel-frequency-cepstral-coefficients-mfccs/
NickleDave commentedon Nov 5, 2022
Returning to this after recent discussions with @dgmets @sthaar and @yangzheng-121
This is captured somewhat above but there's basically two main aspects of thresholding algorithms that might matter:
Anything else I'm missing?
E.g., Otsu's method is adaptive, like most segmenting methods adopted from imaging that use a watershed-type approach
NickleDave/songdkl#58
Questions a practicioner might have is:
Almost like someone needs to benchmark this 😈