(
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,
)
| 431 | |
| 432 | class Encoder(nn.Module): |
| 433 | def __init__( |
| 434 | self, |
| 435 | *, |
| 436 | ch, |
| 437 | out_ch, |
| 438 | ch_mult=(1, 2, 4, 8), |
| 439 | num_res_blocks, |
| 440 | attn_resolutions, |
| 441 | dropout=0.0, |
| 442 | resamp_with_conv=True, |
| 443 | in_channels, |
| 444 | resolution, |
| 445 | z_channels, |
| 446 | double_z=True, |
| 447 | use_linear_attn=False, |
| 448 | attn_type="vanilla", |
| 449 | **ignore_kwargs, |
| 450 | ): |
| 451 | super().__init__() |
| 452 | if use_linear_attn: |
| 453 | attn_type = "linear" |
| 454 | self.ch = ch |
| 455 | self.temb_ch = 0 |
| 456 | self.num_resolutions = len(ch_mult) |
| 457 | self.num_res_blocks = num_res_blocks |
| 458 | self.resolution = resolution |
| 459 | self.in_channels = in_channels |
| 460 | |
| 461 | # downsampling |
| 462 | self.conv_in = torch.nn.Conv2d(in_channels, self.ch, kernel_size=3, stride=1, padding=1) |
| 463 | |
| 464 | curr_res = resolution |
| 465 | in_ch_mult = (1,) + tuple(ch_mult) |
| 466 | self.in_ch_mult = in_ch_mult |
| 467 | self.down = nn.ModuleList() |
| 468 | for i_level in range(self.num_resolutions): |
| 469 | block = nn.ModuleList() |
| 470 | attn = nn.ModuleList() |
| 471 | block_in = ch * in_ch_mult[i_level] |
| 472 | block_out = ch * ch_mult[i_level] |
| 473 | for i_block in range(self.num_res_blocks): |
| 474 | block.append( |
| 475 | ResnetBlock( |
| 476 | in_channels=block_in, |
| 477 | out_channels=block_out, |
| 478 | temb_channels=self.temb_ch, |
| 479 | dropout=dropout, |
| 480 | ) |
| 481 | ) |
| 482 | block_in = block_out |
| 483 | if curr_res in attn_resolutions: |
| 484 | attn.append(make_attn(block_in, attn_type=attn_type)) |
| 485 | down = nn.Module() |
| 486 | down.block = block |
| 487 | down.attn = attn |
| 488 | if i_level != self.num_resolutions - 1: |
| 489 | down.downsample = Downsample(block_in, resamp_with_conv) |
| 490 | curr_res = curr_res // 2 |
nothing calls this directly
no test coverage detected