asteroid-team / torch-audiomentations

Fast audio data augmentation in PyTorch. Inspired by audiomentations. Useful for deep learning.
MIT License
969 stars 88 forks source link

Support min_snr_in_db == max_snr_in_db in AddBackgroundNoise #120

Closed hbredin closed 2 years ago

hbredin commented 2 years ago
  1. torch.distributions.Uniform raises a ValueError when low == high:
    ValueError: Uniform is not defined when low>= high
  2. AddBackgroundNoise only raises when min_snr_in_db > max_snr_in_db, and not when min_snr_in_db == max_snr_in_db

There is therefore an inconsistency between the two behaviors.

I think supporting min == max is the way to go.

iver56 commented 2 years ago

Thanks for filing this. Yeah, low == high isn't properly supported yet in this transform. I guess it could be patched by using torch.full, like here: https://github.com/asteroid-team/torch-audiomentations/blob/cf33679368125b0ff6db6680a7cf0b289386849f/torch_audiomentations/augmentations/shift.py#L119

As a workaround until it is fixed, one can do something like this, which for all practical intents and purposes gives the same result:

AddBackgroundNoise(
    bg_path, min_snr_in_db=12.0, max_snr_in_db=12.0000001
)
iver56 commented 2 years ago

If you'd like to contribute, that would be a welcome PR 😄

hbredin commented 2 years ago

@FrenchKrab I think I noticed this max_snr = min_snr + epsilon hack in your code. Would you like to contribute this change?

FrenchKrab commented 2 years ago

I opened a PR that adds the suggested torch.full fix

iver56 commented 2 years ago

Thanks