🧬 Welmia Face 2.0 — 7.6M Base
A small, 7.6-million-parameter StyleGAN2-style GAN that generates 128×128 human faces from random noise. Trained from scratch, runs on a plain CPU.
✨ Highlights
- Small: 7,625,453 generator parameters (~30.5 MB, float32).
- Runs on CPU: about 22 images/second on an Intel Core i5-10400 (no GPU), see Speed for the exact numbers and caveats.
- StyleGAN2-style generator: mapping network, modulated convolutions with demodulation, per-layer noise inputs, skip-RGB output, no BatchNorm.
- Quality controls: truncation (
psi) to trade diversity for cleaner faces. - Safe weights: shipped as
safetensors(no pickle, no arbitrary code execution when loading the weights). - Reproducible on request: every run prints its seed, so you can regenerate the same faces with
--seed.
🚀 Quick Start
1. Install
pip install torch torchvision safetensors pillow numpy
2. Download the repo files into one folder
You need these four files together:
model.safetensors
welmia_gan.py
welmia_cfg.json
generate.py
3. Generate faces
python generate.py # 8 random faces (2x4 grid) -> ./inference_output/
python generate.py --num 50 # 50 faces
python generate.py --psi 1.0 # more diverse, less clean
python generate.py --seed 7 # reproducible faces
python generate.py --benchmark # measure speed on your machine
Every run prints the seed it used. Run python generate.py --seed <that number> (with the same --psi and --num) to get the same faces back.
4. Use it in your own code
import json, sys, torch
from huggingface_hub import snapshot_download
from safetensors.torch import load_file
path = snapshot_download("Welmia/welmia-face-2.0-7.6m-base")
sys.path.insert(0, path)
import welmia_gan as W
cfg = json.load(open(f"{path}/welmia_cfg.json"))
g = W.make_G(cfg)
g.load_state_dict(load_file(f"{path}/model.safetensors"))
g.eval()
with torch.inference_mode():
z = torch.randn(8, cfg["z_dim"]) # z_dim = 256
imgs = g(z, psi=0.7).clamp(-1, 1) * 0.5 + 0.5 # RGB, 0..1, shape [8, 3, 128, 128]
save_image(imgs, "faces.png", nrow=4) # saves a 2x4 grid
print("Saved faces.png")
welmia_gan.pyis normal Python code that gets imported. Read it before running it, as you should with any code you download.
🎛️ Truncation (psi)
psi pulls each face toward the "average" face.
| psi | Effect |
|---|---|
0.5 | Cleanest and safest, but faces look more similar to each other |
0.7 | Default. Good balance of quality and variety |
1.0 | Full diversity, but more artifacts (warped backgrounds, odd accessories) |
Try python generate.py --psi 1.0 to see the difference yourself.
⚡ Speed (measured on one machine)
| Property | Value |
|---|---|
| CPU | Intel Core i5-10400 |
| RAM | 16 GB |
| GPU used | None (CPU only) |
| Test | python generate.py, 16 faces per run, ψ = 0.7, 5 separate runs |
| Metric | Result |
|---|---|
| Time per batch of 16 | 693 – 874 ms (median 734 ms) |
| Time per image | 43 – 55 ms (median ~46 ms) |
| Throughput | 18 – 23 images/s (median ~22 img/s) |
Caveats (please read):
- Each run was a fresh Python process with no warm-up, so it includes first-call overhead. Steady-state speed should be somewhat better, and
python generate.py --benchmarkmeasures that. - The timing covers the model forward pass only, not saving PNG files.
- This is one machine. Your numbers will differ with CPU, thread count and PyTorch version.
- Compared with our earlier 3.6M DCGAN model (welmia-face-1.0-3.6m-base, whose card reports 50+ img/s on the same CPU), this model is roughly 2× slower per image. That is the price of the bigger, better architecture.
📐 Model Details
| Property | Value |
|---|---|
| Type | StyleGAN2-style generator (unconditional) |
| Generator parameters | 7,625,453 |
| File size | ~30.5 MB (float32, safetensors) |
| Output | 128 × 128 RGB, tanh range [-1, 1] in the model, [0, 1] after the rescale shown above |
| Latent (z) / style (w) size | 256 / 256 |
| Mapping network | 4 layers |
| Channels per resolution | 4:384, 8:384, 16:256, 32:160, 64:96, 128:48 |
| Weights in this repo | EMA (exponential moving average) generator only |
The discriminator is not included. It is only needed for training.
Training summary
| Setting | Value |
|---|---|
| Training | From scratch, no pre-trained weights |
| Hardware | 2 GPUs, distributed data parallel (NCCL gradient all-reduce) |
| Batch size | 64 total (32 per GPU) |
| Learning rate | 0.002 (Adam, betas 0.0 / 0.99) |
| Loss | Non-saturating logistic loss + R1 regularization (gamma 0.25, every 16 steps) |
| Generator EMA | 10 kimg half-life |
| Augmentation | Random horizontal flip |
| Style mixing probability | 0.9 |
| Discriminator | Residual, no normalization layers, minibatch std layer |
📊 Evaluation
There is no quantitative evaluation yet. No FID, precision or recall was computed. Quality was judged by looking at samples, so treat any claim of "better than X" as a visual impression and not a measured result.
⚠️ Limitations
- Low resolution. Output is 128×128. Upscaling it does not add detail.
- Imperfect details. Backgrounds, hair edges, hats, jewelry, glasses and non-frontal poses can show warping or smearing, especially at
psi = 1.0. - Dataset bias. The model reflects its training data. Some ages, skin tones, hairstyles, expressions and backgrounds are better represented than others, and output quality can vary across them.
- Small model. With 7.6M parameters it will not match large production face generators.
- Single-machine speed numbers. See the speed section above.
🛑 Responsible Use
- Every face is synthetic. Do not present generated images as photographs of real people.
- Do not use this model for impersonation, fraud, harassment, disinformation, or to create misleading content.
- Do not use it for identity verification, biometrics, or any decision that affects real people.
- Generated faces may by chance resemble a real person.
📜 License
Released under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 (CC BY-NC-SA 4.0).
- ✅ You may use, share and adapt the model for non-commercial purposes, with attribution to Welmia.
- 🔁 Anything you build on it must be shared under the same license.
- ❌ Commercial use is not permitted. The license is non-commercial because the model was trained on data that carries non-commercial terms.
🔗 Links
- 🌐 Website: welmia.kesug.com
- 🤗 Hugging Face: huggingface.co/Welmia
- 🧬 Previous model: welmia-face-1.0-3.6m-base
- 🐛 Feedback: open a discussion on this repo
Made with curiosity, a small GPU budget, and too much coffee. ☕