Skip to content
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

Can this repo be used in multi thread? #46

Closed
zh794390558 opened this issue Jul 20, 2020 · 11 comments
Closed

Can this repo be used in multi thread? #46

zh794390558 opened this issue Jul 20, 2020 · 11 comments

Comments

@zh794390558
Copy link

I encountered this error, which caused by TimeMask

time mask: t0 138974  t: 21416  m.shpae: (21416,)  newshpae: (93184,)  rawshpae: (93184,)  slice shape: (0,)
err:  operands could not be broadcast together with shapes (0,) (21416,) (0,) 
augmenter = Compose([
        TimeStretch(min_rate=0.8, max_rate=1.25, p=1.0),
        AddGaussianNoise(min_amplitude=0.001, max_amplitude=0.015, p=0.2),
        PitchShift(min_semitones=-4, max_semitones=4, p=0.2),
        Shift(min_fraction=-0.5, max_fraction=0.5, p=0.2),
        FrequencyMask(min_frequency_band=0.0, max_frequency_band=0.5, p=0.2),
        TimeMask(min_band_part=0.0, max_band_part=0.5, fade=False, p=0.2)
], p=1.0, shuffle=False)

def aug_sample(samples, sample_rate):
  assert samples.dtype == np.int16 
  samples =  samples * max(0.01, np.max(np.abs(samples))) / 32768.0
  samples = samples.astype(np.float32)
  samples = augmenter(samples=samples, sample_rate=sample_rate)
  samples *= 32767 / max(0.01, np.max(np.abs(samples)))
  samples = samples.astype(np.int16)
  return samples

using aug_sample to load wav by threading.Thread like mapreduce.

@iver56
Copy link
Owner

iver56 commented Jul 22, 2020

Hi Hui Zhang, and thanks for your interest in audiomentations! Do you get the same error message if you don't use threading? Ideally, audiomentations should support multi-threads, but I don't have any tests for that currently. If you would like to contribute such a test, that would be appreciated!

@zh794390558
Copy link
Author

one augmenter object can not be called by multi-thread.

@iver56
Copy link
Owner

iver56 commented Aug 25, 2020

Ok, in that case I should investigate how that can be fixed. Maybe it needs to be picklable?

Which operating system are you using? Windows?

@iver56 iver56 reopened this Aug 25, 2020
@zh794390558
Copy link
Author

I using centos 7.

@francislata
Copy link

@iver56 - Any updates on this? Currently, I'm using this module to augment a clean audio in the collate_fn but its the bottleneck on producing augmented audio with IR and background noise. The reason why I'm doing this on the fly is to give equal probability to all possible clean audio + IR + background noise combinations.

Thank you!

@iver56
Copy link
Owner

iver56 commented Sep 21, 2020

Hi francislata. No progress on multiprocessing support lately. I want to support it though. My time is limited. If you want to contribute, that would be welcome.

I spent some time looking into applying IR with Pytorch today though. More info on that might appear here later: https://github.com/asteroid-team/torch-audiomentations

@iver56
Copy link
Owner

iver56 commented Sep 22, 2020

@francislata Execution time of IR convolution can be sped up with GPU. See the plot here:

https://github.com/asteroid-team/torch-audiomentations#readme

@francislata
Copy link

@iver56 This is very interesting. I started taking a look at it but will keep going at it. From what I can tell initially, it looks like using the torch module to perform such augmentations, we can take advantage of the GPU support.

@iver56
Copy link
Owner

iver56 commented Dec 10, 2020

@zh794390558 Can you post a more complete code snippet to reproduce this problem? It should include the part with threading.Thread

@atamazian
Copy link
Contributor

This issue is dormant for quite some time. I suggest to close it - if necessary, it can be reopened.

@iver56
Copy link
Owner

iver56 commented May 23, 2022

Yeah, I actually think multithreading works fine now. I've been using it for some time without problems. It's just that I have no unit tests for it 😕
I can close this and then reopen another issue for adding multithreading/multiprocessing tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants