MCPcopy Create free account
hub / github.com/dek924/PerX2CT / DecoderNoAttn

Class DecoderNoAttn

x2ct_nerf/modules/diffusionmodules/model.py:654–773  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

652
653
654class DecoderNoAttn(nn.Module):
655 def __init__(self, *, ch, out_ch, ch_mult=(1, 2, 4, 8), num_res_blocks,
656 attn_resolutions, dropout=0.0, resamp_with_conv=True, in_channels,
657 resolution, z_channels, give_pre_end=False, output_key=[], **ignorekwargs):
658 super().__init__()
659 self.output_key = output_key
660 self.ch = ch
661 self.temb_ch = 0
662 self.num_resolutions = len(ch_mult)
663 self.num_res_blocks = num_res_blocks
664 self.resolution = resolution
665 self.in_channels = in_channels
666 self.give_pre_end = give_pre_end
667
668 # compute in_ch_mult, block_in and curr_res at lowest res
669 in_ch_mult = (1,)+tuple(ch_mult)
670 block_in = ch*ch_mult[self.num_resolutions-1]
671 curr_res = resolution // 2**(self.num_resolutions-1)
672 self.z_shape = (1, z_channels, curr_res, curr_res)
673 print("Working with z of shape {} = {} dimensions.".format(
674 self.z_shape, np.prod(self.z_shape)))
675
676 # z to block_in
677 self.conv_in = torch.nn.Conv2d(z_channels,
678 block_in,
679 kernel_size=3,
680 stride=1,
681 padding=1)
682
683 # middle
684 self.mid = nn.Module()
685 self.mid.block_1 = ResnetBlock(in_channels=block_in,
686 out_channels=block_in,
687 temb_channels=self.temb_ch,
688 dropout=dropout)
689 # self.mid.attn_1 = AttnBlock(block_in)
690 self.mid.block_2 = ResnetBlock(in_channels=block_in,
691 out_channels=block_in,
692 temb_channels=self.temb_ch,
693 dropout=dropout)
694
695 # upsampling
696 self.up = nn.ModuleList()
697 for i_level in reversed(range(self.num_resolutions)):
698 block = nn.ModuleList()
699 attn = nn.ModuleList()
700 block_out = ch*ch_mult[i_level]
701 for i_block in range(self.num_res_blocks+1):
702 block.append(ResnetBlock(in_channels=block_in,
703 out_channels=block_out,
704 temb_channels=self.temb_ch,
705 dropout=dropout))
706 block_in = block_out
707 if curr_res in attn_resolutions:
708 attn.append(AttnBlock(block_in))
709 up = nn.Module()
710 up.block = block
711 up.attn = attn

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected