(self, x, t=None, context=None)
| 314 | padding=1) |
| 315 | |
| 316 | def forward(self, x, t=None, context=None): |
| 317 | #assert x.shape[2] == x.shape[3] == self.resolution |
| 318 | if context is not None: |
| 319 | # assume aligned context, cat along channel axis |
| 320 | x = torch.cat((x, context), dim=1) |
| 321 | if self.use_timestep: |
| 322 | # timestep embedding |
| 323 | assert t is not None |
| 324 | temb = get_timestep_embedding(t, self.ch) |
| 325 | temb = self.temb.dense[0](temb) |
| 326 | temb = nonlinearity(temb) |
| 327 | temb = self.temb.dense[1](temb) |
| 328 | else: |
| 329 | temb = None |
| 330 | |
| 331 | # downsampling |
| 332 | hs = [self.conv_in(x)] |
| 333 | for i_level in range(self.num_resolutions): |
| 334 | for i_block in range(self.num_res_blocks): |
| 335 | h = self.down[i_level].block[i_block](hs[-1], temb) |
| 336 | if len(self.down[i_level].attn) > 0: |
| 337 | h = self.down[i_level].attn[i_block](h) |
| 338 | hs.append(h) |
| 339 | if i_level != self.num_resolutions-1: |
| 340 | hs.append(self.down[i_level].downsample(hs[-1])) |
| 341 | |
| 342 | # middle |
| 343 | h = hs[-1] |
| 344 | h = self.mid.block_1(h, temb) |
| 345 | h = self.mid.attn_1(h) |
| 346 | h = self.mid.block_2(h, temb) |
| 347 | |
| 348 | # upsampling |
| 349 | for i_level in reversed(range(self.num_resolutions)): |
| 350 | for i_block in range(self.num_res_blocks+1): |
| 351 | h = self.up[i_level].block[i_block]( |
| 352 | torch.cat([h, hs.pop()], dim=1), temb) |
| 353 | if len(self.up[i_level].attn) > 0: |
| 354 | h = self.up[i_level].attn[i_block](h) |
| 355 | if i_level != 0: |
| 356 | h = self.up[i_level].upsample(h) |
| 357 | |
| 358 | # end |
| 359 | h = self.norm_out(h) |
| 360 | h = nonlinearity(h) |
| 361 | h = self.conv_out(h) |
| 362 | return h |
| 363 | |
| 364 | def get_last_layer(self): |
| 365 | return self.conv_out.weight |
nothing calls this directly
no test coverage detected