Spatial upsampling by factor 2. [FROM_OFFICIAL_CODE]
| 201 | |
| 202 | |
| 203 | class Upsample(nn.Module): |
| 204 | """Spatial upsampling by factor 2. [FROM_OFFICIAL_CODE]""" |
| 205 | |
| 206 | def __init__(self, channels: int): |
| 207 | super().__init__() |
| 208 | self.conv = nn.Conv2d(channels, channels, kernel_size=3, padding=1) |
| 209 | |
| 210 | def forward(self, x: torch.Tensor) -> torch.Tensor: |
| 211 | x = F.interpolate(x, scale_factor=2, mode="nearest") |
| 212 | return self.conv(x) # (batch, C, H, W) -> (batch, C, 2H, 2W) |
| 213 | |
| 214 | |
| 215 | # --------------------------------------------------------------------------- |