puruchinera/anime-faces-256
Viewer • Updated • 48.2k • 174 • 3
This repository contains an AutoencoderKL (AEKL) trained from scratch for latent-space image synthesis experiments on anime face datasets. This model is designed specifically for latent-space synthesis rather than direct image generation.
(4, 16, 16)0.04706926643848419 (required for correct latent normalization)To train or use the model from the source repository:
git clone https://github.com/YoelPilier/AnimeFaces256_AEKL
cd AnimeFaces256_AEKL
pip install -r requirements.txt
from Models import VAE
import torch
vae = VAE.from_pretrained(checkpoint="best", use_ema=True)
vae = vae.to("cuda")
vae.eval()
with torch.no_grad():
x = batch_images.to("cuda")
z_mean, z_log_var = vae.encoder(x)
z = vae.reparameterize(z_mean, z_log_var)
latents = z * vae.scaling_factor
with torch.no_grad():
z = latents / vae.scaling_factor
images = vae.decoder(z)
For reference, the core architecture is structured as follows:
class VAE(nn.Module):
REPO_ID = "puruchinera/AnimeFaces256_AEKL"
def __init__(self, input_dim=3, hidden_dim=64, latent_dim=4, compression_factor=4):
super().__init__()
self.encoder = Encoder(
input_dim,
hidden_dim,
num_downsamples=compression_factor,
latent_size=latent_dim,
)
self.decoder = Decoder(
input_dim,
hidden_dim,
num_upsamples=compression_factor,
latent_size=latent_dim,
)
self.scaling_factor = 0.04706926643848419
self.latent_dim = latent_dim
def forward(self, x):
z_mean, z_log_var = self.encoder(x)
z = self.reparameterize(z_mean, z_log_var)
reconstructed = self.decoder(z)
return reconstructed, z_mean, z_log_var
def reparameterize(self, mean, log_var):
log_var = torch.tanh(log_var) * 5
std = torch.exp(0.5 * log_var)
eps = torch.randn_like(std)
return mean + eps * std
To train the model yourself using accelerate:
accelerate launch train_vae.py
optimizer = torch.optim.AdamW(
model.parameters(),
lr=3e-4,
weight_decay=1e-5
)
lr = 3e-4lr = 3e-5lr = 5e-6| Metric | Training Value | Validation Value |
|---|---|---|
| Loss | 0.1967 | 0.2022 |
| PSNR | 22.1035 | 22.1793 |
| SSIM | 0.7837 | 0.7853 |
| KL Divergence | 219.7652 | 229.9244 |
| LPIPS | 0.1533 | 0.1611 |
| Reconstruction | 0.0862 | 0.0814 |
If you use this repository or its code in your research or projects, please cite it as:
@misc{pilier2026animefaces256aekl,
author = {Yoel Pilier},
title = {AnimeFaces256-AEKL: AutoencoderKL trained for latent-space image synthesis on anime face datasets},
year = {2026},
publisher = {GitHub},
howpublished = {\url{https://github.com/YoelPilier/AnimeFaces256_AEKL}}
}