Skip to content
Quantoros

What is classifier-free guidance (CFG) in image generation?

Computer VisionLevel: IntermediateGenerative Models

What is classifier-free guidance (CFG) in image generation?

Hints
  • Identify the prediction unit: image, object, pixel or sequence.
  • How do occlusion, lighting or domain changes affect results and evaluation?

Answer

CFG controls how strongly the generated image adheres to the text prompt vs unconstrained quality:

Training: randomly drop the conditioning (text prompt) with probability p. Model learns both conditional and unconditional generation.

Inference:

noise_pred = unconditional_pred + guidance_scale × (conditional_pred - unconditional_pred)
  • guidance_scale = 1: no guidance, creative but may ignore prompt
  • guidance_scale = 7-12: good balance (typical default)
  • guidance_scale > 15: strictly follows prompt but may produce artifacts

Intuition: the difference between conditional and unconditional predictions represents what's "prompt-specific." Amplifying that difference makes the image more prompt-adherent.

Source and licence: JustInCache & contributors — Awesome AI Interviews · Apache-2.0

Related questions