MCPcopy Create free account
hub / github.com/cientgu/VQ-Diffusion / Decoder

Class Decoder

image_synthesis/taming/modules/diffusionmodules/model.py:436–537  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

434
435
436class Decoder(nn.Module):
437 def __init__(self, *, ch, out_ch, ch_mult=(1,2,4,8), num_res_blocks,
438 attn_resolutions, dropout=0.0, resamp_with_conv=True, in_channels,
439 resolution, z_channels, give_pre_end=False, **ignorekwargs):
440 super().__init__()
441 self.ch = ch
442 self.temb_ch = 0
443 self.num_resolutions = len(ch_mult)
444 self.num_res_blocks = num_res_blocks
445 self.resolution = resolution
446 self.in_channels = in_channels
447 self.give_pre_end = give_pre_end
448
449 # compute in_ch_mult, block_in and curr_res at lowest res
450 in_ch_mult = (1,)+tuple(ch_mult)
451 block_in = ch*ch_mult[self.num_resolutions-1]
452 curr_res = resolution // 2**(self.num_resolutions-1)
453 self.z_shape = (1,z_channels,curr_res,curr_res)
454 print("Working with z of shape {} = {} dimensions.".format(
455 self.z_shape, np.prod(self.z_shape)))
456
457 # z to block_in
458 self.conv_in = torch.nn.Conv2d(z_channels,
459 block_in,
460 kernel_size=3,
461 stride=1,
462 padding=1)
463
464 # middle
465 self.mid = nn.Module()
466 self.mid.block_1 = ResnetBlock(in_channels=block_in,
467 out_channels=block_in,
468 temb_channels=self.temb_ch,
469 dropout=dropout)
470 self.mid.attn_1 = AttnBlock(block_in)
471 self.mid.block_2 = ResnetBlock(in_channels=block_in,
472 out_channels=block_in,
473 temb_channels=self.temb_ch,
474 dropout=dropout)
475
476 # upsampling
477 self.up = nn.ModuleList()
478 for i_level in reversed(range(self.num_resolutions)):
479 block = nn.ModuleList()
480 attn = nn.ModuleList()
481 block_out = ch*ch_mult[i_level]
482 for i_block in range(self.num_res_blocks+1):
483 block.append(ResnetBlock(in_channels=block_in,
484 out_channels=block_out,
485 temb_channels=self.temb_ch,
486 dropout=dropout))
487 block_in = block_out
488 if curr_res in attn_resolutions:
489 attn.append(AttnBlock(block_in))
490 up = nn.Module()
491 up.block = block
492 up.attn = attn
493 if i_level != 0:

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected