CoolFace
Modelpublic

HoumanAHuman/conditional-diffusion-mnist

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
Model Card

Conditional Diffusion on Modified MNIST

This project trains a class-conditional diffusion model on a modified MNIST dataset where class 1 includes samples from both MNIST digit 1 and FashionMNIST class 'trouser'.

๐Ÿ“ฆ Setup

bash
git clone https://github.com/yourusername/conditional-diffusion-mnist.git
cd conditional-diffusion-mnist
pip install -r requirements.txt

๐Ÿ“„ Dataset

Prepare the custom dataset:

bash
python prepare_dataset.py

This generates Dataset/shuffled_mnist_with_trousers.pt, a balanced dataset of MNIST 1s and FashionMNIST trousers labeled as 1.

๐Ÿงจ Train the Diffusion Model

bash
python train_diffusion.py

This trains a conditional DDPM model and saves checkpoints under the DDPM/ directory, including unet_final.pt.

๐ŸŽจ Sample from the Model

bash
python sample_images.py

This loads the trained model from DDPM/unet_final.pt and generates class-conditioned samples (by default, class 1).

๐Ÿ“ Folder Structure

conditional-diffusion-mnist/
โ”œโ”€โ”€ DDPM/                                                                 # Model checkpoints
โ”‚   โ””โ”€โ”€ unet_final_ema.pt
โ”‚   โ””โ”€โ”€ class_embedder.pt
โ”œโ”€โ”€ Samples/                                                              # Sample generation
โ”‚   โ””โ”€โ”€ class {condition_class}/                                          # Samples from the original model with respective conditioned class
โ”‚   โ””โ”€โ”€ class {condition_class}-Unlearned with constant lambda/           # Samples from the unlearned (constant lambda) model with respective conditioned class
โ”‚   โ””โ”€โ”€ class {condition_class}-Unlearned with dynamic lambda/            # Samples from the unlearned (dynamic lambda) model with respective conditioned class
โ”œโ”€โ”€ DDPM_Unlearned/                                                       # Model checkpoints after Unlearning with constant lambda
โ”‚   โ””โ”€โ”€ unet_unlearned_ema.pt
โ”‚   โ””โ”€โ”€ class_embedder_unlearned_ema.pt
โ”œโ”€โ”€ DDPM_Unlearned_dynamic/                                               # Model checkpoints after Unlearning with dynamic lambda
โ”‚   โ””โ”€โ”€ unet_unlearned_dynamic_ema.pt
โ”‚   โ””โ”€โ”€ class_embedder_unlearned_dynamic_ema.pt
โ”œโ”€โ”€ Dataset/                                                              # Custom dataset generation and files
โ”‚   โ””โ”€โ”€ shuffled_augmented_mnist.pt
โ”‚   โ””โ”€โ”€ original_mnist.pt
โ”‚   โ””โ”€โ”€ trousers_subset.pt
โ”œโ”€โ”€ train_diffusion.py                                                    # Training script
โ”œโ”€โ”€ preprocess_dataset.py                                                 # Dataset creation script
โ”œโ”€โ”€ requirements.txt
โ””โ”€โ”€ README.md

๐Ÿงช Requirements

Install all dependencies using:

bash
pip install -r requirements.txt

๐Ÿ“ License

MIT License