(self, x, t=None, context=None)
| 414 | padding=1) |
| 415 | |
| 416 | def forward(self, x, t=None, context=None): |
| 417 | #assert x.shape[2] == x.shape[3] == self.resolution |
| 418 | if context is not None: |
| 419 | # assume aligned context, cat along channel axis |
| 420 | x = torch.cat((x, context), dim=1) |
| 421 | if self.use_timestep: |
| 422 | # timestep embedding |
| 423 | assert t is not None |
| 424 | temb = get_timestep_embedding(t, self.ch) |
| 425 | temb = self.temb.dense[0](temb) |
| 426 | temb = nonlinearity(temb) |
| 427 | temb = self.temb.dense[1](temb) |
| 428 | else: |
| 429 | temb = None |
| 430 | |
| 431 | # downsampling |
| 432 | hs = [self.conv_in(x)] |
| 433 | for i_level in range(self.num_resolutions): |
| 434 | for i_block in range(self.num_res_blocks): |
| 435 | h = self.down[i_level].block[i_block](hs[-1], temb) |
| 436 | if len(self.down[i_level].attn) > 0: |
| 437 | h = self.down[i_level].attn[i_block](h) |
| 438 | hs.append(h) |
| 439 | if i_level != self.num_resolutions-1: |
| 440 | hs.append(self.down[i_level].downsample(hs[-1])) |
| 441 | |
| 442 | # middle |
| 443 | h = hs[-1] |
| 444 | h = self.mid.block_1(h, temb) |
| 445 | h = self.mid.attn_1(h) |
| 446 | h = self.mid.block_2(h, temb) |
| 447 | |
| 448 | # upsampling |
| 449 | for i_level in reversed(range(self.num_resolutions)): |
| 450 | for i_block in range(self.num_res_blocks+1): |
| 451 | h = self.up[i_level].block[i_block]( |
| 452 | torch.cat([h, hs.pop()], dim=1), temb) |
| 453 | if len(self.up[i_level].attn) > 0: |
| 454 | h = self.up[i_level].attn[i_block](h) |
| 455 | if i_level != 0: |
| 456 | h = self.up[i_level].upsample(h) |
| 457 | |
| 458 | # end |
| 459 | h = self.norm_out(h) |
| 460 | h = nonlinearity(h) |
| 461 | h = self.conv_out(h) |
| 462 | return h |
| 463 | |
| 464 | def get_last_layer(self): |
| 465 | return self.conv_out.weight |
nothing calls this directly
no test coverage detected