What's Stable Diffusion CFG Scale Meaning?How to Use It?

novita.ai API

In Stable Diffusion, the acronym CFG represents Classifier Free Guidance scale, which plays a crucial role in controlling the adherence of Stable Diffusion to your text prompt. CFG is utilized in both text-to-image (txt2img) and image-to-image (img2img) generations.

The CFG value determines the extent to which Stable Diffusion follows your prompt, and theoretically, a higher value implies stricter adherence. By default, the value is set to 7, striking a balance between creative freedom and prompt guidance. If set to 1, Stable Diffusion enjoys almost complete freedom, while values above 15 impose significant restrictions.

While using the Stable Diffusion Web UI, CFG is limited to positive numbers ranging from 1 to 30. However, when utilizing Stable Diffusion via a Terminal, CFG can be set as high as 999 and can even take negative values. A negative CFG indicates the desire for Stable Diffusion to generate content opposite to your text prompt. Nonetheless, this practice is uncommon as negative prompts tend to yield more predictable results that align with your intentions.

Unveiling Stable Diffusion

Stable diffusion is a concept in the field of image processing and computer graphics that refers to the process of spreading or dispersing pixel values across an image. This technique is often used to create a variety of effects, such as blurring, sharpening, and edge detection. The process is governed by a set of parameters, one of which is the CFG scale.

novita.ai API

An Experiment to Understand CFG Scale Functionality

The CFG scale, or Configuration scale, is a parameter that controls the intensity of the diffusion process. It determines how much the pixel values are spread or dispersed. To understand its functionality, let's consider an experiment.

Suppose we have an image and we apply stable diffusion with a low CFG scale value. The result would be a slightly blurred image as the pixel values are only mildly dispersed. Now, if we increase the CFG scale value and apply stable diffusion again, the image would be more blurred as the pixel values are dispersed more intensely.

How CFG Effects the Quality of Output Images

The CFG scale plays a crucial role in determining the quality of the output images in stable diffusion. A lower CFG scale value can preserve more details but might not achieve the desired diffusion effect. On the other hand, a higher CFG scale value can create a strong diffusion effect but might result in loss of image details. Therefore, finding the right balance is key to achieving high-quality output images.

When to Adjust the CFG Scale in Stable Diffusion

Adjusting the CFG scale in stable diffusion depends on the desired outcome. If the goal is to create a subtle diffusion effect, a lower CFG scale value would be appropriate. Conversely, if the aim is to create a strong diffusion effect, a higher CFG scale value would be needed. It's also important to consider the quality of the original image. High-quality images with a lot of details might require a different CFG scale value compared to low-quality images.

novita.ai API

What is the Best CFG Scale for Stable Diffusion

The best CFG scale for stable diffusion can vary depending on the specific requirements of the project. However, it's generally recommended to start with a moderate CFG scale value and adjust it as needed based on the results. Experimentation is key to finding the optimal CFG scale value for each project.

Conclusion

In conclusion, the CFG scale is a vital parameter in stable diffusion that controls the intensity of the diffusion process. Understanding how to adjust the CFG scale based on the desired outcome and the quality of the original image can significantly improve the results of stable diffusion. As with many things in image processing and computer graphics, finding the optimal CFG scale value often involves a process of trial and error and depends on the specific requirements of each project.

I hope you have a good experience. If you have any other questions, feel free to reach out to me on Discordopen in new window.

novita.aiopen in new window provides Stable Diffusion API and hundreds of fast and cheapest AI image generation APIs for 10,000 models.🎯 Fastest generation in just 2s, Pay-As-You-Go, a minimum of $0.0015 for each standard image, you can add your own models and avoid GPU maintenance. Free to share open-source extensions.