| 318 | |
| 319 | |
| 320 | class NoiseInjection(nn.Module): |
| 321 | def __init__(self): |
| 322 | super().__init__() |
| 323 | |
| 324 | self.weight = nn.Parameter(torch.zeros(1)) |
| 325 | |
| 326 | def forward(self, image, noise=None): |
| 327 | if noise is None: |
| 328 | batch, _, height, width = image.shape |
| 329 | noise = image.new_empty(batch, 1, height, width).normal_() |
| 330 | |
| 331 | return image + self.weight * noise |
| 332 | |
| 333 | |
| 334 | class ConstantInput(nn.Module): |