(
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,
pad_mode="first",
temporal_compress_times=4,
**ignore_kwargs,
)
| 294 | |
| 295 | class Encoder3D(nn.Module): |
| 296 | def __init__( |
| 297 | self, |
| 298 | *, |
| 299 | ch, |
| 300 | out_ch, |
| 301 | ch_mult=(1, 2, 4, 8), |
| 302 | num_res_blocks, |
| 303 | attn_resolutions, |
| 304 | dropout=0.0, |
| 305 | resamp_with_conv=True, |
| 306 | in_channels, |
| 307 | resolution, |
| 308 | z_channels, |
| 309 | double_z=True, |
| 310 | pad_mode="first", |
| 311 | temporal_compress_times=4, |
| 312 | **ignore_kwargs, |
| 313 | ): |
| 314 | super().__init__() |
| 315 | self.ch = ch |
| 316 | self.temb_ch = 0 |
| 317 | self.num_resolutions = len(ch_mult) |
| 318 | self.num_res_blocks = num_res_blocks |
| 319 | self.resolution = resolution |
| 320 | self.in_channels = in_channels |
| 321 | |
| 322 | # log2 of temporal_compress_times |
| 323 | self.temporal_compress_level = int(np.log2(temporal_compress_times)) |
| 324 | |
| 325 | # downsampling |
| 326 | # self.conv_in = torch.nn.Conv3d(in_channels, |
| 327 | # self.ch, |
| 328 | # kernel_size=3, |
| 329 | # stride=1, |
| 330 | # padding=1) |
| 331 | self.conv_in = CausalConv3d(in_channels, self.ch, kernel_size=3, pad_mode=pad_mode) |
| 332 | |
| 333 | curr_res = resolution |
| 334 | in_ch_mult = (1,) + tuple(ch_mult) |
| 335 | self.down = nn.ModuleList() |
| 336 | for i_level in range(self.num_resolutions): |
| 337 | block = nn.ModuleList() |
| 338 | attn = nn.ModuleList() |
| 339 | block_in = ch * in_ch_mult[i_level] |
| 340 | block_out = ch * ch_mult[i_level] |
| 341 | for i_block in range(self.num_res_blocks): |
| 342 | block.append( |
| 343 | ResnetBlock3D( |
| 344 | in_channels=block_in, |
| 345 | out_channels=block_out, |
| 346 | temb_channels=self.temb_ch, |
| 347 | dropout=dropout, |
| 348 | pad_mode=pad_mode, |
| 349 | ) |
| 350 | ) |
| 351 | block_in = block_out |
| 352 | if curr_res in attn_resolutions: |
| 353 | attn.append(AttnBlock2D(block_in)) |
no test coverage detected