Know these Important Parameters for stunning AI images

43,064 views
Updated Categorized as Tutorial Tagged , 8 Comments on Know these Important Parameters for stunning AI images

So you have generated a few Stable Diffusion AI images. They looked great but not quite what you want? You can use some customization. Here’s a primer for the basic generation parameters.

Stable Diffusion Software

We will focus on Stable Diffusion AI. While some parameters mentioned in this article are available in free online AI generators, all of them are available in this popular Stable Diffusion GUI (AUTOMATIC1111). See my quick start guide for setting up in Google Colab.

CFG Scale

Classifier Free Guidance scale is a parameter to control how much the model should respect your prompt.

1 – Mostly ignore your prompt.
3 – Be more creative.
7 – A good balance between following the prompt and freedom.
15 – Adhere more to prompt.
30 – Strictly follow the prompt.

Below are a few examples of increasing the CFG scale with the same random seed. In general, you should stay away from the two extremes – 1 and 30.

Recommendation: Starts with 7. Increase if you want it to follow your prompt more.

Stable Diffusion CFG scale parameters
Higher CFG scale adheres more to the prompt.

Sampling steps

Quality improves as the sampling step increases. Typically, 20 steps with the Euler sampler is enough to reach a high-quality, sharp image. Although the image will change subtly when stepping through to higher values, it will become different but not necessarily of higher quality.

Recommendation: 20-30 steps. Adjust to higher if you suspect quality is low.

Stable Diffusion sampling step size.
Increasing sampling steps.

Sampling methods

There’s a variety of sampling methods you can choose, depending on what GUI you are using. They are simply different methods for solving diffusion equations. They are supposed to give the same result but could be slightly different due to numerical bias. But since there’s no right answer here – the only criterion is the image looks good, the accuracy of the method should not be your concern.

Not all methods are created equal. Below are the processing times of various methods.

Rendering time for 20 steps.

Below are images produced after 20 steps with different sampling methods. Many of them are similar, but some of them can be quite different.

There are discussions in the online community claiming that certain sampling methods tend to yield particular styles. This is without theoretical merit.

My starting point is 20 steps of DPM++ 2M Karras.

Recommendation: DPM++ 2M Karras

Seed

Seed dialog box

The random seed determines the initial noise pattern and, hence, the final image.

Setting it to -1 means using a random one every time. It is useful when you want to generate new images. On the other hand, fixing it would result in the same images in each new generation.

How do you find the seed used for an image if you use a random seed? In the dialog box, you should see something like:

Steps: 20, Sampler: Euler a, CFG scale: 7, Seed: 4239744034, Size: 512×512, Model hash: 7460a6fa

Copy this seed value to the seed input box. If you generate more than one image at a time, the seed value of the second image is incremented by 1, and so on. Alternatively, click the recycle button to reuse the seed from the last generation.

Recommendation: Set to -1 to explore. Fix to a value for fine-tuning.

Image size

The size of the output image. Since Stable Diffusion v1 is trained with 512×512 images, deviating from it too much could cause issues such as duplicating objects. Leave it as square whenever possible. 512×768 (portrait) or 768×512 (landscape) are still okay.

Recommendation: Set the image size as 512×512. Otherwise, 512×768 or 768×512. (For v1 models)

Batch size

Batch size is the number of images generated each time. Since the final images are very dependent on the random seed, it is always a good idea to generate a few images at a time. This way, you can get a good sense of what the current prompt can do.

Recommendation: Set batch size to 4 or 8.

Summary

In this article, we have covered the basic parameters for Stable Diffusion AI. Check out this article for a step-by-step guide to building high-quality prompts. Check out this article for more advanced prompting techniques.

Avatar

By Andrew

Andrew is an experienced engineer with a specialization in Machine Learning and Artificial Intelligence. He is passionate about programming, art, photography, and education. He has a Ph.D. in engineering.

8 comments

  1. Thank you Andrew, you have wonderful articles, very clear lessons. And thank you for sharing your knowledge with others, it is worthy of respect.

  2. Great article!
    Could you please also explain the “Batch count” slider and the “Tiling” and “Hires.fix” check boxes?
    Many Thanks!

Leave a comment

Your email address will not be published. Required fields are marked *