Diffusion Models

अब हम deep learning की सबसे आधुनिक और प्रभावशाली तकनीकों में से एक को सीखने जा रहे हैं — जो text-to-image जैसे tasks में breakthroughs लाई है:

🔍 धीरे-धीरे noise जोड़ो, फिर धीरे-धीरे उसे हटाकर नया data generate करो!


🔷 1. What are Diffusion Models?

Diffusion Models एक तरह के generative models हैं, जो training में images में noise डालते हैं और फिर सीखते हैं उसे वापस original image में बदलना।

🧠 Goal: Noise से high-quality image generate करना।


🔶 2. Real World Analogy

कल्पना कीजिए आपके पास एक साफ़ तस्वीर है, जिसे आप बार-बार थोड़ा-थोड़ा धुंधला (noise) करते हैं। अब model सीखता है कि कैसे इस धुंधली तस्वीर से साफ़ तस्वीर वापस बनाई जाए।


🔷 3. Core Idea

Diffusion Process में दो चरण होते हैं:

✅ 1. Forward Process (Adding Noise)

Original image में step-by-step Gaussian noise मिलाया जाता है।

  • जहां x_0 = original image
  • x_t = noisy image at step t
  • ε = Gaussian noise

✅ 2. Reverse Process (Denoising)

Model सीखता है कि इस noise को step-by-step हटाकर original image कैसे reconstruct की जाए।


🔶 4. Intuition:

Stageक्या हो रहा है
Forward ProcessImage → Noise
Reverse ProcessNoise → Image (generate करने के लिए!)

🔷 5. Architecture

Diffusion models आमतौर पर U-Net architecture का उपयोग करते हैं।

  • Noise-added image input किया जाता है
  • Time-step embedding दिया जाता है
  • U-Net output करता है predicted noise
  • Loss: MSE between actual noise और predicted noise

🔶 6. Training Objective

Model को सिखाया जाता है:

यानी: Model सिखे कि original noise (ε) क्या था, ताकि उसे हटाकर साफ़ image बन सके।


🔷 7. Famous Diffusion Models

ModelHighlightsOrganization
DDPMDenoising Diffusion Probabilistic ModelGoogle
Stable DiffusionText-to-Image diffusion modelStability AI
ImagenHigh-quality generation from textGoogle Brain
DALLE-2CLIP + DiffusionOpenAI

🔶 8. Applications of Diffusion Models

✅ Text-to-Image Generation
✅ Inpainting (Missing image fill करना)
✅ Super-resolution
✅ Audio synthesis
✅ 3D scene generation


🔷 9. Sample Code (Simplified PyTorch)

import torch
import torch.nn as nn

class SimpleDenoiseModel(nn.Module):
def __init__(self):
super().__init__()
self.net = nn.Sequential(
nn.Linear(784, 512),
nn.ReLU(),
nn.Linear(512, 784),
)
def forward(self, x, t):
return self.net(x)

# Forward diffusion (add noise)
def add_noise(x, t):
noise = torch.randn_like(x)
alpha = 1 - 0.02 * t # Simplified
return alpha * x + (1 - alpha) * noise, noise

🧠 Difference from GANs

FeatureGANDiffusion Model
Stable❌ Hard to train✅ More stable
Output QualityMedium to High✅ High
Mode Collapse❌ Possible✅ Rare
Training TimeFaster❌ Slower
Use CaseImage, video, textMostly high-fidelity images

📝 Practice Questions:

  1. Diffusion model में forward और reverse process क्या होते हैं?
  2. Stable Diffusion किस technique पर आधारित है?
  3. GAN और Diffusion में क्या अंतर है?
  4. Time-step embedding क्यों ज़रूरी है?
  5. Diffusion से कौन-कौन से real-world tasks solve किए जा सकते हैं?

🧾 Summary

ConceptDescription
Forward PassClean image → Add noise
Reverse PassNoisy image → Remove noise (generate)
ArchitectureMostly U-Net
Training LossMSE between true and predicted noise
OutputNew image generated from pure noise