MCPcopy Create free account
hub / github.com/TencentARC/MotionCtrl / UpsampleDecoder

Class UpsampleDecoder

lvdm/modules/networks/ae_modules.py:619–664  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

617
618
619class UpsampleDecoder(nn.Module):
620 def __init__(self, in_channels, out_channels, ch, num_res_blocks, resolution,
621 ch_mult=(2,2), dropout=0.0):
622 super().__init__()
623 # upsampling
624 self.temb_ch = 0
625 self.num_resolutions = len(ch_mult)
626 self.num_res_blocks = num_res_blocks
627 block_in = in_channels
628 curr_res = resolution // 2 ** (self.num_resolutions - 1)
629 self.res_blocks = nn.ModuleList()
630 self.upsample_blocks = nn.ModuleList()
631 for i_level in range(self.num_resolutions):
632 res_block = []
633 block_out = ch * ch_mult[i_level]
634 for i_block in range(self.num_res_blocks + 1):
635 res_block.append(ResnetBlock(in_channels=block_in,
636 out_channels=block_out,
637 temb_channels=self.temb_ch,
638 dropout=dropout))
639 block_in = block_out
640 self.res_blocks.append(nn.ModuleList(res_block))
641 if i_level != self.num_resolutions - 1:
642 self.upsample_blocks.append(Upsample(block_in, True))
643 curr_res = curr_res * 2
644
645 # end
646 self.norm_out = Normalize(block_in)
647 self.conv_out = torch.nn.Conv2d(block_in,
648 out_channels,
649 kernel_size=3,
650 stride=1,
651 padding=1)
652
653 def forward(self, x):
654 # upsampling
655 h = x
656 for k, i_level in enumerate(range(self.num_resolutions)):
657 for i_block in range(self.num_res_blocks + 1):
658 h = self.res_blocks[i_level][i_block](h, None)
659 if i_level != self.num_resolutions - 1:
660 h = self.upsample_blocks[k](h)
661 h = self.norm_out(h)
662 h = nonlinearity(h)
663 h = self.conv_out(h)
664 return h
665
666
667class LatentRescaler(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected