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