Encodes the input by passing through the encoder network and returns the latent codes. :param input: (Tensor) Input tensor to encoder [N x C x H x W] :return: (Tensor) List of latent codes
(self, input: Tensor)
| 81 | nn.Tanh()) |
| 82 | |
| 83 | def encode(self, input: Tensor) -> List[Tensor]: |
| 84 | """ |
| 85 | Encodes the input by passing through the encoder network |
| 86 | and returns the latent codes. |
| 87 | :param input: (Tensor) Input tensor to encoder [N x C x H x W] |
| 88 | :return: (Tensor) List of latent codes |
| 89 | """ |
| 90 | result = self.encoder(input) |
| 91 | result = torch.flatten(result, start_dim=1) |
| 92 | |
| 93 | # Split the result into mu and var components |
| 94 | # of the latent Gaussian distribution |
| 95 | mu = self.fc_mu(result) |
| 96 | log_var = self.fc_var(result) |
| 97 | |
| 98 | return [mu, log_var] |
| 99 | |
| 100 | def decode(self, z: Tensor) -> Tensor: |
| 101 | result = self.decoder_input(z) |