Instructions to use CVL-Heidelberg/PQGAN with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PQGAN
How to use CVL-Heidelberg/PQGAN with PQGAN:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Add PQGAN F8 (K512) and F16 (K128) autoencoder weights and model card
Browse files
README.md
CHANGED
|
@@ -1,3 +1,87 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
+
library_name: pytorch
|
| 4 |
+
pipeline_tag: image-to-image
|
| 5 |
+
tags:
|
| 6 |
+
- autoencoder
|
| 7 |
+
- product-quantization
|
| 8 |
+
- vqgan
|
| 9 |
+
- image-tokenizer
|
| 10 |
+
datasets:
|
| 11 |
+
- imagenet-1k
|
| 12 |
---
|
| 13 |
+
|
| 14 |
+
# PQGAN: Product-Quantised Image Representation for High-Quality Image Synthesis
|
| 15 |
+
|
| 16 |
+
Pretrained PQGAN autoencoders from the ICLR 2026 paper by Denis Zavadski, Nikita Philip Tatsch and Carsten Rother.
|
| 17 |
+
|
| 18 |
+
[Paper (OpenReview)](https://openreview.net/forum?id=D8oqcochgq) · [arXiv](https://arxiv.org/abs/2510.03191) · [Code](https://github.com/vislearn/PQGAN)
|
| 19 |
+
|
| 20 |
+
PQGAN replaces the single codebook of VQGAN with product quantisation. Each latent vector is split into *S* subspaces, and each subspace is quantised with its own codebook of *K* entries.
|
| 21 |
+
|
| 22 |
+
## Models
|
| 23 |
+
|
| 24 |
+
Both models were trained on ImageNet at 256×256. Metrics are on the ImageNet validation set (50k images).
|
| 25 |
+
|
| 26 |
+
| File | *F* | *d* | *K* | *S* | Latent (256×256 input) | PSNR ↑ | rFID ↓ | CMMD ↓ | LPIPS ↓ |
|
| 27 |
+
|------|-----|-----|-----|-----|------------------------|--------|--------|--------|---------|
|
| 28 |
+
| `checkpoints/PQGAN_F8_K512_Z128_S64` | 8 | 128 | 512 | 64 | 128×32×32 | 37.4 | 0.036 | 0.011 | 0.0024 |
|
| 29 |
+
| `checkpoints/PQGAN_F16_K128_Z128_S64` | 16 | 128 | 128 | 64 | 128×16×16 | 28.3 | 0.41 | 0.094 | 0.0304 |
|
| 30 |
+
|
| 31 |
+
*F*: downsampling factor, *d*: latent channels, *K*: codebook size per subspace, *S*: number of subspaces.
|
| 32 |
+
|
| 33 |
+
Each model has a `.safetensors` file with the autoencoder and quantiser weights, and a `.yaml` file with the model config. Discriminator and optimizer states are not included.
|
| 34 |
+
|
| 35 |
+
## Usage
|
| 36 |
+
|
| 37 |
+
Install the code from [GitHub](https://github.com/vislearn/PQGAN) (Python 3.11):
|
| 38 |
+
|
| 39 |
+
```sh
|
| 40 |
+
git clone https://github.com/vislearn/PQGAN.git
|
| 41 |
+
cd PQGAN
|
| 42 |
+
pip install -e .
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
Load a model and reconstruct an image:
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
import torch
|
| 49 |
+
import yaml
|
| 50 |
+
from huggingface_hub import hf_hub_download
|
| 51 |
+
from PIL import Image
|
| 52 |
+
from safetensors.torch import load_file
|
| 53 |
+
from torchvision import transforms
|
| 54 |
+
|
| 55 |
+
from vv.models.latent_diffusion_copy import VQModel
|
| 56 |
+
|
| 57 |
+
name = "PQGAN_F8_K512_Z128_S64" # or "PQGAN_F16_K128_Z128_S64"
|
| 58 |
+
config = yaml.safe_load(open(hf_hub_download("CVL-Heidelberg/PQGAN", f"checkpoints/{name}.yaml")))
|
| 59 |
+
model = VQModel(**config["model"]["init_args"])
|
| 60 |
+
model.load_state_dict(load_file(hf_hub_download("CVL-Heidelberg/PQGAN", f"checkpoints/{name}.safetensors")))
|
| 61 |
+
model = model.eval().cuda()
|
| 62 |
+
|
| 63 |
+
# Models expect 256x256 inputs with ImageNet normalisation
|
| 64 |
+
mean, std = torch.tensor([0.485, 0.456, 0.406]), torch.tensor([0.229, 0.224, 0.225])
|
| 65 |
+
preprocess = transforms.Compose([transforms.Resize((256, 256)), transforms.ToTensor(), transforms.Normalize(mean, std)])
|
| 66 |
+
x = preprocess(Image.open("image.jpg").convert("RGB")).unsqueeze(0).cuda()
|
| 67 |
+
|
| 68 |
+
with torch.no_grad():
|
| 69 |
+
quant, _, (_, _, indices) = model.encode(x) # quant: (1, 128, 32, 32) for F=8, (1, 128, 16, 16) for F=16
|
| 70 |
+
rec = model.decode(quant)
|
| 71 |
+
|
| 72 |
+
rec = (rec.cpu() * std[:, None, None] + mean[:, None, None]).clamp(0, 1) # back to [0, 1]
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
`indices` is a list with one tensor of codebook indices per subspace (64 entries).
|
| 76 |
+
|
| 77 |
+
## Citation
|
| 78 |
+
|
| 79 |
+
```bibtex
|
| 80 |
+
@inproceedings{zavadski2026pqgan,
|
| 81 |
+
title = {{PQGAN}: Product-Quantised Image Representation for High-Quality Image Synthesis},
|
| 82 |
+
author = {Zavadski, Denis and Tatsch, Nikita Philip and Rother, Carsten},
|
| 83 |
+
booktitle = {The Fourteenth International Conference on Learning Representations},
|
| 84 |
+
year = {2026},
|
| 85 |
+
url = {https://openreview.net/forum?id=D8oqcochgq}
|
| 86 |
+
}
|
| 87 |
+
```
|
checkpoints/PQGAN_F16_K128_Z128_S64.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:501dd5a0f536576b274e54c3f6c6dc084e85cd470ea4be875acc2cf02300638d
|
| 3 |
+
size 287631732
|
checkpoints/PQGAN_F16_K128_Z128_S64.yaml
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
model:
|
| 2 |
+
class_path: vv.models.latent_diffusion_copy.VQModel
|
| 3 |
+
init_args:
|
| 4 |
+
learning_rate: 4.5e-06
|
| 5 |
+
ddconfig:
|
| 6 |
+
double_z: false
|
| 7 |
+
z_channels: 256
|
| 8 |
+
resolution: 256
|
| 9 |
+
in_channels: 3
|
| 10 |
+
out_ch: 3
|
| 11 |
+
ch: 128
|
| 12 |
+
ch_mult:
|
| 13 |
+
- 1
|
| 14 |
+
- 1
|
| 15 |
+
- 2
|
| 16 |
+
- 2
|
| 17 |
+
- 4
|
| 18 |
+
num_res_blocks: 2
|
| 19 |
+
attn_resolutions:
|
| 20 |
+
- 16
|
| 21 |
+
dropout: 0.0
|
| 22 |
+
lossconfig:
|
| 23 |
+
target: vv.models.latent_diffusion_copy.dummy_loss.DummyLoss
|
| 24 |
+
n_embed: 128
|
| 25 |
+
embed_dim: 128
|
| 26 |
+
ckpt_path: null
|
| 27 |
+
ignore_keys: []
|
| 28 |
+
image_key: image
|
| 29 |
+
colorize_nlabels: null
|
| 30 |
+
monitor: val/rec_loss
|
| 31 |
+
batch_resize_range: null
|
| 32 |
+
scheduler_config: null
|
| 33 |
+
lr_g_factor: 1.0
|
| 34 |
+
remap: null
|
| 35 |
+
sane_index_shape: false
|
| 36 |
+
use_ema: false
|
| 37 |
+
split_quantizer: true
|
| 38 |
+
num_spaces: 64
|
| 39 |
+
distance_type: l2
|
checkpoints/PQGAN_F8_K512_Z128_S64.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d17aa790335e5ccdb003524bb5624780c49807877db02b22dde3b78a3eb12bf1
|
| 3 |
+
size 281515908
|
checkpoints/PQGAN_F8_K512_Z128_S64.yaml
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
model:
|
| 2 |
+
class_path: vv.models.latent_diffusion_copy.VQModel
|
| 3 |
+
init_args:
|
| 4 |
+
learning_rate: 4.5e-06
|
| 5 |
+
ddconfig:
|
| 6 |
+
double_z: false
|
| 7 |
+
z_channels: 256
|
| 8 |
+
resolution: 256
|
| 9 |
+
in_channels: 3
|
| 10 |
+
out_ch: 3
|
| 11 |
+
ch: 128
|
| 12 |
+
ch_mult:
|
| 13 |
+
- 1
|
| 14 |
+
- 2
|
| 15 |
+
- 2
|
| 16 |
+
- 4
|
| 17 |
+
num_res_blocks: 2
|
| 18 |
+
attn_resolutions:
|
| 19 |
+
- 32
|
| 20 |
+
dropout: 0.0
|
| 21 |
+
lossconfig:
|
| 22 |
+
target: vv.models.latent_diffusion_copy.dummy_loss.DummyLoss
|
| 23 |
+
n_embed: 512
|
| 24 |
+
embed_dim: 128
|
| 25 |
+
ckpt_path: null
|
| 26 |
+
ignore_keys: []
|
| 27 |
+
image_key: image
|
| 28 |
+
colorize_nlabels: null
|
| 29 |
+
monitor: val/rec_loss
|
| 30 |
+
batch_resize_range: null
|
| 31 |
+
scheduler_config: null
|
| 32 |
+
lr_g_factor: 1.0
|
| 33 |
+
remap: null
|
| 34 |
+
sane_index_shape: false
|
| 35 |
+
use_ema: false
|
| 36 |
+
split_quantizer: true
|
| 37 |
+
num_spaces: 64
|
| 38 |
+
distance_type: l2
|