| 137 | |
| 138 | |
| 139 | class ConvLayer(nn.Sequential): |
| 140 | def __init__( |
| 141 | self, |
| 142 | in_channel, |
| 143 | out_channel, |
| 144 | kernel_size, |
| 145 | downsample=False, |
| 146 | blur_kernel=[1, 3, 3, 1], |
| 147 | bias=True, |
| 148 | activate=True, |
| 149 | ): |
| 150 | layers = [] |
| 151 | |
| 152 | if downsample: |
| 153 | factor = 2 |
| 154 | p = (len(blur_kernel) - factor) + (kernel_size - 1) |
| 155 | pad0 = (p + 1) // 2 |
| 156 | pad1 = p // 2 |
| 157 | |
| 158 | layers.append(Blur(blur_kernel, pad=(pad0, pad1))) |
| 159 | |
| 160 | stride = 2 |
| 161 | self.padding = 0 |
| 162 | |
| 163 | else: |
| 164 | stride = 1 |
| 165 | self.padding = kernel_size // 2 |
| 166 | |
| 167 | layers.append(EqualConv2d(in_channel, out_channel, kernel_size, padding=self.padding, stride=stride, |
| 168 | bias=bias and not activate)) |
| 169 | |
| 170 | if activate: |
| 171 | if bias: |
| 172 | layers.append(FusedLeakyReLU(out_channel)) |
| 173 | else: |
| 174 | layers.append(ScaledLeakyReLU(0.2)) |
| 175 | |
| 176 | super().__init__(*layers) |
| 177 | |
| 178 | |
| 179 | class ResBlock(nn.Module): |