paddlespeech.t2s.modules.conv module

class paddlespeech.t2s.modules.conv.Conv1dBatchNorm(in_channels, out_channels, kernel_size, stride=1, padding=0, weight_attr=None, bias_attr=None, data_format='NCL', momentum=0.9, epsilon=1e-05)[source]

Bases: Layer

A Conv1D Layer followed by a BatchNorm1D.

Args:
in_channels (int):

The feature size of the input.

out_channels (int):

The feature size of the output.

kernel_size (int):

The size of the convolution kernel.

stride (int, optional):

The stride of the convolution, by default 1.

padding (int, str or Tuple[int], optional):

The padding of the convolution. If int, a symmetrical padding is applied before convolution; If str, it should be "same" or "valid"; If Tuple[int], its length should be 2, meaning (pad_before, pad_after), by default 0.

weight_attr (ParamAttr, Initializer, str or bool, optional):

The parameter attribute of the convolution kernel, by default None.

bias_attr (ParamAttr, Initializer, str or bool, optional):

The parameter attribute of the bias of the convolution, by defaultNone.

data_format (str ["NCL" or "NLC"], optional):

The data layout of the input, by default "NCL"

momentum (float, optional):

The momentum of the BatchNorm1D layer, by default 0.9

epsilon (float, optional):

The epsilon of the BatchNorm1D layer, by default 1e-05

Methods

__call__(*inputs, **kwargs)

Call self as a function.

add_parameter(name, parameter)

Adds a Parameter instance.

add_sublayer(name, sublayer)

Adds a sub Layer instance.

apply(fn)

Applies fn recursively to every sublayer (as returned by .sublayers()) as well as self.

buffers([include_sublayers])

Returns a list of all buffers from current layer and its sub-layers.

children()

Returns an iterator over immediate children layers.

clear_gradients()

Clear the gradients of all parameters for this layer.

create_parameter(shape[, attr, dtype, ...])

Create parameters for this layer.

create_tensor([name, persistable, dtype])

Create Tensor for this layer.

create_variable([name, persistable, dtype])

Create Tensor for this layer.

eval()

Sets this Layer and all its sublayers to evaluation mode.

extra_repr()

Extra representation of this layer, you can have custom implementation of your own layer.

forward(x)

Forward pass of the Conv1dBatchNorm layer.

full_name()

Full name for this layer, composed by name_scope + "/" + MyLayer.__class__.__name__

load_dict(state_dict[, use_structured_name])

Set parameters and persistable buffers from state_dict.

named_buffers([prefix, include_sublayers])

Returns an iterator over all buffers in the Layer, yielding tuple of name and Tensor.

named_children()

Returns an iterator over immediate children layers, yielding both the name of the layer as well as the layer itself.

named_parameters([prefix, include_sublayers])

Returns an iterator over all parameters in the Layer, yielding tuple of name and parameter.

named_sublayers([prefix, include_self, ...])

Returns an iterator over all sublayers in the Layer, yielding tuple of name and sublayer.

parameters([include_sublayers])

Returns a list of all Parameters from current layer and its sub-layers.

register_buffer(name, tensor[, persistable])

Registers a tensor as buffer into the layer.

register_forward_post_hook(hook)

Register a forward post-hook for Layer.

register_forward_pre_hook(hook)

Register a forward pre-hook for Layer.

set_dict(state_dict[, use_structured_name])

Set parameters and persistable buffers from state_dict.

set_state_dict(state_dict[, use_structured_name])

Set parameters and persistable buffers from state_dict.

state_dict([destination, include_sublayers, ...])

Get all parameters and persistable buffers of current layer and its sub-layers.

sublayers([include_self])

Returns a list of sub layers.

to([device, dtype, blocking])

Cast the parameters and buffers of Layer by the give device, dtype and blocking.

to_static_state_dict([destination, ...])

Get all parameters and buffers of current layer and its sub-layers.

train()

Sets this Layer and all its sublayers to training mode.

backward

register_state_dict_hook

forward(x)[source]

Forward pass of the Conv1dBatchNorm layer.

Args:
x (Tensor):

The input tensor. Its data layout depends on data_format. shape=(B, C_in, T_in) or (B, T_in, C_in)

Returns:
Tensor:

The output tensor. shape=(B, C_out, T_out) or (B, T_out, C_out)

class paddlespeech.t2s.modules.conv.Conv1dCell(in_channels, out_channels, kernel_size, dilation=1, weight_attr=None, bias_attr=None)[source]

Bases: Conv1D

A subclass of Conv1D layer, which can be used in an autoregressive decoder like an RNN cell.

When used in autoregressive decoding, it performs causal temporal convolution incrementally. At each time step, it takes a step input and returns a step output.

Notes

It is done by caching an internal buffer of length receptive_file - 1. when adding a step input, the buffer is shited by one step, the latest input is added to be buffer and the oldest step is discarded. And it returns a step output. For single step case, convolution is equivalent to a linear transformation. That it can be used as a cell depends on several restrictions: 1. stride must be 1; 2. padding must be a causal padding (recpetive_field - 1, 0). Thus, these arguments are removed from the __init__ method of this class.

Args:
in_channels (int):

The feature size of the input.

out_channels (int):

The feature size of the output.

kernel_size (int or Tuple[int]):

The size of the kernel.

dilation (int or Tuple[int]):

The dilation of the convolution, by default 1

weight_attr (ParamAttr, Initializer, str or bool, optional):

The parameter attribute of the convolution kernel, by default None.

bias_attr (ParamAttr, Initializer, str or bool, optional):

The parameter attribute of the bias. If False, this layer does not have a bias, by default None.

Examples:
>>> cell = Conv1dCell(3, 4, kernel_size=5)
>>> inputs = [paddle.randn([4, 3]) for _ in range(16)]
>>> outputs = []
>>> cell.eval()
>>> cell.start_sequence()
>>> for xt in inputs:
>>>     outputs.append(cell.add_input(xt))
>>> len(outputs))
16
>>> outputs[0].shape
[4, 4]
Attributes:
receptive_field

The receptive field of the Conv1dCell.

Methods

__call__(*inputs, **kwargs)

Call self as a function.

add_input(x_t)

Add step input and compute step output.

add_parameter(name, parameter)

Adds a Parameter instance.

add_sublayer(name, sublayer)

Adds a sub Layer instance.

apply(fn)

Applies fn recursively to every sublayer (as returned by .sublayers()) as well as self.

buffers([include_sublayers])

Returns a list of all buffers from current layer and its sub-layers.

children()

Returns an iterator over immediate children layers.

clear_gradients()

Clear the gradients of all parameters for this layer.

create_parameter(shape[, attr, dtype, ...])

Create parameters for this layer.

create_tensor([name, persistable, dtype])

Create Tensor for this layer.

create_variable([name, persistable, dtype])

Create Tensor for this layer.

eval()

Sets this Layer and all its sublayers to evaluation mode.

extra_repr()

Extra representation of this layer, you can have custom implementation of your own layer.

forward(x)

Defines the computation performed at every call.

full_name()

Full name for this layer, composed by name_scope + "/" + MyLayer.__class__.__name__

initialize_buffer(x_t)

Initialize the buffer for the step input.

load_dict(state_dict[, use_structured_name])

Set parameters and persistable buffers from state_dict.

named_buffers([prefix, include_sublayers])

Returns an iterator over all buffers in the Layer, yielding tuple of name and Tensor.

named_children()

Returns an iterator over immediate children layers, yielding both the name of the layer as well as the layer itself.

named_parameters([prefix, include_sublayers])

Returns an iterator over all parameters in the Layer, yielding tuple of name and parameter.

named_sublayers([prefix, include_self, ...])

Returns an iterator over all sublayers in the Layer, yielding tuple of name and sublayer.

parameters([include_sublayers])

Returns a list of all Parameters from current layer and its sub-layers.

register_buffer(name, tensor[, persistable])

Registers a tensor as buffer into the layer.

register_forward_post_hook(hook)

Register a forward post-hook for Layer.

register_forward_pre_hook(hook)

Register a forward pre-hook for Layer.

set_dict(state_dict[, use_structured_name])

Set parameters and persistable buffers from state_dict.

set_state_dict(state_dict[, use_structured_name])

Set parameters and persistable buffers from state_dict.

start_sequence()

Prepare the layer for a series of incremental forward.

state_dict([destination, include_sublayers, ...])

Get all parameters and persistable buffers of current layer and its sub-layers.

sublayers([include_self])

Returns a list of sub layers.

to([device, dtype, blocking])

Cast the parameters and buffers of Layer by the give device, dtype and blocking.

to_static_state_dict([destination, ...])

Get all parameters and buffers of current layer and its sub-layers.

train()

Sets this Layer and all its sublayers to training mode.

update_buffer(x_t)

Shift the buffer by one step.

backward

register_state_dict_hook

add_input(x_t)[source]

Add step input and compute step output.

Args:
x_t (Tensor):

The step input. shape=(batch_size, in_channels)

Returns:
y_t (Tensor):

The step output. shape=(batch_size, out_channels)

initialize_buffer(x_t)[source]

Initialize the buffer for the step input.

Args:
x_t (Tensor):

The step input. shape=(batch_size, in_channels)

property receptive_field

The receptive field of the Conv1dCell.

start_sequence()[source]

Prepare the layer for a series of incremental forward.

Warnings:

This method should be called before a sequence of calls to add_input.

Raises:
Exception

If this method is called when the layer is in training mode.

update_buffer(x_t)[source]

Shift the buffer by one step.

Args:
x_t (Tensor): T

he step input. shape=(batch_size, in_channels)