MCPcopy Create free account
hub / github.com/IceClear/StableSR / __init__

Method __init__

ldm/modules/diffusionmodules/model.py:570–640  ·  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, tanh_out=False, use_linear_attn=False,
                 attn_type="vanilla", **ignorekwargs)

Source from the content-addressed store, hash-verified

568
569class Decoder(nn.Module):
570 def __init__(self, *, ch, out_ch, ch_mult=(1,2,4,8), num_res_blocks,
571 attn_resolutions, dropout=0.0, resamp_with_conv=True, in_channels,
572 resolution, z_channels, give_pre_end=False, tanh_out=False, use_linear_attn=False,
573 attn_type="vanilla", **ignorekwargs):
574 super().__init__()
575 if use_linear_attn: attn_type = "linear"
576 self.ch = ch
577 self.temb_ch = 0
578 self.num_resolutions = len(ch_mult)
579 self.num_res_blocks = num_res_blocks
580 self.resolution = resolution
581 self.in_channels = in_channels
582 self.give_pre_end = give_pre_end
583 self.tanh_out = tanh_out
584
585 # compute in_ch_mult, block_in and curr_res at lowest res
586 in_ch_mult = (1,)+tuple(ch_mult)
587 block_in = ch*ch_mult[self.num_resolutions-1]
588 curr_res = resolution // 2**(self.num_resolutions-1)
589 self.z_shape = (1,z_channels,curr_res,curr_res)
590 print("Working with z of shape {} = {} dimensions.".format(
591 self.z_shape, np.prod(self.z_shape)))
592
593 # z to block_in
594 self.conv_in = torch.nn.Conv2d(z_channels,
595 block_in,
596 kernel_size=3,
597 stride=1,
598 padding=1)
599
600 # middle
601 self.mid = nn.Module()
602 self.mid.block_1 = ResnetBlock(in_channels=block_in,
603 out_channels=block_in,
604 temb_channels=self.temb_ch,
605 dropout=dropout)
606 self.mid.attn_1 = make_attn(block_in, attn_type=attn_type)
607 self.mid.block_2 = ResnetBlock(in_channels=block_in,
608 out_channels=block_in,
609 temb_channels=self.temb_ch,
610 dropout=dropout)
611
612 # upsampling
613 self.up = nn.ModuleList()
614 for i_level in reversed(range(self.num_resolutions)):
615 block = nn.ModuleList()
616 attn = nn.ModuleList()
617 block_out = ch*ch_mult[i_level]
618 for i_block in range(self.num_res_blocks+1):
619 block.append(ResnetBlock(in_channels=block_in,
620 out_channels=block_out,
621 temb_channels=self.temb_ch,
622 dropout=dropout))
623 block_in = block_out
624 if curr_res in attn_resolutions:
625 attn.append(make_attn(block_in, attn_type=attn_type))
626 up = nn.Module()
627 up.block = block

Callers

nothing calls this directly

Calls 5

ResnetBlockClass · 0.85
make_attnFunction · 0.85
UpsampleClass · 0.70
NormalizeFunction · 0.70
__init__Method · 0.45

Tested by

no test coverage detected