* `x` has shape `[batch_size, in_channels, height, width]` * `t` has shape `[batch_size]`
(self, x: torch.Tensor, t: torch.Tensor=torch.tensor([0]).cuda())
| 281 | self.final = nn.Conv2d(in_channels, output_channels, kernel_size=(3, 3), padding=(1, 1)) |
| 282 | |
| 283 | def forward(self, x: torch.Tensor, t: torch.Tensor=torch.tensor([0]).cuda()): |
| 284 | """ |
| 285 | * `x` has shape `[batch_size, in_channels, height, width]` |
| 286 | * `t` has shape `[batch_size]` |
| 287 | """ |
| 288 | |
| 289 | # Get time-step embeddings |
| 290 | if self.is_noise: |
| 291 | t = self.time_emb(t) |
| 292 | else: |
| 293 | t = None |
| 294 | # Get image projection |
| 295 | x = self.image_proj(x) |
| 296 | |
| 297 | # `h` will store outputs at each resolution for skip connection |
| 298 | h = [x] |
| 299 | # First half of U-Net |
| 300 | for m in self.down: |
| 301 | x = m(x, t) |
| 302 | h.append(x) |
| 303 | |
| 304 | # Middle (bottom) |
| 305 | x = self.middle(x, t) |
| 306 | |
| 307 | # Second half of U-Net |
| 308 | for m in self.up: |
| 309 | if isinstance(m, Upsample): |
| 310 | x = m(x, t) |
| 311 | else: |
| 312 | # Get the skip connection from first half of U-Net and concatenate |
| 313 | s = h.pop() |
| 314 | # print(x.shape, s.shape) |
| 315 | x = torch.cat((x, s), dim=1) |
| 316 | # |
| 317 | x = m(x, t) |
| 318 | |
| 319 | # Final normalization and convolution |
| 320 | return self.final(self.act(x)) |
| 321 | |
| 322 | 9 |
| 323 | class DocDiff(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected