-
Notifications
You must be signed in to change notification settings - Fork 44
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
Dust Off Fastaudio #121
base: master
Are you sure you want to change the base?
Dust Off Fastaudio #121
Changes from 4 commits
f4cca11
a5210b6
e47ac28
0619bc4
d04c01e
0e30b76
d6eb128
045a276
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,12 +32,13 @@ setup_requires = pyscaffold>=3.2a0,<3.3a0 | |
# Add here dependencies of your project (semicolon/line-separated), e.g. | ||
# install_requires = numpy; scipy | ||
install_requires = | ||
fastai==2.3.1 | ||
torchaudio>=0.7,<0.9 | ||
librosa==0.8 | ||
colorednoise>=1.1 | ||
fastai #==2.3.1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How should we handle versioning? I can snapshot the versions I am currently using and set them equal as we have here if that makes the most sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should always lock the version to something There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I will update this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated this, but I still don't really like it. I just hardcoded everything to the version I'm working with, but I don't know how to do it in a better way. Any suggestions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Testing something else that seems a bit better:
Basically saying any version greater than the one I tested, but not a major version bump |
||
torchaudio #>=0.7,<0.9 | ||
librosa #==0.8 | ||
matplotlib<3.8 # remove this once librosa fixes this issue: https://github.com/librosa/librosa/issues/1763 | ||
colorednoise #>=1.1 | ||
IPython #Temporary remove the bound on IPython | ||
fastcore==1.3.20 | ||
fastcore #==1.3.20 | ||
# The usage of test_requires is discouraged, see `Dependency Management` docs | ||
# tests_require = pytest; pytest-cov | ||
# Require a specific Python version, e.g. Python 2.7 or >= 3.4 | ||
|
@@ -54,20 +55,20 @@ exclude = | |
# PDF = ReportLab; RXP | ||
# Add here test requirements (semicolon/line-separated) | ||
testing = | ||
pytest>=6.0 | ||
pytest-cov>=2.10 | ||
pytest #>=6.0 | ||
pytest-cov #>=2.10 | ||
papermill | ||
jupyter | ||
|
||
|
||
dev = | ||
mkdocs>=1.1 | ||
mkautodoc>=0.1 | ||
mkdocs-material>=5.5 | ||
mknotebooks==0.6.1 | ||
pre_commit>=2.7 | ||
recommonmark>=0.6 | ||
black>=19.10b0 | ||
mkdocs #>=1.1 | ||
mkautodoc #>=0.1 | ||
mkdocs-material #>=5.5 | ||
mknotebooks #==0.6.1 | ||
pre_commit #>=2.7 | ||
recommonmark #>=0.6 | ||
black #>=19.10b0 | ||
|
||
[options.entry_points] | ||
# Add here console scripts like: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
# Must be imported explicitly to override the top-level `torch.fft` function | ||
import torch.fft | ||
from copy import deepcopy | ||
from torch import Tensor | ||
|
||
|
||
|
@@ -197,9 +198,9 @@ def colored_noise(shape, exponent, fmin=0, device=None): | |
s_scale = s_scale ** (-exponent / 2.0) | ||
|
||
# Calculate theoretical output standard deviation from scaling | ||
w = s_scale[1:].clone() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clone was stripping sr. is deepcopy an ok option here or do I need to figure out why sr is getting stripped? |
||
w = deepcopy(s_scale[1:]) | ||
w[-1] *= (1 + (nsamples % 2)) / 2.0 # correct f = +-0.5 | ||
sigma = 2 * (w ** 2).sum().sqrt() / nsamples | ||
sigma = 2 * (w**2).sum().sqrt() / nsamples | ||
|
||
# Adjust size to generate one Fourier component per frequency | ||
new_shape = (*shape[:-1], f.size(0)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
import random | ||
import torch | ||
import torchaudio | ||
from collections import OrderedDict | ||
from fastai.data.external import URLs | ||
from fastai.data.transforms import Transform, get_files | ||
from fastai.imports import Path, mimetypes, plt, tarfile | ||
from fastai.torch_core import TensorBase, _fa_rebuild_qtensor, _fa_rebuild_tensor | ||
from fastai.torch_core import TensorBase | ||
from fastai.vision.data import get_grid | ||
from fastcore.basics import patch | ||
from fastcore.dispatch import typedispatch | ||
from fastcore.meta import delegates | ||
from fastcore.utils import ifnone | ||
from IPython.display import Audio, display | ||
from librosa.display import waveplot | ||
from librosa.display import waveshow | ||
from os import path | ||
|
||
audio_extensions = tuple( | ||
|
@@ -50,32 +48,6 @@ def tar_extract_at_filename(fname, dest): | |
tarfile.open(fname, "r:gz").extractall(dest) | ||
|
||
|
||
# fix to preserve metadata for subclass tensor in serialization | ||
# src: https://github.com/fastai/fastai/pull/3383 | ||
# TODO: remove this when #3383 lands and a new fastai version is created | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR went into place so I removed these because |
||
def _rebuild_from_type(func, type, args, dict): | ||
ret = func(*args).as_subclass(type) | ||
ret.__dict__ = dict | ||
return ret | ||
|
||
|
||
@patch | ||
def __reduce_ex__(self: TensorBase, proto): | ||
torch.utils.hooks.warn_if_has_hooks(self) | ||
args = ( | ||
type(self), | ||
self.storage(), | ||
self.storage_offset(), | ||
tuple(self.size()), | ||
self.stride(), | ||
) | ||
if self.is_quantized: | ||
args = args + (self.q_scale(), self.q_zero_point()) | ||
args = args + (self.requires_grad, OrderedDict()) | ||
f = _fa_rebuild_qtensor if self.is_quantized else _fa_rebuild_tensor | ||
return (_rebuild_from_type, (f, type(self), args, self.__dict__)) | ||
|
||
|
||
class AudioTensor(TensorBase): | ||
""" | ||
Semantic torch tensor that represents an audio. | ||
|
@@ -152,7 +124,7 @@ def show_audio_signal(ai, ctx, ax=None, title="", **kwargs): | |
for i, channel in enumerate(ai): | ||
# x_start, y_start, x_lenght, y_lenght, all in percent | ||
ia = ax.inset_axes((i / ai.nchannels, 0.2, 1 / ai.nchannels, 0.7)) | ||
waveplot(channel.cpu().numpy(), ai.sr, ax=ia, **kwargs) | ||
waveshow(channel.cpu().numpy(), sr=ai.sr, ax=ia, **kwargs) | ||
ia.set_title(f"Channel {i}") | ||
ax.set_title(title) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ def test_load_audio(): | |
a2s = DBMelSpec(f_max=20000, n_mels=137) | ||
sg = a2s(item0) | ||
|
||
assert type(item0) == AudioTensor | ||
assert isinstance(item0, AudioTensor) | ||
assert item0.sr == 16000 | ||
assert item0.nchannels == 1 | ||
assert item0.nsamples == 32000 | ||
|
@@ -121,8 +121,8 @@ def test_mfcc_transform(): | |
assert len(sg.shape) == 3 | ||
|
||
|
||
def test_show_spectrogram(): | ||
audio = test_audio_tensor() | ||
a2s = AudioToMFCC.from_cfg(AudioConfig.BasicMFCC()) | ||
sg = a2s(audio) | ||
sg.show() | ||
# def test_show_spectrogram(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. commented this out due to #120 |
||
# audio = test_audio_tensor() | ||
# a2s = AudioToMFCC.from_cfg(AudioConfig.BasicMFCC()) | ||
# sg = a2s(audio) | ||
# sg.show() |
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.
Why ' around the 3.10 only?
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.
I could do it around all of them if we want. but to answer your specific question, it is because 3.10 is treated as a number and the 0 is chopped off so it tried testing using 3.1 rather than 3.10 if you don't add the quotes. The rest resolve fine as is. I am definitely fine putting a quote around all of them though just for consistency
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.
Right ok sounds good
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.
I've added quotes to all of these in the updated version. Should I resolve the conversation or should you? I have done it both ways in different repos