Spatial downsampling by factor 2. [FROM_OFFICIAL_CODE]
| 190 | |
| 191 | |
| 192 | class Downsample(nn.Module): |
| 193 | """Spatial downsampling by factor 2. [FROM_OFFICIAL_CODE]""" |
| 194 | |
| 195 | def __init__(self, channels: int): |
| 196 | super().__init__() |
| 197 | self.conv = nn.Conv2d(channels, channels, kernel_size=3, stride=2, padding=1) |
| 198 | |
| 199 | def forward(self, x: torch.Tensor) -> torch.Tensor: |
| 200 | return self.conv(x) # (batch, C, H, W) -> (batch, C, H/2, W/2) |
| 201 | |
| 202 | |
| 203 | class Upsample(nn.Module): |