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

Method __init__

x2ct_nerf/modules/diffusionmodules/model.py:777–858  ·  view source on GitHub ↗
(self, *, ch, out_ch, ch_mult=(1, 2, 4, 8), num_res_blocks,
                 attn_resolutions, dropout=0.0, resamp_with_conv=True, in_channels,
                 resolution, z_channels, give_pre_end=False, output_key=[],
                 skipconnect_type=None, skipconnect_emb=None, skipconnect_layer=None, **ignorekwargs)

Source from the content-addressed store, hash-verified

775
776class UNetBlockDecoder(nn.Module):
777 def __init__(self, *, ch, out_ch, ch_mult=(1, 2, 4, 8), num_res_blocks,
778 attn_resolutions, dropout=0.0, resamp_with_conv=True, in_channels,
779 resolution, z_channels, give_pre_end=False, output_key=[],
780 skipconnect_type=None, skipconnect_emb=None, skipconnect_layer=None, **ignorekwargs):
781 super().__init__()
782 self.output_key = output_key
783 self.ch = ch
784 self.temb_ch = 0
785 self.num_resolutions = len(ch_mult)
786 self.num_res_blocks = num_res_blocks
787 self.resolution = resolution
788 self.in_channels = in_channels
789 self.give_pre_end = give_pre_end
790 self.skipconnect_type = skipconnect_type # {sum, concat, nonlinear_sum}
791 self.skipconnect_emb = skipconnect_emb
792 self.skipconnect_layer = skipconnect_layer
793 assert self.skipconnect_type in ['sum', 'concat', 'nonlinear_sum']
794
795 # compute in_ch_mult, block_in and curr_res at lowest res
796 in_ch_mult = (1,)+tuple(ch_mult)
797 block_in = ch*ch_mult[self.num_resolutions-1]
798 curr_res = resolution // 2**(self.num_resolutions-1)
799 self.z_shape = (1, z_channels, curr_res, curr_res)
800 print("Working with z of shape {} = {} dimensions.".format(
801 self.z_shape, np.prod(self.z_shape)))
802
803 self.conv_in = torch.nn.Conv2d(z_channels,
804 block_in,
805 kernel_size=3,
806 stride=1,
807 padding=1)
808
809 # middle
810 self.mid = nn.Module()
811 self.mid.block_1 = ResnetUNetBlock(in_channels=block_in,
812 out_channels=block_in,
813 temb_channels=self.temb_ch,
814 dropout=dropout)
815 self.mid.attn_1 = AttnBlock(block_in)
816 self.mid.block_2 = ResnetUNetBlock(in_channels=block_in,
817 out_channels=block_in,
818 temb_channels=self.temb_ch,
819 dropout=dropout)
820
821 # upsampling
822 self.skip_ch = 0
823 self.concat_feat = 0
824 self.up = nn.ModuleList()
825 for i, i_level in enumerate(reversed(range(self.num_resolutions))):
826 block = nn.ModuleList()
827 attn = nn.ModuleList()
828 block_out = ch*ch_mult[i_level]
829 if i != 0:
830 if self.skipconnect_type in ['nonlinear_sum', 'sum']:
831 self.skip_ch = skipconnect_emb[i-1]
832 if self.skipconnect_type == 'concat':
833 self.concat_feat = self.skipconnect_emb[i-1]
834 for i_block in range(self.num_res_blocks+1):

Callers

nothing calls this directly

Calls 5

ResnetUNetBlockClass · 0.85
AttnBlockClass · 0.70
UpsampleClass · 0.70
NormalizeFunction · 0.70
__init__Method · 0.45

Tested by

no test coverage detected