Model image distributions
Learn the visual structure of training images and generate plausible new samples, rather than simply classifying images.
Diffusion Models from Scratch explores how a neural network can learn to reverse a gradual noising process and generate new images. I rebuilt the workflow in PyTorch using denoising diffusion probabilistic models (DDPM), a conditional U-Net, time embeddings and classifier-free guidance.
Inspired by practical exercises completed during an NVIDIA Deep Learning Institute course; the public repository is an independent reconstruction following the loss of my original working notebooks.
Instead of predicting an existing label, a diffusion model learns a sequence of transformations that turns random noise into a structured image.
Learn the visual structure of training images and generate plausible new samples, rather than simply classifying images.
Train a time-aware neural network to estimate the noise added to an image at different stages of diffusion.
Export the intermediate reverse-diffusion states as GIFs and videos to inspect how the sampling trajectory evolves.
Training exposes the network to noisy versions of real images. Generation starts with random noise and repeatedly predicts what should be removed.
The forward process gradually adds Gaussian noise according to a predefined noise schedule. A random timestep t can be sampled directly during training.
The U-Net estimates the noise present at the current timestep. A sampling rule removes a portion of that noise and iterates toward the final image.
Conceptual diagrams for explanation; they do not represent measured model outputs. The equations show the usual DDPM noise-prediction parameterization, where ε is sampled Gaussian noise and y is optional class conditioning.
The network operates at several spatial resolutions, combines local and contextual information through skip connections, and predicts a noise tensor matching the image shape.
Structural overview; the exact layer widths and training settings are configurable in the repository.
Extract increasingly abstract features while reducing spatial resolution.
Combine rich features with information about the diffusion timestep and available conditions.
Recover spatial resolution, reusing encoder features to preserve finer details.
These mechanisms connect a conventional convolutional network to a probabilistic image-generation pipeline.
A sequence of noise strengths controls how much clean-image information remains at each timestep.
Convert timestep indices into vectors so the network can adapt its prediction to different noise levels.
Use mean squared error between sampled Gaussian noise and the network's predicted noise.
Provide labels to steer the model toward specific visual classes rather than generating unconditionally.
Train with occasional dropped conditions, then combine conditional and unconditional noise predictions while sampling.
Run repeated denoising steps and save intermediate frames to visualize the model's evolving estimates.
Instead of directly drawing the final image, the model learns to estimate the added noise. During conditional sampling, classifier-free guidance adjusts the estimated noise using predictions with and without the class label.
The workflow separates model training from the sampling and export stages so experiments can be reproduced with different datasets or trained checkpoints.
Load images, resize and normalize; construct train batches.
Draw t and Gaussian noise ε for each image.
Compute noisy xₜ using the diffusion schedule.
Pass xₜ, time embedding and optional label through U-Net.
Minimize noise prediction MSE and save a model checkpoint.
Start from noise; perform reverse diffusion with optional CFG.
Save final grids and denoising frames as PNG, GIF and MP4.
The project explores denoising in both single-channel and color images, with increasing visual complexity and conditioning requirements.
Small grayscale images of clothing provide a controlled setting to understand how the model learns the overall structure of objects while removing noise.
Color imagery introduces an additional degree of difficulty: learning patterns across three correlated channels and exploring class-conditioned generation.
The learning material also covered digit generation and concepts associated with CLIP embeddings. The public reconstruction emphasizes the DDPM training and sampling pipeline.
These are the original animation files preserved from my NVIDIA coursework. They illustrate generation trajectories; the repository also provides scripts to produce new ones from freshly trained checkpoints.
Frame-by-frame visualization of a denoising experiment with Fashion-MNIST.
Open fashion.mp4 ↗Visual record of an RGB flower-generation experiment and its evolving samples.
Open flowers.mp4 ↗The same two experiments are also preserved as GIF files. Animations may take a moment to load on slower connections.


The independent repository organizes training, sampling and video export into separate commands. The exact number of epochs and image quality depend on the hardware, dataset and chosen settings.
# Install requirements
pip install -r requirements.txt
# Run automated tests
python -m pytest -q
# Train the Fashion-MNIST model
python scripts/train.py --dataset fashion --epochs 20
# Sample images and export PNG / GIF / MP4
python scripts/sample.py --checkpoint checkpoints/fashion.pt --samples 70 --output demo/generated_fashionCheckpoint-based sampling avoids training again every time a new generation or video is needed.
Intermediate diffusion frames are collected and combined into visual grids, GIF animations and MP4 clips.
Automated tests exercise core model and export functionality; full training quality must be evaluated after running a complete experiment.
The most valuable outcome was understanding how architectural design, probability and an iterative inference algorithm combine to make image generation possible.
Generative AI is a process, not just an output. Building and rebuilding this workflow helped me understand how the noise schedule, training objective, neural architecture and sampling decisions influence the final result.
I learned how a model can approximate a reverse stochastic process by predicting noise at different timesteps, rather than directly producing an image in one pass.
Time embeddings help a single U-Net operate across multiple noise levels; class information and CFG offer additional control during generation.
Inspecting the full reverse trajectory makes debugging and interpretation more informative than examining only the final generated grid.
Separating model architecture, training, sampling and exports, along with basic tests and documentation, makes the implementation easier to revisit and extend.
This project connects the mathematics of probabilistic modeling to practical deep learning engineering, while preserving an honest distinction between historical course demonstrations and the newer independent reconstruction.
The GitHub repository is an independent learning implementation. NVIDIA is credited as the educational context; this project is not presented as an official NVIDIA product or an endorsement.
Explore the PyTorch code, model components, training scripts, sampling pipeline, tests and project documentation.
View GitHub repository ↗The work originated as hands-on exercises in an NVIDIA Deep Learning Institute course. After losing the original code, I created a separate reconstruction and retained the original GIF/MP4 outputs as historical demonstrations.
Educational attribution · no claim of official affiliation