Compute the Inception Score from class probabilities
Why it matters Inception Score was a standard GAN metric and is still reported in image generation papers.
The Inception Score rewards generated samples that are each confidently classified and, together, cover many classes.
Write inception_score(P). P is (n, k) predicted class probabilities for n generated images. Marginal p_y = mean over rows. Return exp(mean over rows of KL(P_i || p_y)), using 0 * log 0 = 0.
def inception_score(P)Example
P = identity (3, 3) gives KL log 3 for each row, so the score is 3.
Understand the idea
The Inception Score rates generated images using a classifier's predicted class probabilities. Good generators make images that are each clearly one class (sharp rows) and, across the set, cover many classes (a broad average). KL divergence between each row and the average captures both. Worked example: P = [[0.9, 0.1], [0.1, 0.9]]. The marginal is [0.5, 0.5]. KL for row 1 = 0.9 ln(0.9 / 0.5) + 0.1 ln(0.1 / 0.5) = 0.529 - 0.161 = 0.368, and row 2 is the same. IS = exp(0.368) = about 1.445. If every image were confidently the same class, P = [[1, 0], [1, 0]], the marginal equals each row, KL is 0 and IS = 1. Perfect one-hot rows over 2 classes give IS = 2. Rule: p_y = mean of the rows of P; KL_i = sum over classes of P_ij * log(P_ij / p_y_j), treating 0 * log 0 as 0; IS = exp(mean of KL_i). Compare to the actual marginal, not a uniform distribution, or mode collapse goes unpunished. Used in: older GAN and diffusion papers, usually alongside FID.