Download modules/parallel_wavegan/layers/causal_conv.py from Ccbb121/ProDiff: direct link, hf CLI and curl.
- Browser
- Download file 1.77 kB
-
https://huggingface.co/datasets/Ccbb121/ProDiff/resolve/main/modules/parallel_wavegan/layers/causal_conv.py
- Command line
-
hf download hf://datasets/Ccbb121/ProDiff/modules/parallel_wavegan/layers/causal_conv.py
-
curl -L -o causal_conv.py https://huggingface.co/datasets/Ccbb121/ProDiff/resolve/main/modules/parallel_wavegan/layers/causal_conv.py
1.77 kB
| # -*- coding: utf-8 -*- | |
| # Copyright 2020 Tomoki Hayashi | |
| # MIT License (https://opensource.org/licenses/MIT) | |
| """Causal convolusion layer modules.""" | |
| import torch | |
| class CausalConv1d(torch.nn.Module): | |
| """CausalConv1d module with customized initialization.""" | |
| def __init__(self, in_channels, out_channels, kernel_size, | |
| dilation=1, bias=True, pad="ConstantPad1d", pad_params={"value": 0.0}): | |
| """Initialize CausalConv1d module.""" | |
| super(CausalConv1d, self).__init__() | |
| self.pad = getattr(torch.nn, pad)((kernel_size - 1) * dilation, **pad_params) | |
| self.conv = torch.nn.Conv1d(in_channels, out_channels, kernel_size, | |
| dilation=dilation, bias=bias) | |
| def forward(self, x): | |
| """Calculate forward propagation. | |
| Args: | |
| x (Tensor): Input tensor (B, in_channels, T). | |
| Returns: | |
| Tensor: Output tensor (B, out_channels, T). | |
| """ | |
| return self.conv(self.pad(x))[:, :, :x.size(2)] | |
| class CausalConvTranspose1d(torch.nn.Module): | |
| """CausalConvTranspose1d module with customized initialization.""" | |
| def __init__(self, in_channels, out_channels, kernel_size, stride, bias=True): | |
| """Initialize CausalConvTranspose1d module.""" | |
| super(CausalConvTranspose1d, self).__init__() | |
| self.deconv = torch.nn.ConvTranspose1d( | |
| in_channels, out_channels, kernel_size, stride, bias=bias) | |
| self.stride = stride | |
| def forward(self, x): | |
| """Calculate forward propagation. | |
| Args: | |
| x (Tensor): Input tensor (B, in_channels, T_in). | |
| Returns: | |
| Tensor: Output tensor (B, out_channels, T_out). | |
| """ | |
| return self.deconv(x)[:, :, :-self.stride] | |