🤔 What is CFG

---
title: "Use CFG in Stable Diffusion"
description: "What CFG can do?"
author: "Simin LIU"
date: "5/1/2024"
categories:
    - Stable Diffusion
    - Diffusion models
---

CFG is a function that is ‘Classifier Free Guidance scale’. Frankly, it controls how relevant the image to your prompts. If CFG is very low, AI can be more free to draw the image.

🎨 Let’s Try different ranges of CFG!

Prompts:

half-body, realistic, RAW photo, masterpiece, best quality, 8K, insane details, intricate details, hyper-detailed, intricate details, hyper quality, dynamic angle, (centered, 1.3), advanced lighting, master lighting, film grain, front view, (1 black cat, 1.2), yellow eyes, cowboy hat, (cyborg, Mech Suit, 1.1), mechanical ears, simple background, desert, night,

Negative Prompts:

people,nsfw,paintings,cartoon,anime,sketches,worst quality,low quality,normal quality,lowres,watermark,monochrome,grayscale,ugly,blurry,

This is what we get in CFG Scale:3.0

This is what we get in CFG Scale:5.0

This is what we get in CFG Scale:7.0

This is what we get in CFG Scale:10.0

This is what we get in CFG Scale:15.0

This is what we get in CFG Scale:20.0

As the number of the CFG increases, the model’s output demonstrates a greater adherence to the given prompt.

In our example, we observe a noticeable shift towards desert-related content, with a closer adherence to the given prompt.

This suggests that the model’s expanded capacity allows it to better understand and integrate the thematic elements provided in the prompt, resulting in more contextually relevant output.

😯 So? The Higher CFG the Better?

No.

The increase in CFG doesn’t necessarily mean the image can become better. A higher CFG will make the image contrast too high.

Moreover, different models have their own better CFGs suitable for them.

Usually CFG Scale is from 7 to 10 with detailed prompts.