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

Method __init__

ldm/modules/diffusionmodules/model.py:469–532  ·  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, double_z=True, use_linear_attn=False, attn_type="vanilla",
                 **ignore_kwargs)

Source from the content-addressed store, hash-verified

467
468class Encoder(nn.Module):
469 def __init__(self, *, ch, out_ch, ch_mult=(1,2,4,8), num_res_blocks,
470 attn_resolutions, dropout=0.0, resamp_with_conv=True, in_channels,
471 resolution, z_channels, double_z=True, use_linear_attn=False, attn_type="vanilla",
472 **ignore_kwargs):
473 super().__init__()
474 if use_linear_attn: attn_type = "linear"
475 self.ch = ch
476 self.temb_ch = 0
477 self.num_resolutions = len(ch_mult)
478 self.num_res_blocks = num_res_blocks
479 self.resolution = resolution
480 self.in_channels = in_channels
481
482 # downsampling
483 self.conv_in = torch.nn.Conv2d(in_channels,
484 self.ch,
485 kernel_size=3,
486 stride=1,
487 padding=1)
488
489 curr_res = resolution
490 in_ch_mult = (1,)+tuple(ch_mult)
491 self.in_ch_mult = in_ch_mult
492 self.down = nn.ModuleList()
493 for i_level in range(self.num_resolutions):
494 block = nn.ModuleList()
495 attn = nn.ModuleList()
496 block_in = ch*in_ch_mult[i_level]
497 block_out = ch*ch_mult[i_level]
498 for i_block in range(self.num_res_blocks):
499 block.append(ResnetBlock(in_channels=block_in,
500 out_channels=block_out,
501 temb_channels=self.temb_ch,
502 dropout=dropout))
503 block_in = block_out
504 if curr_res in attn_resolutions:
505 attn.append(make_attn(block_in, attn_type=attn_type))
506 down = nn.Module()
507 down.block = block
508 down.attn = attn
509 if i_level != self.num_resolutions-1:
510 down.downsample = Downsample(block_in, resamp_with_conv)
511 curr_res = curr_res // 2
512 self.down.append(down)
513
514 # middle
515 self.mid = nn.Module()
516 self.mid.block_1 = ResnetBlock(in_channels=block_in,
517 out_channels=block_in,
518 temb_channels=self.temb_ch,
519 dropout=dropout)
520 self.mid.attn_1 = make_attn(block_in, attn_type=attn_type)
521 self.mid.block_2 = ResnetBlock(in_channels=block_in,
522 out_channels=block_in,
523 temb_channels=self.temb_ch,
524 dropout=dropout)
525
526 # end

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected