Downloads · 30 days
0
beatrizfarias/mnist-conditional-gan
mnist-conditional-gan is a machine learning model from beatrizfarias. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
A Conditional Generative Adversarial Network (cGAN) trained to generate handwritten digit images conditioned on a target label (0–9).
Downloads · 30 days
0
Access
Public
Updated Mar 26, 2026
Repo size
6 MB
Likes
0
Public
Click a slice to open those files.
.pth6 MB · 100%
From the Hugging Face model README
A Conditional Generative Adversarial Network (cGAN) trained to generate handwritten digit images conditioned on a target label (0–9).
Both the Generator and Discriminator receive the digit label as input via a learned embedding, allowing the Generator to produce class-specific images.
Generator
z (latent dim = 100) + label embedding (dim = 10)(1, 28, 28) grayscale imageDiscriminator
from huggingface_hub import hf_hub_download
import torch
from cgan_model import Generator
model = Generator(latent_dim=100, num_classes=10)
weights_path = hf_hub_download(repo_id="beatrizfarias/mnist-conditional-gan", filename="mnist_cgan_generator.pth")
model.load_state_dict(torch.load(weights_path, map_location="cpu"))
model.eval()
z = torch.randn(1, 100)
y = torch.tensor([7]) # generate a "7"
with torch.no_grad():
img = model(z, y) # shape: (1, 1, 28, 28)
All 10 digit classes are clearly recognizable and well-formed after 200 epochs of training.