Shortcuts

asteroid.filterbanks.transforms module

asteroid.filterbanks.transforms.angle(tensor, dim=-2)[source]

Return the angle of the complex-like torch tensor.

Parameters:
  • tensor (torch.Tensor) – the complex tensor from which to extract the phase.
  • dim (int, optional) – the frequency (or equivalent) dimension along which real and imaginary values are concatenated.
Returns:

torch.Tensor – The counterclockwise angle from the positive real axis on the complex plane in radians.

asteroid.filterbanks.transforms.apply_complex_mask(tf_rep, mask, dim=-2)[source]

Applies a complex-valued mask to a complex-valued representation.

Operands are assumed to have the real parts of each entry followed by the imaginary parts of each entry along dimension dim, e.g. for, dim = 1, the matrix

is interpreted as

where j is such that j * j = -1.

Parameters:
  • tf_rep (torch.Tensor) – The time frequency representation to apply the mask to.
  • (class (mask) – torch.Tensor): The complex-valued mask to be applied.
  • dim (int) – The frequency (or equivalent) dimension of both tf_rep an mask along which real and imaginary values are concatenated.
Returns:

torch.Tensortf_rep multiplied by the mask in the complex sense.

asteroid.filterbanks.transforms.apply_mag_mask(tf_rep, mask, dim=-2)[source]

Applies a real-valued mask to a complex-valued representation.

If tf_rep has 2N elements along dim, mask has N elements, mask is duplicated along dim to apply the same mask to both the Re and Im.

tf_rep is assumed to have the real parts of each entry followed by the imaginary parts of each entry along dimension dim, e.g. for, dim = 1, the matrix

is interpreted as

where j is such that j * j = -1.

Parameters:
  • tf_rep (torch.Tensor) – The time frequency representation to apply the mask to. Re and Im are concatenated along dim.
  • mask (torch.Tensor) – The real-valued mask to be applied.
  • dim (int) – The frequency (or equivalent) dimension of both tf_rep and mask along which real and imaginary values are concatenated.
Returns:

torch.Tensortf_rep multiplied by the mask.

asteroid.filterbanks.transforms.apply_real_mask(tf_rep, mask, dim=-2)[source]

Applies a real-valued mask to a real-valued representation.

It corresponds to ReIm mask in [1].

Parameters:
  • tf_rep (torch.Tensor) – The time frequency representation to apply the mask to.
  • mask (torch.Tensor) – The real-valued mask to be applied.
  • dim (int) – Kept to have the same interface with the other ones.
Returns:

torch.Tensortf_rep multiplied by the mask.

asteroid.filterbanks.transforms.check_complex(tensor, dim=-2)[source]

Assert tensor in complex-like in a given dimension.

Parameters:
  • tensor (torch.Tensor) – tensor to be checked.
  • dim (int) – the frequency (or equivalent) dimension along which real and imaginary values are concatenated.
Raises:

AssertionError if dimension is not even in the specified dimension

asteroid.filterbanks.transforms.ebased_vad(mag_spec, th_db=40)[source]

Compute energy-based VAD from a magnitude spectrogram (or equivalent).

Parameters:
  • mag_spec (torch.Tensor) – the spectrogram to perform VAD on. Expected shape (batch, *, freq, time). The VAD mask will be computed independently for all the leading dimensions until the last two. Independent of the ordering of the last two dimensions.
  • th_db (int) – The threshold in dB from which a TF-bin is considered silent.
Returns:

torch.BoolTensor, the VAD mask.

Examples

>>> import torch
>>> mag_spec = torch.abs(torch.randn(10, 2, 65, 16))
>>> batch_src_mask = ebased_vad(mag_spec)
asteroid.filterbanks.transforms.from_mag_and_phase(mag, phase, dim=-2)[source]

Return a complex-like torch tensor from magnitude and phase components.

Parameters:
  • mag (torch.tensor) – magnitude of the tensor.
  • phase (torch.tensor) – angle of the tensor
  • dim (int, optional) – the frequency (or equivalent) dimension along which real and imaginary values are concatenated.
Returns:

torch.Tensor – The corresponding complex-like torch tensor.

asteroid.filterbanks.transforms.from_numpy(array, dim=-2)[source]

Convert complex numpy array to complex-like torch tensor.

Parameters:
  • array (np.array) – array to be converted.
  • dim (int, optional) – the frequency (or equivalent) dimension along which real and imaginary values are concatenated.
Returns:

torch.Tensor – Corresponding torch.Tensor (complex axis in dim `dim`=

asteroid.filterbanks.transforms.from_torchaudio(tensor, dim=-2)[source]

Converts torchaudio style complex tensor to complex-like torch tensor.

Parameters:
  • tensor (torch.tensor) – torchaudio-style complex-like torch tensor.
  • dim (int, optional) – the frequency (or equivalent) dimension along which real and imaginary values are concatenated.
Returns:

torch.Tensor – asteroid-style complex-like torch tensor.

asteroid.filterbanks.transforms.mul_c(inp, other, dim=-2)[source]

Entrywise product for complex valued tensors.

Operands are assumed to have the real parts of each entry followed by the imaginary parts of each entry along dimension dim, e.g. for, dim = 1, the matrix

is interpreted as

where j is such that j * j = -1.

Parameters:
  • inp (torch.Tensor) – The first operand with real and imaginary parts concatenated on the dim axis.
  • other (torch.Tensor) – The second operand.
  • dim (int, optional) – frequency (or equivalent) dimension along which real and imaginary values are concatenated.
Returns:

torch.Tensor – The complex multiplication between inp and other

For now, it assumes that other has the same shape as inp along dim.

asteroid.filterbanks.transforms.take_cat(x, dim=-2)[source]
asteroid.filterbanks.transforms.take_mag(x, dim=-2)[source]

Takes the magnitude of a complex tensor.

The operands is assumed to have the real parts of each entry followed by the imaginary parts of each entry along dimension dim, e.g. for, dim = 1, the matrix

is interpreted as

where j is such that j * j = -1.

Parameters:
  • x (torch.Tensor) – Complex valued tensor.
  • dim (int) – frequency (or equivalent) dimension along which real and imaginary values are concatenated.
Returns:

torch.Tensor – The magnitude of x.

asteroid.filterbanks.transforms.take_reim(x, dim=-2)[source]
asteroid.filterbanks.transforms.to_numpy(tensor, dim=-2)[source]

Convert complex-like torch tensor to numpy complex array

Parameters:
  • tensor (torch.Tensor) – Complex tensor to convert to numpy.
  • dim (int, optional) – the frequency (or equivalent) dimension along which real and imaginary values are concatenated.
Returns:

numpy.array – Corresponding complex array.

asteroid.filterbanks.transforms.to_torchaudio(tensor, dim=-2)[source]

Converts complex-like torch tensor to torchaudio style complex tensor.

Parameters:
  • tensor (torch.tensor) – asteroid-style complex-like torch tensor.
  • dim (int, optional) – the frequency (or equivalent) dimension along which real and imaginary values are concatenated.
Returns:

torch.Tensor – torchaudio-style complex-like torch tensor.

Read the Docs v: v0.3.3
Versions
latest
stable
v0.3.3
v0.3.2
v0.3.1
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.