| 462 | return params |
| 463 | |
| 464 | def encode(self, x: torch.Tensor, return_reg_log: bool = False) -> Union[torch.Tensor, Tuple[torch.Tensor, dict]]: |
| 465 | if self.max_batch_size is None: |
| 466 | z = self.encoder(x) |
| 467 | z = self.quant_conv(z) |
| 468 | else: |
| 469 | N = x.shape[0] |
| 470 | bs = self.max_batch_size |
| 471 | n_batches = int(math.ceil(N / bs)) |
| 472 | z = list() |
| 473 | for i_batch in range(n_batches): |
| 474 | z_batch = self.encoder(x[i_batch * bs : (i_batch + 1) * bs]) |
| 475 | z_batch = self.quant_conv(z_batch) |
| 476 | z.append(z_batch) |
| 477 | z = torch.cat(z, 0) |
| 478 | |
| 479 | z, reg_log = self.regularization(z) |
| 480 | if return_reg_log: |
| 481 | return z, reg_log |
| 482 | return z |
| 483 | |
| 484 | def decode(self, z: torch.Tensor, **decoder_kwargs) -> torch.Tensor: |
| 485 | if self.max_batch_size is None: |