[Invitation to open collaboration] Practice what you learn in the course and help animal researchers! šŸµ

fastai2            0.0.17              
fastcore           0.1.17             
fastprogress       0.2.4               
torch              1.4.0
torchaudio         0.4.0
torchvision        0.5.0

I canā€™t find the sox package.

Hereā€™s the latest version of the notebook.

2 Likes

Hi all,

I finally got torchaudio to import, after spending yet another whole afternoon on these unending configuration errors. I am pissed off that I waste half my waking hours reading obtuse, contradictory stack overflow answers, installing and uninstalling in every order, trying older and newer versions, rebuilding environments, etc.

Here are the steps that worked for me. YMMV:

  1. Re-create a completely fresh fastai2 conda environment using the instructions at
    https://forums.fast.ai/t/platform-local-server-ubuntu/65851?u=pomo

  2. The notebook did not know about torchaudio, so I found it on the anaconda.org website. That page states that conda install -c pytorch torchaudio will install torchaudio 0.4.0. Instead it actually installs torchaudio 0.2.0.

Can anyone in the Universe explain why? I want to see if my head explodes.

  1. In any case, import torchaudio still fails with the same uninterpretable error message as above.

  2. conda uninstall torchaudio followed by pip install torchaudio installs torchaudio 0.4.0. Florianā€™s listing of versions provided a clue.

  3. import torchaudio now works inside a Jupyter notebook. Yay!

One more question in addition to the head-exploding one. What is the best way to keep my fastai2 conda environment up to date? I donā€™t need the latest development versions, just the current master release that mostly works. Iā€™ve been using pip install fastai2 fastcore --upgrade. Is it right?

Thanks for listening and for helping.

Florian,

Would you please take a look at this error? Thanks.

device
device(type='cuda', index=0)

learn.lr_find()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-13-d81c6bd29d71> in <module>
----> 1 learn.lr_find()

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastai2/callback/schedule.py in lr_find(self, start_lr, end_lr, num_it, stop_div, show_plot, suggestions)
    221     n_epoch = num_it//len(self.dls.train) + 1
    222     cb=LRFinder(start_lr=start_lr, end_lr=end_lr, num_it=num_it, stop_div=stop_div)
--> 223     with self.no_logging(): self.fit(n_epoch, cbs=cb)
    224     if show_plot: self.recorder.plot_lr_find()
    225     if suggestions:

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastai2/learner.py in fit(self, n_epoch, lr, wd, cbs, reset_opt)
    190                     try:
    191                         self.epoch=epoch;          self('begin_epoch')
--> 192                         self._do_epoch_train()
    193                         self._do_epoch_validate()
    194                     except CancelEpochException:   self('after_cancel_epoch')

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastai2/learner.py in _do_epoch_train(self)
    163         try:
    164             self.dl = self.dls.train;                        self('begin_train')
--> 165             self.all_batches()
    166         except CancelTrainException:                         self('after_cancel_train')
    167         finally:                                             self('after_train')

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastai2/learner.py in all_batches(self)
    141     def all_batches(self):
    142         self.n_iter = len(self.dl)
--> 143         for o in enumerate(self.dl): self.one_batch(*o)
    144 
    145     def one_batch(self, i, b):

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastai2/data/load.py in __iter__(self)
     97         for b in _loaders[self.fake_l.num_workers==0](self.fake_l):
     98             if self.device is not None: b = to_device(b, self.device)
---> 99             yield self.after_batch(b)
    100         self.after_iter()
    101         if hasattr(self, 'it'): delattr(self, 'it')

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastcore/transform.py in __call__(self, o)
    183         self.fs.append(t)
    184 
--> 185     def __call__(self, o): return compose_tfms(o, tfms=self.fs, split_idx=self.split_idx)
    186     def __repr__(self): return f"Pipeline: {' -> '.join([f.name for f in self.fs if f.name != 'noop'])}"
    187     def __getitem__(self,i): return self.fs[i]

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastcore/transform.py in compose_tfms(x, tfms, is_enc, reverse, **kwargs)
    136     for f in tfms:
    137         if not is_enc: f = f.decode
--> 138         x = f(x, **kwargs)
    139     return x
    140 

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastai2/vision/augment.py in __call__(self, b, split_idx, **kwargs)
     31     def __call__(self, b, split_idx=None, **kwargs):
     32         self.before_call(b, split_idx=split_idx)
---> 33         return super().__call__(b, split_idx=split_idx, **kwargs) if self.do else b
     34 
     35 # Cell

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastcore/transform.py in __call__(self, x, **kwargs)
     70     @property
     71     def name(self): return getattr(self, '_name', _get_name(self))
---> 72     def __call__(self, x, **kwargs): return self._call('encodes', x, **kwargs)
     73     def decode  (self, x, **kwargs): return self._call('decodes', x, **kwargs)
     74     def __repr__(self): return f'{self.name}: {self.encodes} {self.decodes}'

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastcore/transform.py in _call(self, fn, x, split_idx, **kwargs)
     80     def _call(self, fn, x, split_idx=None, **kwargs):
     81         if split_idx!=self.split_idx and self.split_idx is not None: return x
---> 82         return self._do_call(getattr(self, fn), x, **kwargs)
     83 
     84     def _do_call(self, f, x, **kwargs):

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastcore/transform.py in _do_call(self, f, x, **kwargs)
     85         if not _is_tuple(x):
     86             return x if f is None else retain_type(f(x, **kwargs), x, f.returns_none(x))
---> 87         res = tuple(self._do_call(f, x_, **kwargs) for x_ in x)
     88         return retain_type(res, x)
     89 

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastcore/transform.py in <genexpr>(.0)
     85         if not _is_tuple(x):
     86             return x if f is None else retain_type(f(x, **kwargs), x, f.returns_none(x))
---> 87         res = tuple(self._do_call(f, x_, **kwargs) for x_ in x)
     88         return retain_type(res, x)
     89 

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastcore/transform.py in _do_call(self, f, x, **kwargs)
     84     def _do_call(self, f, x, **kwargs):
     85         if not _is_tuple(x):
---> 86             return x if f is None else retain_type(f(x, **kwargs), x, f.returns_none(x))
     87         res = tuple(self._do_call(f, x_, **kwargs) for x_ in x)
     88         return retain_type(res, x)

~/anaconda3/envs/fastai2/lib/python3.7/site-packages/fastcore/dispatch.py in __call__(self, *args, **kwargs)
     96         if not f: return args[0]
     97         if self.inst is not None: f = MethodType(f, self.inst)
---> 98         return f(*args, **kwargs)
     99 
    100     def __get__(self, inst, owner):

<ipython-input-4-ad044bf89bcd> in encodes(self, o)
     83     def encodes(self, o: TensorAudio):
     84         noise_amp = (0.001*torch.rand(1) * torch.max(o)).to(self.device)
---> 85         o = (o + noise_amp * torch.empty(o.shape).normal_()).to(self.device)
     86         return o
     87 

RuntimeError: expected device cuda:0 but got device cpu


(fastai2) malcolm@PC-GPU:~$ conda list fast
# packages in environment at /home/malcolm/anaconda3/envs/fastai2:
#
# Name                    Version                   Build  Channel
fastai2                   0.0.16                   pypi_0    pypi
fastcore                  0.1.16                   pypi_0    pypi
fastprogress              0.2.3                      py_0    conda-forge
fastscript                0.1.4                    pypi_0    pypi

Sorry, was a bug in the noise transform. I updated the notebook. Could you please try again? :slight_smile: ?

2 Likes

Hi Florian. Yes, I got it working! (There was an error loading one audio sample file, fixed by re-downloading the macaque calls. Hope it is not a sign of my disk failing.)

Even though Iā€™ve experimented with your notebook for only a short time, I have to say it is a brilliant approach. You adopted the proven, refined techniques for image processing directly into audio, with minimal redesign. Itā€™s a kind of architectural transfer learning.

Thanks also for showing how to use fastai2 correctly to construct the data pipeline, and with transforms. It would have taken me a week to figure all that out.

I think that your work opens up many potential directions for this project.

1 Like

Thanks Florian!

Next question :slight_smile: : Is there any real advantage in coding AudioFixLength from scratch, as compared to just using librosaā€™s fix_length function? I know one has to convert to numpty and back, is that the reason?

Would someone please assist me in using fastai2?

  1. Suppose I have a model (model) and a PyTorch DataSets (dst, dsv), one for training and one for validation. How do I get from there to a DataBlock and a Learner?

  2. Is there any way to search the fastai2 docs, as we can with https://docs.fast.ai/?

This task must be very simple, but I just canā€™t figure out how to navigate the API.

Thank you!

This is a tutorial in fastai2 which included an example of creating dataloader from pytorch dataset https://dev.fast.ai/tutorial.siamese

For project developed with nbdev, normally you can find the doc link directly on top of the github repo

1 Like

not really :smiley: i tried to use torchaudio instead of librosa so I had to code it from scratch. I code the transforms to get used to the DataBlocks and Transforms of fastai2. I guess it would be best to just use https://github.com/rbracco/fastai2_audio (I think they do great work!) for the DataBlocks etc ā€¦ and just use a custom Conv1d model. I havenā€™t had the time to look deeper into fastai2_audio so I just stick to my code.

Also I tried the 1d resnet approach on different datasets:


got very poor results (40 - 60 % accuracy depending on the fold)


very good results, 96% on the local validation set. havenā€™t submitted to Kaggle to see the results for the test set.

So i am still not sure if the 1d CNN approach is better than using spectrograms. Iā€™d like to find out how to make a fine-tunable model.

  1. Train on a bigger dataset
  2. learn.export()
  3. replace the data loaders in the learner (is that possible?) with a new dataset
  4. Cut the ā€œheadā€ (linear layer) and replace it with one that matches the number of classes of the new dataset

Has anyone an Idea how to do that? Is there a way to replace the dataloaders?

3 Likes

What I have done in another context is:

  • save just the trained model weights
  • recreate the original model
  • load the saved weights
  • edit the model head
  • create a new Learner with the new Dataset and edited model

Itā€™s probably not the best way, but it seems to work. Did you find that directly replacing the DataLoaders can work?

One point I am not completely sure of is whether fastai2ā€™s Learner will correctly grab the trainable parameters of the new head.

Hi everyone. I just made some revisions to ROCKET_Sounds which Radek merged into the repository.

The most important change is that working fastai2 code is included. It shows how to construct a fastai2 Learner given the Macaque calls and a PyTorch model. fit_one_cycle() converges much faster (in epochs) than the pure PyTorch training loop, arriving at 97.3% accuracy with 1000 conv1dā€™s.

(To reach 97.3% you will need to edit class ROCKET in ROCKETSound1.py. In init, change to the second of the two dilation calculations.)

The notebook also shows visualizations of the highest weighted conv1d biases and dilations, and ends with some questions to ponder about the ROCKET method.

Thanks for any corrections and improvements!

As an interesting aside, I found an article that measured the Macaque hearing range as 55 Hz-45 kHz. Because that range extends far above the Nyquist frequency of our samples (11 kHz), it may be wise not to downsample them. But I certainly have no idea whether Macaques actually use such high frequencies for communication, identification, or ploting conspiracies. Clever little monkeys.

2 Likes

Hey @Brainkite! Iā€™m @radekā€™s colleague and one of the co-founders of the Earth Species Project.

When we first started looking at this years ago we spent a lot of time with biologists from many fields and listening. One side effect of that was ending up in the inhospitable rainforests of the Central African Republic with the Elephant Listening Project for three weeks (including xmas and new years!). We were trying to understand their acoustic array and how they record in such harsh conditions.

You are absolutely correct. I really had no idea that there existed a place on land quite like that. Studying Forest Elephants is a bit like studying something on the bottom of the ocean, it turns out. We can observe them when they choose to enter a small clearing, but because they are protective of the familial units, there is no way to follow them into the woods, where they spend most of their time. This means that we have absolutely no idea how they spend most of their lives.

2 Likes

A cursory search provided this repo for translating vggish from tensorflow to pytorch.. It looked there were several other attempts as well.

Did you ever play at getting them working with Pytorch?

1 Like

We use GCP at Earth Species Project and I bumped against the same several times. My notes are here, as well as documentation of much of our setup process.

1 Like

Really nice notebook thanks. I was doing some work on attention and 1D convolutions and this was really useful. Thanks

1 Like

For those working with audio, I saw this new birdcall competition on kaggle. Iā€™m not sure of all the details, but it reminded me of this thread.