Convolution + upsampling network module.
| 123 | |
| 124 | |
| 125 | class ConvInUpsampleNetwork(torch.nn.Module): |
| 126 | """Convolution + upsampling network module.""" |
| 127 | |
| 128 | def __init__(self, |
| 129 | upsample_scales, |
| 130 | nonlinear_activation=None, |
| 131 | nonlinear_activation_params={}, |
| 132 | interpolate_mode="nearest", |
| 133 | freq_axis_kernel_size=1, |
| 134 | aux_channels=80, |
| 135 | aux_context_window=0, |
| 136 | use_causal_conv=False |
| 137 | ): |
| 138 | """Initialize convolution + upsampling network module. |
| 139 | |
| 140 | Args: |
| 141 | upsample_scales (list): List of upsampling scales. |
| 142 | nonlinear_activation (str): Activation function name. |
| 143 | nonlinear_activation_params (dict): Arguments for specified activation function. |
| 144 | mode (str): Interpolation mode. |
| 145 | freq_axis_kernel_size (int): Kernel size in the direction of frequency axis. |
| 146 | aux_channels (int): Number of channels of pre-convolutional layer. |
| 147 | aux_context_window (int): Context window size of the pre-convolutional layer. |
| 148 | use_causal_conv (bool): Whether to use causal structure. |
| 149 | |
| 150 | """ |
| 151 | super(ConvInUpsampleNetwork, self).__init__() |
| 152 | self.aux_context_window = aux_context_window |
| 153 | self.use_causal_conv = use_causal_conv and aux_context_window > 0 |
| 154 | # To capture wide-context information in conditional features |
| 155 | kernel_size = aux_context_window + 1 if use_causal_conv else 2 * aux_context_window + 1 |
| 156 | # NOTE(kan-bayashi): Here do not use padding because the input is already padded |
| 157 | self.conv_in = Conv1d(aux_channels, aux_channels, kernel_size=kernel_size, bias=False) |
| 158 | self.upsample = UpsampleNetwork( |
| 159 | upsample_scales=upsample_scales, |
| 160 | nonlinear_activation=nonlinear_activation, |
| 161 | nonlinear_activation_params=nonlinear_activation_params, |
| 162 | interpolate_mode=interpolate_mode, |
| 163 | freq_axis_kernel_size=freq_axis_kernel_size, |
| 164 | use_causal_conv=use_causal_conv, |
| 165 | ) |
| 166 | |
| 167 | def forward(self, c): |
| 168 | """Calculate forward propagation. |
| 169 | |
| 170 | Args: |
| 171 | c : Input tensor (B, C, T'). |
| 172 | |
| 173 | Returns: |
| 174 | Tensor: Upsampled tensor (B, C, T), |
| 175 | where T = (T' - aux_context_window * 2) * prod(upsample_scales). |
| 176 | |
| 177 | Note: |
| 178 | The length of inputs considers the context window size. |
| 179 | |
| 180 | """ |
| 181 | c_ = self.conv_in(c) |
| 182 | c = c_[:, :, :-self.aux_context_window] if self.use_causal_conv else c_ |
nothing calls this directly
no outgoing calls
no test coverage detected