-
Notifications
You must be signed in to change notification settings - Fork 665
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
Centroid frequency limits #2061
base: main
Are you sure you want to change the base?
Conversation
Hi @jacobjwebber! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution. I think I understand the gist of the new logic, but can you add a test code that explains the desired behavior?
max_freq_index = int(round((max_freq * fft_bins) / nyquist)) if max_freq is not None else fft_bins | ||
|
||
if min_freq is not None or max_freq is not None: | ||
assert min_freq_index < max_freq_index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of checking the value here, the check on the given arguments should happen at the beginning of the argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't fully understand this. Would you mind explaining?
specgram = spectrogram(waveform, pad=pad, window=window, n_fft=n_fft, hop_length=hop_length, | ||
win_length=win_length, power=1., normalized=False) | ||
freqs = torch.linspace(0, sample_rate // 2, steps=1 + n_fft // 2, | ||
device=specgram.device).reshape((-1, 1)) | ||
|
||
min_freq_index = int(round((min_freq * fft_bins) / nyquist)) if min_freq is not None else 0 | ||
max_freq_index = int(round((max_freq * fft_bins) / nyquist)) if max_freq is not None else fft_bins |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC TorchScript does not handle ternary operator. Can you run pytest test/torchaudio_unittest/transforms/torchscript_consistency_cpu_test.py -k Centroid
and see if it works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, this test seems to pass on my system. Should I still swap out the ternary?
CircleCI is not getting triggered. Let me close and reopen the PR to see if it helps. |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
Use variables to make code more readable Co-authored-by: moto <855818+mthrok@users.noreply.github.com>
Hi @mthrok, sorry for taking a little while to get back to you. I added a test in batch_consistency_test.py for the new behaviour -- I am not sure if this is the right place. The basic idea of why you would want this is that you might want the centroid of a specific range of frequencies. I used this recently because I only wanted the centroid of voiced frequencies. A downside of accepting this is that it adds features that aren't present in librosa. I think this transform was initially intended to clone a function from that library |
All it needed is adding missing `deep_phonemizer` package to `requirements.txt`
It was mentioned in #1059 that it might be good to support a narrow range of frequencies to find the spectral centroid. This is an attempt at that.
Apologies if this is not correct, it is my first attempt at a PR for pytorch/audio!