art.preprocessing.audio
¶
This module contains audio preprocessing tools.
L-Filter¶
- class art.preprocessing.audio.LFilter(numerator_coef: ndarray = array([1.0]), denominator_coef: ndarray = array([1.0]), axis: int = -1, initial_cond: Optional[ndarray] = None, clip_values: Optional[CLIP_VALUES_TYPE] = None, apply_fit: bool = False, apply_predict: bool = True, verbose: bool = False)¶
This module implements the filter function for audio signals. It provides with an infinite impulse response (IIR) or finite impulse response (FIR) filter. This implementation is a wrapper around the scipy.signal.lfilter function in the scipy package.
- __call__(x: ndarray, y: Optional[ndarray] = None) Tuple[ndarray, Optional[ndarray]] ¶
Apply filter to sample x.
- Return type:
Tuple
- Parameters:
x (
ndarray
) – Samples of shape (nb_samples, seq_length). Note that, it is allowable that sequences in the batch could have different lengths. A possible example of x could be: x = np.array([np.array([0.1, 0.2, 0.1, 0.4]), np.array([0.3, 0.1])]).y – Labels of the sample x. This function does not affect them in any way.
- Returns:
Similar samples.
- __init__(numerator_coef: ndarray = array([1.0]), denominator_coef: ndarray = array([1.0]), axis: int = -1, initial_cond: Optional[ndarray] = None, clip_values: Optional[CLIP_VALUES_TYPE] = None, apply_fit: bool = False, apply_predict: bool = True, verbose: bool = False)¶
Create an instance of LFilter.
- Parameters:
numerator_coef (
ndarray
) – The numerator coefficient vector in a 1-D sequence.denominator_coef (
ndarray
) – The denominator coefficient vector in a 1-D sequence. By simply setting the array of denominator coefficients to np.array([1.0]), this preprocessor can be used to apply a FIR filter.axis (
int
) – The axis of the input data array along which to apply the linear filter. The filter is applied to each subarray along this axis.initial_cond – Initial conditions for the filter delays.
clip_values – Tuple of the form (min, max) representing the minimum and maximum values allowed for features.
apply_fit (
bool
) – True if applied during fitting/training.apply_predict (
bool
) – True if applied during predicting.verbose (
bool
) – Show progress bars.
- estimate_gradient(x: ndarray, grad: ndarray) ndarray ¶
Provide an estimate of the gradients of the defence for the backward pass.
- Return type:
ndarray
- Parameters:
x (
ndarray
) – Input data for which the gradient is estimated. First dimension is the batch size.grad (
ndarray
) – Gradient value so far.
- Returns:
The gradient (estimate) of the defence.
LFilter - PyTorch¶
- class art.preprocessing.audio.LFilterPyTorch(numerator_coef: ndarray = array([1.0]), denominator_coef: ndarray = array([1.0]), clip_values: Optional[CLIP_VALUES_TYPE] = None, apply_fit: bool = False, apply_predict: bool = True, verbose: bool = False, device_type: str = 'gpu')¶
This module implements the filter function for audio signals in PyTorch. It provides with an infinite impulse response (IIR) or finite impulse response (FIR) filter. This implementation is a wrapper around the torchaudio.functional.lfilter function in the torchaudio package.
- __call__(x: ndarray, y: Optional[ndarray] = None) Tuple[ndarray, Optional[ndarray]] ¶
Apply filter to sample x.
- Return type:
Tuple
- Parameters:
x (
ndarray
) – Samples of shape (nb_samples, seq_length). Note that, it is allowable that sequences in the batch could have different lengths. A possible example of x could be: x = np.array([np.array([0.1, 0.2, 0.1, 0.4]), np.array([0.3, 0.1])]).y – Labels of the sample x. This function does not affect them in any way.
- Returns:
Similar samples.
- __init__(numerator_coef: ndarray = array([1.0]), denominator_coef: ndarray = array([1.0]), clip_values: Optional[CLIP_VALUES_TYPE] = None, apply_fit: bool = False, apply_predict: bool = True, verbose: bool = False, device_type: str = 'gpu') None ¶
Create an instance of LFilterPyTorch.
- Parameters:
numerator_coef (
ndarray
) – The numerator coefficient vector in a 1-D sequence.denominator_coef (
ndarray
) – The denominator coefficient vector in a 1-D sequence. By simply setting the array of denominator coefficients to np.array([1.0]), this preprocessor can be used to apply a FIR filter.clip_values – Tuple of the form (min, max) representing the minimum and maximum values allowed for features.
apply_fit (
bool
) – True if applied during fitting/training.apply_predict (
bool
) – True if applied during predicting.verbose (
bool
) – Show progress bars.device_type (
str
) – Type of device on which the classifier is run, either gpu or cpu.
- forward(x: torch.Tensor, y: Optional[torch.Tensor] = None) Tuple[torch.Tensor, Optional[torch.Tensor]] ¶
Apply filter to a single sample x.
- Return type:
Tuple
- Parameters:
x – A single audio sample.
y – Label of the sample x. This function does not affect them in any way.
- Returns:
Similar sample.