The Concept
FID: fréchet inception distance
What It Measures
FID compares the distribution of generated images to real images:
- Extract features from both sets using InceptionV3
- Compute Fréchet distance between the two Gaussian distributions
- Lower FID = better (generated images are closer to real images)
# FID requires a reference dataset of "real" images
# Compare: 1000 generated images vs 1000 real images
# Using pytorch-fid: https://github.com/mseitzer/pytorch-fid
# Command line:
# python -m pytorch_fid path/to/generated path/to/real
# Programmatic:
from pytorch_fid.fid_score import calculate_fid_given_paths
fid_score = calculate_fid_given_paths(
paths=["generated_images/", "real_images/"],
batch_size=50,
device="cuda",
dims=2048, # InceptionV3 feature dimension
)
print(f"FID: {fid_score:.2f}") # Lower is better
FID Interpretation
| FID Score | Quality | Interpretation |
|---|
| < 10 | Excellent | Generated ≈ real |
| 10-30 | Good | High quality, minor artifacts |
| 30-50 | Fair | Noticeable artifacts |
| 50-100 | Poor | Significant quality issues |
| > 100 | Bad | Clearly synthetic |
FID Limitations
FID measures distribution similarity, NOT individual image quality. A model with low FID can still produce bad individual images. FID also requires a reference dataset of "real" images, which may not always be available. Use FID for model comparison, not per-image quality gates.
CLIPScore: text-image alignment
What It Measures
CLIPScore measures how well an image matches its text prompt:
- Encode image and text using CLIP model
- Compute cosine similarity between embeddings
- Higher = better (0-1 scale, typically 0.2-0.4)
import torch
import clip
from PIL import Image
# Load CLIP model
model, preprocess = clip.load("ViT-B/32", device="cuda")
def compute_clip_score(image_path: str, prompt: str) -> float:
"""Compute CLIPScore for an image-prompt pair."""
image = preprocess(Image.open(image_path)).unsqueeze(0).to("cuda")
text = clip.tokenize([prompt]).to("cuda")
with torch.no_grad():
image_features = model.encode_image(image)
text_features = model.encode_text(text)
# Cosine similarity
similarity = torch.cosine_similarity(
image_features, text_features
).item()
# CLIPScore = 100 * max(cosine_similarity, 0) (standard scaling)
clip_score = 100 * max(similarity, 0)
return clip_score
score = compute_clip_score("generated.png", "a mountain landscape at sunset")
print(f"CLIPScore: {score:.2f}") # e.g., 31.45 (higher is better)
CLIPScore Interpretation
| CLIPScore | Alignment | Interpretation |
|---|
| > 35 | Excellent | Image closely matches prompt |
| 30-35 | Good | Clear alignment with prompt |
| 25-30 | Fair | Partial alignment |
| 20-25 | Poor | Weak alignment |
| < 20 | Bad | Image doesn't match prompt |
What does CLIPScore measure and how is it different from FID?
CLIPScore and FID measure different things: CLIPScore = text-image alignment (per-image). It encodes the image and prompt using CLIP, computes cosine similarity. High score = image matches prompt. FID = distribution quality (dataset-level). It extracts InceptionV3 features from generated and real images, computes Fréchet distance. Low FID = generated distribution matches real distribution. Use CLIPScore for: "does this image match the prompt?" Use FID for: "is this model producing realistic images overall?"
Aesthetic score (LAION)
What It Measures
Aesthetic Score predicts human visual appeal (1-10 scale):
- Trained on LAION human ratings
- Uses CLIP embeddings + linear regression head
- Higher = more aesthetically pleasing
# LAION Aesthetic Predictor: https://github.com/LAION-AI/aesthetic-predictor
import torch
import clip
from PIL import Image
# Load aesthetic predictor model
aesthetic_model = torch.load("aesthetic_predictor.pth").to("cuda")
model, preprocess = clip.load("ViT-L/14", device="cuda")
def compute_aesthetic_score(image_path: str) -> float:
"""Compute aesthetic score (1-10) for an image."""
image = preprocess(Image.open(image_path)).unsqueeze(0).to("cuda")
with torch.no_grad():
image_features = model.encode_image(image)
# Normalize features
image_features = image_features / image_features.norm(dim=-1, keepdim=True)
# Predict aesthetic score
score = aesthetic_model(image_features).item()
return score # 1-10 scale
score = compute_aesthetic_score("generated.png")
print(f"Aesthetic Score: {score:.2f}/10") # e.g., 7.82
Aesthetic Score Interpretation
| Score | Quality | Use Case |
|---|
| 8-10 | Excellent | Hero images, final delivery |
| 6-8 | Good | Production-ready |
| 4-6 | Fair | Preview, draft |
| < 4 | Poor | Reject, regenerate |
ImageReward
What It Measures
ImageReward predicts human preference for generated images:
- Trained on 137K human comparisons
- Combines prompt alignment + aesthetic quality + artifact detection
- Higher = better (typically -1 to 2 range)
# ImageReward: https://github.com/THUDM/ImageReward
import ImageReward
# Load model
rm = ImageReward.load("ImageReward-v1.0")
def compute_image_reward(prompt: str, image_path: str) -> float:
"""Compute ImageReward score."""
score = rm.score(prompt, image_path)
return score
score = compute_image_reward("a mountain landscape", "generated.png")
print(f"ImageReward: {score:.3f}") # e.g., 1.234
Multi-metric quality evaluator
from dataclasses import dataclass
@dataclass
class QualityReport:
"""Multi-metric quality report for a generated image."""
clip_score: float
aesthetic_score: float
image_reward: float
passed: bool # All thresholds met
class QualityEvaluator:
"""Evaluate generated images across multiple metrics."""
def __init__(self, thresholds: dict = None):
self.thresholds = thresholds or {
"clip_score": 25.0, # Minimum CLIPScore
"aesthetic_score": 6.0, # Minimum aesthetic (1-10)
"image_reward": 0.0, # Minimum ImageReward
}
def evaluate(self, image_path: str, prompt: str) -> QualityReport:
"""Run all quality metrics."""
clip_s = compute_clip_score(image_path, prompt)
aesthetic = compute_aesthetic_score(image_path)
reward = compute_image_reward(prompt, image_path)
passed = (
clip_s >= self.thresholds["clip_score"] and
aesthetic >= self.thresholds["aesthetic_score"] and
reward >= self.thresholds["image_reward"]
)
return QualityReport(
clip_score=clip_s,
aesthetic_score=aesthetic,
image_reward=reward,
passed=passed,
)
Metric comparison
| Metric | What It Measures | Scale | Per-Image | Requires Reference | Best For |
|---|
| FID | Distribution quality | 0-∞ (lower=better) | No (dataset) | Yes (real images) | Model comparison |
| CLIPScore | Prompt alignment | 0-100 (higher=better) | Yes | No (just prompt) | Per-image QA |
| Aesthetic | Visual appeal | 1-10 (higher=better) | Yes | No | Quality gate |
| ImageReward | Human preference | -1 to 2 (higher=better) | Yes | No (just prompt) | Production QA |