MCPcopy Create free account
hub / github.com/bbaaii/DreamDiffusion / UpsampleDecoder

Class UpsampleDecoder

code/dc_ldm/modules/diffusionmodules/model.py:607–652  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected