Stable Diffusion Advanced Tutorial – How to use Stable Diffusion?

Original link: https://www.dongwm.com/post/how-to-use-stable-diffusion/

foreword

Today’s article introduces how to run SD, including online use and local running stable-diffusion-webui, and experience the effect.

Civitai platform

First of all, I want to introduce a platform: Civitai is currently the most well-known community platform for Stable Diffusion AI art models. Users call it Station C. There are many models uploaded by users in it:

In addition, you can filter by pictures, and high-quality pictures uploaded by relevant users will be listed in the model. The picture page has parameters such as relevant prompt text, model used, and sampling data, which can help users who are not familiar with Stable Diffusion get started quickly:

PS: If you choose Everything Browing mode , there will be surprises, please do a good job of psychological construction~

Using Stable Diffusion Online

If you just want to try it out, the easiest way is to visit the official website of Stable Diffusion https://beta.dreamstudio.ai/ online, you can generate about a hundred images for free, and then you need to pay a small fee.

In fact, there are some other online services, but they are all castrated versions (for example, do not support model selection, do not support plug-ins, etc.), which cannot reflect the true capabilities of Stable Diffusion, so they are not recommended. Just look for the official ones.

Deploy Stable Diffusion Locally

This is the way I mainly recommend, and it is also the most interesting place to play Stable Diffusion. Currently the most mainstream method is to use the https://github.com/AUTOMATIC1111/stable-diffusion-webui project to run a Python Web UI locally.

First of all, it must be clear that AI painting requires a lot of image processing and calculation, so there are hardware requirements for computers:

Local operation requires a large enough video memory (the memory of an independent graphics card). The minimum configuration is 10GB of video memory, the bigger the better. The memory should not be too small, preferably greater than 16GB. The size of the video memory determines the size of the picture you can generate. Generally speaking, the larger the picture size, the more SD can play, and the more details will be filled in the picture.
SD is usually run through the GPU, because the GPU will accelerate the calculation. But it is also possible to run with the CPU, but the speed will be very slow: for example, a graphics card can calculate a good image in 30 seconds, and the CPU takes 10 minutes to calculate.

My computer is a Macbook M1 architecture, so I can refer to the official wiki document Installation on Apple Silicon to configure it. After a brief look at the startup script, even if I am not a Python developer, I think the startup process can be completed smoothly. Next is the process of my configuration:

First download related dependencies and stable-diffusion-webui:

 ➜ brew install cmake protobuf rust [email protected] git wget  
➜ cd ~/workspace  
➜ git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui  

At present, the code is only cloned, and there is no available model. At this time, you can download the model from the Hugging Face mentioned in the document or the C station Civitai.com .

The model format is generally .ckpt or .safetensors as the file extension. The format difference is:

.ckpt : A compressed file containing Python code, which is very common and convenient for Python language programs. The disadvantage is that the file is very large, generally 2-8G. .safetensors : Contains only the data required for generation, not the code, generally only tens to hundreds of M, and it is safer and faster to load files.

I usually download from station C, and found an example: https://civitai.com/models/25995/blindbox

Note that this is a Lora model (the Type in the information on the right is LORA), so it should be placed in models/Lora instead of the models/Stable-diffusion directory as stated in the document.

 mv ~/Downloads/blindbox_V1Mix.safetensors ~/workspace/stable-diffusion-webui/models/Lora  

Then I pulled down to the page, and I found a generated rendering https://civitai.com/images/421118?period=AllTime&sort=Most+Reactions&modelVersionId=32988&modelId=25995&postId=128086

You can see the various parameters used to generate this graph. Note that the Model in it is called `revAnimated_v11・, and there is no need to download it locally. You can find it by searching first: https://civitai.com/models/7371/rev-animated

You can see that the Type on the right indicates that it is a CHECKPOINT type, download it and put it in models/Stable-diffusion directory:

 mv ~/Downloads/revAnimated_v122.safetensors ~/workspace/stable-diffusion-webui/models/Stable-diffusion  

Let me mention the model type of Checkpoint here. According to my understanding, it means an archive point , that is, a point in different versions of the open source Stable-diffusion can be used as a model. In addition, this model subtype is called Checkpoint Merge , that is, it mixes multiple models together, and different models account for different proportions of weights after merging.

Then start the webUI:

 cd stable-diffusion-webui  
./webui.sh  

The first startup will download the relevant dependencies, which is relatively slow. After the download is complete, you will see the startup prompt:

 ...  
Running on local URL: http://127.0.0.1:7860  

Open the browser and visit this address to see the Web page. SD currently supports two modes of Vincent graph and graph-generated graph. This article will first experience the Vincent graph.

Text to image (txt2img)

This is the most basic function of SD, converting text prompts into images. Still use the blindbox example mentioned above, just use its various parameters, the only thing to mention is that “Batch size” is selected as 8, which is to generate 8 images at a time (the fact is 9 images, and the other image is all Thumbnail of the picture), then click “Generate” on the right, and the generation will start, about 10 minutes (if a single picture is about 1 minute):

The generated effect is very good. First introduce the parameters and uses of each parameter:

  1. “Stable Diffusion checkpoint” on the top left is a drop-down box, you can choose the model you want. There are many pre-trained models to choose from, and if you have your own special needs, you can also train your own model.
  2. There are 2 text input boxes on the left side, the upper wide one enters the positive prompt text (prompt) text, indicating what requirements you want the picture to meet, the lower narrow one enters the negative prompt word (Negative Prompt) text, indicating that the picture does not Hope to meet the requirements. Prompt words can be English phrases or words separated by commas, which are similar to a list of tags.
  3. Sampling Me…

Original: Stable Diffusion Advanced Tutorial – How to use Stable Diffusion?

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