asteroid.complex_nn module¶
Complex building blocks that work with _PyTorch native_ complex tensors, i.e. dtypes complex64/complex128, or tensors for which .is_complex() returns True.
Note that Asteroid code has two other representations of complex numbers:
- Torchaudio representation […, 2] where […, 0] and […, 1] are real and imaginary components, respectively
- Asteroid style representation, identical to the Torchaudio representation, but with the last dimension concatenated: tensor([r1, r2, …, rn, i1, i2, …, in]). The concatenated (2 * n) dimension may be at an arbitrary position, i.e. the tensor is of shape […, 2 * n, …]. See asteroid.filterbanks.transforms for details.
-
class
asteroid.complex_nn.
BoundComplexMask
(bound_type)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Module version of bound_complex_mask
-
class
asteroid.complex_nn.
ComplexMultiplicationWrapper
(module_cls, *args, **kwargs)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Make a complex-valued module F from a real-valued module f by applying complex multiplication rules:
F(a + i b) = f1(a) - f1(b) + i (f2(b) + f2(a))where f1, f2 are instances of f that do not share weights.
Parameters: module_cls (callable) – A class or function that returns a Torch module/functional. Constructor of f in the formula above. Called 2x with *args, **kwargs, to construct the real and imaginary component modules.
-
class
asteroid.complex_nn.
OnReIm
(module_cls, *args, **kwargs)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Like on_reim, but for stateful modules.
Parameters: module_cls (callable) – A class or function that returns a Torch module/functional. Called 2x with *args, **kwargs, to construct the real and imaginary component modules.
-
asteroid.complex_nn.
as_torch_complex
(x, asteroid_dim=-2)[source]¶ Convert complex x to complex. Input may be one of:
- PyTorch native complex
- Torchaudio style complex
- Asteroid style complex
- Tuple or list of (real, imaginary) components
Parameters: asteroid_dim (int, optional) – Dimension to check for Asteroid-style complex. Raises: ValueError: If type of x is not understood.
-
asteroid.complex_nn.
bound_complex_mask
(mask: <sphinx.ext.autodoc.importer._MockObject object at 0x7f827d13e050>, bound_type='tanh')[source]¶ Bound a complex mask, as proposed in [1], section 3.2.
Valid bound types, for a complex mask $M = |M| ⋅ e^{i φ(M)}$:
- Unbounded (“UBD”): $M_{mathrm{UBD}} = M$
- Sigmoid (“BDSS”): $M_{mathrm{BDSS}} = σ(|M|) e^{i σ(φ(M))}$
- Tanh (“BDT”): $M_{mathrm{BDT}} = mathrm{tanh}(|M|) e^{i φ(M)}$
Parameters: bound_type (str or None) – The type of bound to use, either of “tanh”/”bdt” (default), “sigmoid”/”bdss” or None/”bdt”. References
[1] : “Phase-aware Speech Enhancement with Deep Complex U-Net”, Hyeong-Seok Choi et al. https://arxiv.org/abs/1903.03107
-
asteroid.complex_nn.
on_reim
(f)[source]¶ Make a complex-valued function callable from a real-valued one by applying it to the real and imaginary components independently.
Return: cf(x), complex version of f: A function that applies f to the real and imaginary components of x and returns the result as PyTorch complex tensor.