MCPcopy Create free account
hub / github.com/LTH14/rcg / __init__

Method __init__

pixel_generator/mage/taming/modules/diffusionmodules/model.py:232–294  ·  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, **ignorekwargs)

Source from the content-addressed store, hash-verified

230
231class Decoder(nn.Module):
232 def __init__(self, *, ch, out_ch, ch_mult=(1,2,4,8), num_res_blocks,
233 attn_resolutions, dropout=0.0, resamp_with_conv=True, in_channels,
234 resolution, z_channels, give_pre_end=False, **ignorekwargs):
235 super().__init__()
236 self.ch = ch
237 self.temb_ch = 0
238 self.num_resolutions = len(ch_mult)
239 self.num_res_blocks = num_res_blocks
240 self.resolution = resolution
241 self.in_channels = in_channels
242 self.give_pre_end = give_pre_end
243
244 # compute in_ch_mult, block_in and curr_res at lowest res
245 in_ch_mult = (1,)+tuple(ch_mult)
246 block_in = ch*ch_mult[self.num_resolutions-1]
247 curr_res = resolution // 2**(self.num_resolutions-1)
248 self.z_shape = (1,z_channels,curr_res,curr_res)
249 print("Working with z of shape {} = {} dimensions.".format(
250 self.z_shape, np.prod(self.z_shape)))
251
252 # z to block_in
253 self.conv_in = torch.nn.Conv2d(z_channels,
254 block_in,
255 kernel_size=3,
256 stride=1,
257 padding=1)
258
259 # middle
260 self.mid = nn.Module()
261 self.mid.block_1 = ResnetBlock(in_channels=block_in,
262 out_channels=block_in,
263 temb_channels=self.temb_ch,
264 dropout=dropout)
265 self.mid.block_2 = ResnetBlock(in_channels=block_in,
266 out_channels=block_in,
267 temb_channels=self.temb_ch,
268 dropout=dropout)
269
270 # upsampling
271 self.up = nn.ModuleList()
272 for i_level in reversed(range(self.num_resolutions)):
273 block = nn.ModuleList()
274 block_out = ch*ch_mult[i_level]
275 for i_block in range(self.num_res_blocks):
276 block.append(ResnetBlock(in_channels=block_in,
277 out_channels=block_out,
278 temb_channels=self.temb_ch,
279 dropout=dropout))
280 block_in = block_out
281 up = nn.Module()
282 up.block = block
283 if i_level != 0:
284 up.upsample = Upsample(block_in, resamp_with_conv)
285 curr_res = curr_res * 2
286 self.up.insert(0, up) # prepend to get consistent order
287
288 # end
289 self.norm_out = Normalize(block_in)

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected