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

Method __init__

ldm/modules/diffusionmodules/model.py:317–414  ·  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, use_timestep=True, use_linear_attn=False, attn_type="vanilla")

Source from the content-addressed store, hash-verified

315
316class Model(nn.Module):
317 def __init__(self, *, ch, out_ch, ch_mult=(1,2,4,8), num_res_blocks,
318 attn_resolutions, dropout=0.0, resamp_with_conv=True, in_channels,
319 resolution, use_timestep=True, use_linear_attn=False, attn_type="vanilla"):
320 super().__init__()
321 if use_linear_attn: attn_type = "linear"
322 self.ch = ch
323 self.temb_ch = self.ch*4
324 self.num_resolutions = len(ch_mult)
325 self.num_res_blocks = num_res_blocks
326 self.resolution = resolution
327 self.in_channels = in_channels
328
329 self.use_timestep = use_timestep
330 if self.use_timestep:
331 # timestep embedding
332 self.temb = nn.Module()
333 self.temb.dense = nn.ModuleList([
334 torch.nn.Linear(self.ch,
335 self.temb_ch),
336 torch.nn.Linear(self.temb_ch,
337 self.temb_ch),
338 ])
339
340 # downsampling
341 self.conv_in = torch.nn.Conv2d(in_channels,
342 self.ch,
343 kernel_size=3,
344 stride=1,
345 padding=1)
346
347 curr_res = resolution
348 in_ch_mult = (1,)+tuple(ch_mult)
349 self.down = nn.ModuleList()
350 for i_level in range(self.num_resolutions):
351 block = nn.ModuleList()
352 attn = nn.ModuleList()
353 block_in = ch*in_ch_mult[i_level]
354 block_out = ch*ch_mult[i_level]
355 for i_block in range(self.num_res_blocks):
356 block.append(ResnetBlock(in_channels=block_in,
357 out_channels=block_out,
358 temb_channels=self.temb_ch,
359 dropout=dropout))
360 block_in = block_out
361 if curr_res in attn_resolutions:
362 attn.append(make_attn(block_in, attn_type=attn_type))
363 down = nn.Module()
364 down.block = block
365 down.attn = attn
366 if i_level != self.num_resolutions-1:
367 down.downsample = Downsample(block_in, resamp_with_conv)
368 curr_res = curr_res // 2
369 self.down.append(down)
370
371 # middle
372 self.mid = nn.Module()
373 self.mid.block_1 = ResnetBlock(in_channels=block_in,
374 out_channels=block_in,

Callers 15

__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45

Calls 5

ResnetBlockClass · 0.85
make_attnFunction · 0.85
DownsampleClass · 0.70
UpsampleClass · 0.70
NormalizeFunction · 0.70

Tested by

no test coverage detected