New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
onset_strength_multi uses nfft=2048 and hop_length=512 by default instead of preset values #989
Comments
Thanks for catching that. I've tested it locally, and confirm that presets doesn't correctly handle this particular case. In general, presets will not be able to detect this sort of thing. The two fixes that come to mind are:
(1) is the easiest to fix, though it comes up in a few places and will require careful thought to do correctly. (2) might be unexpectedly tricky, and still not give you an out-of-the-box solution, but I think it's the only way to reliably work around dynamic kwargs getting. Maybe @beasteers has some thoughts on this too? |
Yeah this is a problem with kw args and setting defaults via signature inspection. One of the issues that is more of an issue is subclassing/function wrapping (where we use class SpecialMel(Mel):
def __init__(self, *a, blah=10, **kw):
self.blah = blah
return super().__init__(*a, **kw) We can't set the defaults for params passed to Another issue is that inter module references are not updated. For example, you might expect thatt from presets import librosa
librosa.update(dict(n_mels=256, nfft=4096, sr=None))
y, sr = librosa.load(librosa.util.example_audio_file())
S = librosa.feature.melspectrogram(y=y, sr=sr)
# S.shape == (128, 2647) # expected 256, :/ I'm not sure of an automated way to address this. I would say librosa.update(dict(sr=44100))
librosa.scope_update({
'core.onset_strength_multi': dict(nfft=1024)
}) Or maybe this too ? librosa.update(dict(sr=44100, nfft=1024))
librosa.scope_update({
'core.onset_strength_multi': dict(nfft=...) # filled with 1024
}) And then we can use |
To bad there's no way to pass a custom |
mir_eval does this sort of thing in its submodule-level Digging through our codebase for fishy kwarg usage turns up the following: get
I'm generally fine with promoting those parameters up to their containing functions in these cases; using kwargs for this was just lazy. This change would not incur any compatibility issues, so I'm fine with rolling it into 0.7.1. The odd one out here is set
There's quite a bit more going on here, but I the unifying theme is to propagate default values that can be directly overridden. If presets doesn't work in these cases, that's a problem with presets, and not our usage here. Proposed solutionFix the two cases in Does that sound reasonable? @beasteers ? |
I like the idea, but it would fail in a case like this (which I don't think is more common than uncommon): def a(a=1, b=2, c=3):
pass
def b(d, e, f, **kw):
return a(**kw)
b(4, 5, 6, a=3, y=8) # `y` gets passed to `a()` So I agree that it's a bit hacky here. (Though I must admit, I've been tempted on several occasions to implement something like that for myself.) Yeah I agree that those So yep. Sounds reasonable. 👍🏻 |
Ok, I'll put out a PR this afternoon to fix this one up. |
Correct me if I'm wrong but I believe it happens here. The default values are hard coded inside the function instead of in the list of key word arguments like usual. So when setting a preset using the presets library with e.g. sr=44100, nfft=4096 and hop_length=1024, the new default values are not used.
The text was updated successfully, but these errors were encountered: