Stable Diffusion Advanced Tutorial – Script

Original link: https://www.dongwm.com/post/stable-diffusion-script/

foreword

This section mainly introduces the script function provided by stable-diffusion-webui. Like the extension, the script is also independent. The script mainly involves the logic of generating images, not the generation algorithm. It is similar to the use of decorators in the Python language. You can adjust prompt words, parameter values, etc. according to the rules before generating images. Insert more operations for each step performed.

The difference between scripts and extensions

According to my understanding, the extension is to expand the stable-diffusion-webui UI interface, so it will involve front-end static files (such as javascript, CSS, etc.), so it will add a Tab on the Web UI page.

The script, like its name, is a Python script that implements a certain function. It is light and simple. When writing code, you need to inherit the base class of scripts.Script and write the corresponding logic according to the corresponding method.

script list

The project’s wiki has a dedicated page: https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Custom-Scripts

All current extensions are listed here, but I haven’t used them yet. At present, only some of the official projects are used:

 ls ~/workspace/stable-diffusion-webui/scripts  
poor_mans_outpainting.py prompts_from_file.py prompt_matrix.py  
custom_code.py postprocessing_codeformer.py sd_upscale.py  
img2imgalt.py postprocessing_gfpgan.py xyz_grid.py  
loopback.py postprocessing_upscale.py  
outpainting_mk_2.py  

Some of these scripts can be used in both txt2img and img2img modes, and some can only be used in img2img mode, please note.

Next, I will focus on a few commonly used scripts. Others are welcome to supplement their usage and usage.

Prompt matrix

As its name suggests, generate image matrix according to different prompt words. We used to write prompt words, which were some tags separated by commas. But if you want to understand or are not sure about the combined effect of several prompt words, then you may have to generate them multiple times, which is inefficient and inconvenient.

After enabling this script, you can use | syntax to split words, which will form multiple prompt word combinations so that you can see the effect at one time:

You can see the last two prompts on the front, using headphones|,<lora:blindbox_v1_mix:1>| <lora:iu_V35:1> , so that a matrix can be generated to see the two lora models and whether they are The effect of wearing headphones:

In the picture, you can戴耳机用blindbox ,戴耳机用iu ,不戴耳机用blindbox , and不戴耳机用iu . Btw, you can see that changing Lora will make a huge difference~

X/Y/Z plot

Whether you are a beginner or a user with some experience in using SD, you are often not sure which value of each parameter is the most suitable for your needs. According to the past mode, you can only modify the parameters, then generate a graph and save it, modify the parameters and then generate picture. Keep looping and finally try out the best value. But this process is very long and tedious, and this X/Y/Z plot script can quickly let us understand the meaning and effect of these function parameters. Next, we generate a matrix diagram by adjusting each parameter, which is very convenient to compare the effect of the parameters.

First look at the selection of the page (prompt words, etc. still use a picture produced before, and add an additional negative nsfw , that is, not safe from work , in addition, I specified a seed for easy comparison):

In this example, I have chosen the three dimensions of x/y/z, which are:

  1. Sampler, click the yellow icon on the right to list all sampling schemes, I only list some of them here
  2. CFG scale. 5-15 (+3) means that within the range of 5-12, the value is increased by + 3, that is, 4 values ​​of 5,8,11,14 14.
  3. Steps. 20-35 [3] is another way of expression, which is to find 3 values ​​from the range of 20-35, that is, the 3 values ​​of 20,27,35 .

Note that the larger the range you choose, the more time-consuming it will be (this is a multiplicative relationship). For example, there are more than 20 kinds of samplers, but I only chose 3 kinds. In this way, you can understand the effects of different parameter values ​​in a small range. Here is an extreme example (it took about 1 hour to complete the generation). If you have more experience, you will gradually know what values ​​​​of different parameters will be better. Reasonable.

The graph of its result is very large. I cut the whole graph and cut the subgraph with step 27:

In addition, it is not necessary to select all three axes. You can only select 2 or even 1 indicator, and then generate the impact on the graph when the parameter value changes, but pay attention to the need to fix the seed.

script installation

There are currently three ways to install the script, there is no recommendation bias, just according to personal habits.

Manually copy files

The first is to directly copy the scripts in the project to the scripts directory, for example https://github.com/memes-forever/Stable-diffusion-webui-video

It can be like this:

“`bash
wget https://raw.githubusercontent.com/memes-forever/Stable-diffusion-webui-video/main/videos.py -O ~/workspace/stable-diffusion-webui/scripts/vid…

Original: Stable Diffusion Advanced Tutorial – Script

This article is transferred from: https://www.dongwm.com/post/stable-diffusion-script/
This site is only for collection, and the copyright belongs to the original author.