question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

interfaces.py separate_file() not working properly?

See original GitHub issue

Specs: Windows Version 10.0.19042 Build 19042, Python 3.8.3

I’m following the Source Separation tutorial that can be accessed from this page.

Since the audio I have is already mixed, I tried to use model.separate_file(), based off the HuggingFace speechbrain/sepformer-wsj02mix code. There are two issues with that:

  1. CPU, RAM and disk usage on my PC shoot up into the high nineties, causing the computer to freeze.
  2. After the computer unfreezes (presumably, after the calculations are finished), an error is thrown:
Traceback (most recent call last):
  ...
    est_sources = model.separate_file(path='data/test/audio/speech.wav')
  File "C:\...\venv\lib\site-packages\speechbrain\pretrained\interfaces.py", line 710, in separate_file
    est_sources = self.separate_batch(batch)
  File "C:\...\venv\lib\site-packages\speechbrain\pretrained\interfaces.py", line 669, in separate_batch
    est_mask = self.modules.masknet(mix_w)
  File "C:\...\venv\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "C:\...\venv\lib\site-packages\speechbrain\lobes\models\dual_path.py", line 1124, in forward
    x = self.dual_mdl[i](x)
  File "C:\...\venv\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "C:\...\venv\lib\site-packages\speechbrain\lobes\models\dual_path.py", line 975, in forward
    inter = self.inter_mdl(inter)
  File "C:\...\venv\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "C:\...\venv\lib\site-packages\speechbrain\lobes\models\dual_path.py", line 597, in forward
    return self.mdl(x + pos_enc)[0]
RuntimeError: The size of tensor a (2830) must match the size of tensor b (2500) at non-singleton dimension 1

My guess is that the data that separate_file() passes to separate_batch() is incorrect:

source, fl = split_path(path)
path = fetch(fl, source=source, savedir=savedir)
batch, _ = torchaudio.load(path)
est_sources = self.separate_batch(batch)

Does resampling the data have something to do with it?

If, instead of using separate_file(), I write:

mix, fs = torchaudio.load('data/test/audio/speech.wav')
resampler = torchaudio.transforms.Resample(fs, 8000)
mix = resampler(mix)
est_sources = model.separate_batch(mix)

as suggested in the aforementioned tutorial, the computer doesn’t freeze and est_sources is a torch.Tensor with torch.Size([1, 471272, 2]), which looks like expected behavior to me.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
ycemsubakancommented, Mar 21, 2021

Yes, this is a good suggestion actually. We will add this to the code. Thank you @UrosOgrizovic !

0reactions
ycemsubakancommented, Apr 2, 2021

The suggested fix has been implemented in #608 .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with interfaces in separate files not working? · Issue #30
I've implemented an interface in one file let's call it A.py: from interface import Interface class A(Interface): def method1(self): pass ...
Read more >
How to declare and import typescript interfaces in a separate file
You need to export the interface from the file in which is defined and import it wherever you want to use it. in...
Read more >
Calling Functions from Other Files - Problem Solving with Python
User-defined functions can be called from other files. A function can be called and run in a different file than the file where...
Read more >
Implementing an Interface in Python - Real Python
In this tutorial, you'll see how you can use a Python interface to help determine what class you should use to tackle the...
Read more >
os — Miscellaneous operating system interfaces — Python ...
All functions accepting path or file names accept both bytes and string objects, and result in an object of the same type, if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found