MedLatent β€” Autoencoders on brain MRI and faces (latent size 2 β†’ 128)

Convolutional autoencoders trained with latent dimensions 2 to 128 on two very different datasets: IXI brain MRI (healthy adults, T1 axial slices) and CelebA faces. They are part of a controlled AE-vs-VAE study: same architecture, data, optimiser and schedule. The only differences are the latent layer.

  • Companion repo: medlatent-vae
  • Interactive demo β€” latent clusters (PCA / t-SNE / UMAP, 2-D / 3-D), real vs generated images, latent walks, dataset comparison: MedLatent Studio

⚠️ Research models, not medical devices. Reconstructions and generated brain images are not diagnostic images.

Results (held-out test set)

IXI brain MRI β€” 128Γ—128 grayscale T1 slices

run z PSNR (dB) fg PSNR SSIM FID recon ↓ FID Gaussian-fit samples ↓ best epoch
ixi/z2 2 20.29 15.71 0.718 197.9 189.9 95
ixi/z3 3 20.64 16.03 0.735 194.3 184.0 74
ixi/z4 4 21.56 16.77 0.780 188.7 172.3 80
ixi/z8 8 23.43 18.46 0.833 156.4 142.8 51
ixi/z16 16 24.68 19.64 0.856 156.6 142.2 21
ixi/z64 64 26.54 21.42 0.891 124.9 125.7 67
ixi/z128 128 27.07 21.94 0.899 119.6 121.0 84

Real-vs-real FID on this dataset: 5.6 (the best achievable reference).

IXI metrics vs latent size

CelebA faces β€” 64Γ—64 RGB

run z PSNR (dB) fg PSNR SSIM FID recon ↓ FID Gaussian-fit samples ↓ best epoch
celeba/z2 2 15.17 15.24 0.442 163.8 170.0 50
celeba/z4 4 16.31 16.32 0.484 133.6 133.4 48
celeba/z8 8 17.73 17.67 0.541 105.0 109.5 50
celeba/z16 16 19.14 19.03 0.605 86.1 89.2 39
celeba/z64 64 22.10 21.92 0.723 69.4 76.8 45
celeba/z128 128 23.60 23.40 0.778 58.7 74.8 48

Real-vs-real FID on this dataset: 3.0 (the best achievable reference).

CelebA metrics vs latent size

Samples from a z = 16 model (IXI):

samples

Metrics. PSNR/SSIM on the full image; fg PSNR only on foreground pixels (the black background inflates PSNR). FID with the standard InceptionV3 features (grayscale repeated to RGB, up to 10,000 test images). FID is only comparable within a dataset. Generation for the AE: decode codes drawn from a full-covariance Gaussian fitted to the training codes (latent_gaussian.npz). Single seed per configuration; treat differences below ~0.2 dB / a few FID points as noise.

Files

{ixi,celeba}/<run>/
  model.safetensors      weights (state_dict, fp32)
  config.json            architecture, training setup, best epoch, test metrics
  latent_gaussian.npz    mean + Cholesky factor of a Gaussian fitted to the training codes (for sampling)
  metrics_test.json      all test metrics      history.csv   per-epoch train/val curves
  figures/               training curves, samples, latent traversals/perturbations,
                         latent_space/ PCA, t-SNE, UMAP in 2-D and 3-D (PNG + interactive HTML), training_progress/
{ixi,celeba}/comparison/  results table, metrics-vs-latent figure, AE-vs-VAE latent comparisons per size
models/ae.py              self-contained model definition

CelebA licence compliance: figures that show or reconstruct real CelebA faces are not included. CelebA folders only contain generated images and plots.

Usage

import json, numpy as np, torch
from huggingface_hub import hf_hub_download
from safetensors.torch import load_file
import importlib.util

repo, run = "ChandraPrakashBathula/medlatent-autoencoder", "ixi/z16"
spec = importlib.util.spec_from_file_location("m", hf_hub_download(repo, "models/ae.py"))
m = importlib.util.module_from_spec(spec); spec.loader.exec_module(m)

cfg = json.load(open(hf_hub_download(repo, f"{run}/config.json")))
model = m.Autoencoder(m.AEConfig(**cfg["model_config"])).eval()
model.load_state_dict(load_file(hf_hub_download(repo, f"{run}/model.safetensors")))

g = np.load(hf_hub_download(repo, f"{run}/latent_gaussian.npz"))
mu, L = torch.tensor(g["mean"]).float(), torch.tensor(g["chol"]).float()
z = cfg["model_config"]["latent_dim"]
with torch.no_grad():
    codes = mu + torch.randn(16, z) @ L.T   # Gaussian fitted to the training codes
    samples = model.decode(codes)
# images are in [0, 1]: IXI 1x128x128, CelebA 3x64x64

Training setup

  • Encoder: 5 stride-2 conv stages (32β†’512 channels, GroupNorm, SiLU) β†’ linear to the latent; decoder mirrors it with nearest-neighbour upsampling and a sigmoid output. About 12–15 M parameters.
  • Loss: per-pixel MSE.
  • AdamW (lr 2e-4, weight decay 1e-4), cosine schedule, batch 64, AMP, gradient clipping 1.0. Early stopping on validation loss (IXI: patience 15, ≀100 epochs; CelebA: patience 10, ≀50 epochs; a 100-epoch CelebA control run gave no improvement).
  • Augmentation (training only): IXI random flip, Β±10Β° rotation, Β±5 % scale/shift, intensity gamma ∈ [1/1.2, 1.2]; CelebA flip only.
  • Data: IXI 581 subjects, axial slices in the 30–80 % height range, 70/15/15 split by subject (407/87/87, seed 42). CelebA official partition (162,770 / 19,867 / 19,962; identities disjoint), centre crop 148 β†’ 64Γ—64.

Limitations

Trained with a pixel-wise loss, so reconstructions and samples are blurry: fine anatomy (cortical folds) and texture (hair) are lost first. Samples are far from real data (see real-vs-real FID). Healthy adult IXI scans only: no pathology, scanner or population shift was tested. Tiny IXI models (z ≀ 3) are ~0.5–0.8 dB worse with augmentation than without.

Licence

  • Weights trained on IXI: derived from data under CC BY-SA 3.0 (https://brain-development.org/ixi-dataset/).
  • Weights trained on CelebA: non-commercial research use only, following the CelebA dataset agreement (Liu et al., Deep Learning Face Attributes in the Wild, ICCV 2015).
  • See LICENSE.md. No warranty; not for clinical use.
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Dataset used to train ChandraPrakashBathula/medlatent-autoencoder

Space using ChandraPrakashBathula/medlatent-autoencoder 1