iver56 / audiomentations

A Python library for audio data augmentation. Inspired by albumentations. Useful for machine learning.

Home Page:https://iver56.github.io/audiomentations/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can this repo be used in multi thread?

zh794390558 opened this issue · comments

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.

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!

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

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?

I using centos 7.

@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!

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

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

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

@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.

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

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

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