(self, img)
| 31 | |
| 32 | # convert PIL image to latents |
| 33 | def encode(self, img): |
| 34 | with torch.no_grad(): |
| 35 | latent = self.vae.encode(tfms.ToTensor()(img).unsqueeze(0).to(self.device) * 2 - 1) |
| 36 | latent = 0.18215 * latent.latent_dist.sample() |
| 37 | return latent |
| 38 | |
| 39 | # convert latents to PIL image |
| 40 | def decode(self, latent): |