MCPcopy Create free account
hub / github.com/VisionXLab/OF-Diff / UpsampleDecoder

Class UpsampleDecoder

ldm/modules/diffusionmodules/model.py:700–745  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

698
699
700class UpsampleDecoder(nn.Module):
701 def __init__(self, in_channels, out_channels, ch, num_res_blocks, resolution,
702 ch_mult=(2,2), dropout=0.0):
703 super().__init__()
704 # upsampling
705 self.temb_ch = 0
706 self.num_resolutions = len(ch_mult)
707 self.num_res_blocks = num_res_blocks
708 block_in = in_channels
709 curr_res = resolution // 2 ** (self.num_resolutions - 1)
710 self.res_blocks = nn.ModuleList()
711 self.upsample_blocks = nn.ModuleList()
712 for i_level in range(self.num_resolutions):
713 res_block = []
714 block_out = ch * ch_mult[i_level]
715 for i_block in range(self.num_res_blocks + 1):
716 res_block.append(ResnetBlock(in_channels=block_in,
717 out_channels=block_out,
718 temb_channels=self.temb_ch,
719 dropout=dropout))
720 block_in = block_out
721 self.res_blocks.append(nn.ModuleList(res_block))
722 if i_level != self.num_resolutions - 1:
723 self.upsample_blocks.append(Upsample(block_in, True))
724 curr_res = curr_res * 2
725
726 # end
727 self.norm_out = Normalize(block_in)
728 self.conv_out = torch.nn.Conv2d(block_in,
729 out_channels,
730 kernel_size=3,
731 stride=1,
732 padding=1)
733
734 def forward(self, x):
735 # upsampling
736 h = x
737 for k, i_level in enumerate(range(self.num_resolutions)):
738 for i_block in range(self.num_res_blocks + 1):
739 h = self.res_blocks[i_level][i_block](h, None)
740 if i_level != self.num_resolutions - 1:
741 h = self.upsample_blocks[k](h)
742 h = self.norm_out(h)
743 h = nonlinearity(h)
744 h = self.conv_out(h)
745 return h
746
747
748class LatentRescaler(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected