Stretch2d module.
| 14 | |
| 15 | |
| 16 | class Stretch2d(torch.nn.Module): |
| 17 | """Stretch2d module.""" |
| 18 | |
| 19 | def __init__(self, x_scale, y_scale, mode="nearest"): |
| 20 | """Initialize Stretch2d module. |
| 21 | |
| 22 | Args: |
| 23 | x_scale (int): X scaling factor (Time axis in spectrogram). |
| 24 | y_scale (int): Y scaling factor (Frequency axis in spectrogram). |
| 25 | mode (str): Interpolation mode. |
| 26 | |
| 27 | """ |
| 28 | super(Stretch2d, self).__init__() |
| 29 | self.x_scale = x_scale |
| 30 | self.y_scale = y_scale |
| 31 | self.mode = mode |
| 32 | |
| 33 | def forward(self, x): |
| 34 | """Calculate forward propagation. |
| 35 | |
| 36 | Args: |
| 37 | x (Tensor): Input tensor (B, C, F, T). |
| 38 | |
| 39 | Returns: |
| 40 | Tensor: Interpolated tensor (B, C, F * y_scale, T * x_scale), |
| 41 | |
| 42 | """ |
| 43 | return F.interpolate( |
| 44 | x, scale_factor=(self.y_scale, self.x_scale), mode=self.mode) |
| 45 | |
| 46 | |
| 47 | class Conv2d(torch.nn.Conv2d): |