| 68 | |
| 69 | |
| 70 | class EncoderDownSampleBlock(nn.Module): |
| 71 | def __init__(self, in_channels, with_conv): |
| 72 | super().__init__() |
| 73 | self.with_conv = with_conv |
| 74 | self.in_channels = in_channels |
| 75 | if self.with_conv: |
| 76 | self.conv = torch.nn.Conv2d(in_channels, |
| 77 | in_channels, |
| 78 | kernel_size=3, |
| 79 | stride=2, |
| 80 | padding=0) |
| 81 | |
| 82 | def forward(self, x): |
| 83 | if self.with_conv: |
| 84 | pad = (0, 1, 0, 1) |
| 85 | x = torch.nn.functional.pad(x, pad, mode="constant", value=0) |
| 86 | x = self.conv(x) |
| 87 | else: |
| 88 | x = torch.nn.functional.avg_pool2d(x, kernel_size=2, stride=2) |
| 89 | return x |
| 90 | |
| 91 | |
| 92 | class ResnetBlock(nn.Module): |