4.5.17 · HinglishGenerative Models

Evaluating generative models (FID, IS)

3,115 words14 min readRead in English

4.5.17 · AI-ML › Generative Models

Overview

Evaluating generative models discriminative tasks se fundamentally alag hai kyunki koi ek "correct" output nahi hota—hum quality (realism) aur diversity (data distribution ki coverage) ki parwah karte hain. Traditional metrics jaise accuracy yahan apply nahi hoti, isliye hum specialized scores use karte hain: Inception Score (IS) aur Fréchet Inception Distance (FID).

Figure — Evaluating generative models (FID, IS)

Inception Score (IS)

Core Idea

Inception Score quality aur diversity measure karta hai yeh check karke:

  1. Sharpness (quality): Har generated image confidently ek category mein classify honi chahiye → low entropy conditional distribution
  2. Diversity: Overall label distribution uniform honi chahiye → high entropy marginal

First Principles se Derivation

Step 1: Ek "good" generative model kya hota hai?

Ek achha generator produce karna chahiye:

  • Meaningful images: Agar aap ek classifier ko ek image dikhao, toh woh confident hona chahiye (jaise "90% dog, 10% other") → ki low entropy hoti hai
  • Diverse images: Sabhi images mein milake, aapko sabhi classes dikhni chahiye → ki high entropy hoti hai

Step 2: KL divergence ise quantify karta hai

Yeh step kyun? KL divergence tab bada hota hai jab:

  • peaked ho (low entropy) → achhi quality
  • uniform ho (high entropy) → achhi diversity

Step 3: Sabhi generated samples par average karo

Hum ise logarithm properties se split karte hain:

Pehla term hai (negative conditional entropy), doosra simplify hota hai kyunki .

Toh:

Zyada (diverse labels) aur kam (confident predictions) → zyada IS.

Step 4: Interpretability ke liye exponentiate karo

Exponentiate kyun? Log-space se ek aisi scale par convert karne ke liye jahan higher = better, aur "effective number of classes" wali intuition se match karne ke liye. IS ≈ 1 matlab terrible (sabhi images ek jaisi lagte hain ya noise hain), IS ≈ number of classes matlab perfect.

Worked Example


Fréchet Inception Distance (FID)

Core Idea

FID real images aur generated images ke distributions ke beech Inception-v3 ke feature space mein distance measure karta hai. Lower FID = distributions zyada close hain = better generation.

First Principles se Derivation

Step 1: Gaussians ke liye Fréchet distance

Agar do distributions Gaussian hain:

Fréchet distance (Gaussians ke liye Wasserstein-2 distance bhi kaha jata hai) ka ek closed form hota hai:

Yeh formula kyun? Yeh 2-Wasserstein distance se aata hai:

jahan distributions ke beech ek coupling hai. Gaussians ke liye, is infimum ka analytical solution hota hai.

Step 2: Feature distributions par apply karo

Features extract karo:

  • real images ke liye: Inception pool3 layer se (2048-dim)
  • fake images ke liye:

Parameters estimate karo:

(Same ke liye)

Step 3: Matrix square root compute karo

Term eigenvalue decomposition se compute hota hai:

Agar , toh

Kyun? Kyunki positive semi-definite matrices ke liye, square root well-defined hoti hai.

Step 4: Difference ka trace

Trace kyun? Yeh sabhi 2048 dimensions mein covariance mismatch ko sum karta hai. term ek geometric mean hai jo covariance structure differences ko penalize karta hai.

Worked Example


IS vs FID: Kab Kya Use Karein

| Metric | Kya Measure Karta Hai | Pros | Cons | Best For | |--------|-------|------|----------| | IS | Quality & diversity (bina reference ke) | Fast, real data ki zaroorat nahi | Mode collapse detect nahi karta, ImageNet classes ki taraf biased | Quick sanity check, unconditional generation | | FID | Real data se distribution match | Mode collapse pakad leta hai, human judgment se align hota hai | Real data chahiye, compute karna expensive | Final evaluation, models compare karna |


Connections

  • GAN Training Dynamics: Yeh metrics GAN training guide karte hain—collapse FID drop mein dikha deta hai.
  • Inception-v3 Architecture: Feature extractor ko samajhna clarify karta hai ki yeh metrics kyun kaam karte hain.
  • Mode Collapse in GANs: FID is failure mode detect karne ka primary tool hai.
  • Precision and Recall for Generative Models: Newer metrics jo FID ko quality (precision) aur coverage (recall) mein decompose karte hain.
  • Perceptual Loss Functions: Similar idea—pre-trained networks use karke perceptual similarity measure karo.

Recall Ek 12-Saal ke Bachche ko Explain Karo

Imagine karo tum ek teacher ho jo art students grade kar rahe ho. Tum chahte ho ki unki drawings:

  1. Achhi hon (real cheezein jaisi lagein)
  2. Diverse hon (sab ek hi tree na banayein) Lekin tum khud hazaron drawings nahi dekh sakte, toh tum ek robot judge (Inception network) train karte ho jo seekh gaya hai ki "achha art" kaisa hota hai.

Inception Score (IS): Tum robot ko ek drawing dikhao. Agar woh kehta hai "yeh definitely ek dog hai!" (confident), toh drawing clear hai. Agar woh bahut saari drawings mein alag-alag cheezein dekhta hai (dogs, cats, cars), toh woh diverse hai. High IS = confident + diverse.

FID: Tumhare paas real photos aur student drawings hain. Tum robot se dono sets describe karwao (bina "dog" ya "cat" kahe, sirf internal descriptions jaise "pointy," "fluffy"). Phir tum measure karo: dono description clouds kitne similar hain? Chhota distance = drawings real photos jaisi lagti hain.

Dono kyun? IS sirf clarity check karta hai. FID check karta hai ki students sahi cheezein bana rahe hain (ek perfect dragon ki drawing "cats ki photos" se match nahi karti).


#flashcards/ai-ml

Inception Score (IS) kaunsi problem solve karta hai? :: Generative models ka automatic evaluation bina manual inspection ke, generated samples ki quality (sharpness) aur diversity dono measure karna ek pre-trained classifier se.

IS kaunsi do properties check karta hai?
1) Quality: individual samples mein low-entropy p(y|x) honi chahiye (confident predictions), 2) Diversity: marginal p(y) mein high entropy honi chahiye (sabhi classes represented).

Inception Score formula likho :: IS = exp(E_x[D_KL(p(y|x) || p(y))]) jahan p(y|x) classifier ki prediction hai generated image x ke liye, aur p(y) average class distribution hai.

IS mein KL divergence ko exponentiate kyun karte hain?
Log-space se ek interpretable scale par convert karne ke liye jahan higher better hai, aur "effective number of classes" wali intuition se match karne ke liye (perfect generation ke liye IS ≈ number of classes).
Inception Score ki main limitation kya hai?
Yeh mode collapse detect nahi kar sakta—ek model jo sirf ek mode ke perfect samples generate karta hai high IS achieve kar sakta hai kyunki p(y|x) phir bhi confident hai, chahe diversity kam ho.
FID kya measure karta hai?
Real image features aur generated image features ke distributions ke beech Inception-v3 ke feature space mein distance, specifically Fréchet distance yeh assume karke ki dono Gaussian hain.
FID formula likho
FID = ||μ_r - μ_g||² + Tr(Σ_r + Σ_g - 2(Σ_r Σ_g)^(1/2)) jahan μ aur Σ real (r) aur generated (g) features ka mean aur covariance hain.
FID ke do components kya hain?
1) Mean difference ||μ_r - μ_g||² jo distribution shift measure karta hai, 2) Covariance term Tr(Σ_r + Σ_g - 2(Σ_r Σ_g)^(1/2)) jo shape/spread mismatch measure karta hai.
Raw pixels ki jagah Inception-v3 features kyun use karte hain?
Inception features semantic properties (textures, object parts) capture karti hain jo human perception se align hoti hain, unlike pixel-space jahan chhote shifts bade distances cause karte hain chahe perceptually similar ho.
Kya aap alag-alag datasets ke FID scores compare kar sakte hain?
Nahi, FID dataset-dependent hai kyunki intrinsic complexity vary karti hai (MNIST vs CelebA) aur Inception ka feature space kuch data types ke liye doosron se better suited ho sakta hai.
FID = 0 ka matlab kya hai?
Generated aur real distributions feature space mein identical hain—lekin iska matlab yeh ho sakta hai ki model ne training data memorize kar li (overfitting) true generalization nahi.
FID mode collapse detect karne mein IS se better kyun hai?
FID real data distribution se compare karta hai, toh agar generator real data mein maujood modes miss karta hai, toh Σ_g, Σ_r se match nahi karega aur FID high hoga.
FID ke liye Inception-v3 ki kaunsi layer use hoti hai?
Pool3 layer (2048-dimensional feature vectors) final classification layer se pehle, jo high-level semantic features capture karti hai.
FID compute karne ke liye typically kitne samples use hote hain?
Stable covariance estimates paane ke liye real aur generated distributions dono se kam se kam 10,000 samples.
IS specifically KL divergence kyun use karta hai?
KL divergence naturally conditional p(y|x) aur marginal p(y) ke beech relationship capture karta hai—yeh bada hota hai jab individual samples confident hoon (low H(y|x)) lekin overall distribution diverse ho (high H(y)).
FID mein trace operation kya hai?
Tr(A) matrix A ke diagonal elements ko sum karta hai, is context mein sabhi 2048 feature dimensions mein total variance represent karta hai.
FID mein (Σ_r Σ_g)^(1/2) ki zaroorat kyun hai?
Matrix square root covariances ka geometric mean provide karta hai, ek symmetric distance create karta hai jo distributions ke beech correlation structure differences ko properly account karta hai.
High IS ke saath high FID kya indicate karta hai?
Generated images individually sharp hain aur bahut saari classes cover karti hain (high IS) lekin real data distribution se match nahi karti (high FID)—possible hai agar plausible lekin galat samples generate ho raha ho.
Low IS ke saath low FID kya indicate karta hai?
Yeh contradictory aur unlikely hai—low IS matlab blurry ya mode-collapsed samples, jo real data se achhi tarah match nahi hone chahiye. Evaluation error suggest karta hai.
FID ko quality se diversity alag karne ke liye kaunsa metric complement karta hai?
Generative models ke liye Precision aur Recall—precision sample quality measure karta hai (no outliers), recall mode coverage measure karta hai (distribution support).

Concept Map

cares about

cares about

uses metric

uses metric

relies on

relies on

low entropy

high entropy

measures quality

measures diversity

computed via

compares

against

Evaluating generative models

Quality realism

Diversity coverage

Inception-v3 classifier

Inception Score

Frechet Inception Distance

Conditional p y given x

Marginal p y

KL divergence