Stable Diffusion - Environment configuration for Stable Diffusion WebUI image generation tool

Welcome to my CSDN: https://spike.blog.csdn.net/
This article address: https://spike.blog.csdn.net/article/details/131528224

AIGC

Stable Diffusion WebUI is an image generation tool based on deep learning. It generates high-quality new images based on user input text or images. The features are as follows:

  • Supports a variety of image generation tasks, such as face generation, style transfer, image inpainting, image super-resolution, etc.
  • Using the stable diffusion model (Stable Diffusion Model) as the core algorithm of image generation, this model has the advantages of high efficiency, stability and controllability.
  • Provides a friendly web interface that users can access and use through a browser without installing any software or plug-ins.
  • Support custom parameters and models, users can adjust the effect and style of image generation according to their own needs and preferences.

Stable Diffusion WebUI is an image generation tool suitable for all kinds of users. Whether you are a professional designer, artist, photographer, or ordinary enthusiast or learner, you can use your creativity and imagination here to generate the image you want.

Run the WebUI environment:

source venv/bin/activate
python launch.py --port 9301 --listen --xformers
nohup python -u launch.py --port 9301 --listen --xformers > nohup.sd.out &

Web version:

  • GitHub:https://github.com/AUTOMATIC1111/stable-diffusion-webui
  • Installation document: https://stable-diffusion-book.vercel.app/install/WebUi/launch/

1. Environment configuration

Download the project (about 23118 project files, the download speed is slow):

git clone [email protected]:AUTOMATIC1111/stable-diffusion-webui.git

Automatically configure the environment (more Python environments need to be installed, and the download speed is slower):

cd stable-diffusion-webui
bash webui.sh  # 自动安装环境

The log is as follows:

################################################################
Install script for stable-diffusion + Web UI
Tested on Debian 11 (Bullseye)
################################################################

################################################################
Running on chenlong user
################################################################

################################################################
Repo already cloned, using it as install directory
################################################################

################################################################
Create and activate python venv
################################################################

The default configured Python environment is located at: stable-diffusion-webui/venv/bin/activate, that is, using a virtual environment virtualenv, namely:

conda deactivate   # 取消 conda
source venv/bin/activate  # 激活

If you encounter a PyTorch GPU error, just reinstall PyTorch.

Encountered a problem, in the virtual environment, manually install some packages, pay attention to resolve the version conflict of the Python package:

pip install einops==0.3.0 kornia==0.6 omegaconf==2.1.1 pytorch-lightning==1.4.2 torchmetrics==0.6.0 transformers==4.26.1 torch==2.0.1 torchvision==0.15.2 google-auth==2.22.0rc1 urllib3==1.26.16

pip install facexlib==0.3.0 tb-nightly==2.14.0a20230702 sdkit==1.0.112 opencv-python==4.6.0.66 -i https://mirrors.aliyun.com/pypi/simple

# 需要安装
# pip install git+https://ghproxy.com/https://github.com/mlfoundations/open_clip.git --prefer-binary
pip install open-clip-torch==2.0.2 deepspeed==0.9.5
pip install opencv-python-headless==4.8.0.74 opencv-python==4.8.0.74

The default configured project environment is located at: stable-diffusion-webui/repositories, manually download dependent projects:

cd repositories/
git clone https://ghproxy.com/https://github.com/Stability-AI/stablediffusion.git stable-diffusion-stability-ai
git clone https://ghproxy.com/https://github.com/crowsonkb/k-diffusion.git/ k-diffusion
git clone https://ghproxy.com/https://github.com/sczhou/CodeFormer.git
git clone https://ghproxy.com/https://github.com/salesforce/BLIP.git
git clone https://ghproxy.com/https://github.com/CompVis/taming-transformers

Final 5 folders:

BLIP/
CodeFormer/
k-diffusion/
stable-diffusion-stability-ai/
taming-transformers/

Run the WebUI environment:

conda deactivate
source venv/bin/activate
python launch.py --port 9301 --xformers

Started successfully:

UI

Bug1: 遇到Bug “AttributeError: module ‘open_clip’ has no attribute ‘transformer’”

To install from source open_clip, you can:

pip install git+https://github.com/mlfoundations/open_clip.git --prefer-binary

**Bug2: 遇到Bug “FileNotFoundError: No checkpoints found. When searching for checkpoints for Stable-diffusion” **

The Stable-diffusion model has not been downloaded, namely:

FileNotFoundError: No checkpoints found. When searching for checkpoints, looked at:
 - file /nfs/chenlong/stable_diffusion/stable-diffusion-webui/model.ckpt
 - directory /nfs/chenlong/stable_diffusion/stable-diffusion-webui/models/Stable-diffusion
 Can't run without a checkpoint. Find and place a .ckpt or .safetensors file into any of those locations.

Download manually, about 4G

cd models/Stable-diffusion
wget https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors

Bug3: 遇到Bug “No module ‘xformers’. Proceeding without it.”

Xformers has been installed, it is not a bug, because there is no startup command parameter, just launch.pyadd --xformersthe parameter:

python launch.py --port 9301 --listen --xformers

Bug4: Encountered Bug “Cannot locate TCMalloc”

The installation package is missing google-perftools, just install it.

sudo apt install --no-install-recommends google-perftools

Bug5: EncounteredRuntimeError: Torch is not able to use GPU; add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check

The reason is that the installation of PyTorch is abnormal. In Python, import torchwhen calling , an exception also occurs:
ImportError: cannot import name '_get_cpp_backtrace' from 'torch._C'.

Just reinstall PyTorch, that is, first check and uninstall PyTorch, and then install:

pip list | grep torch
pip uninstall torch torchvision
pip install torch==2.0.1 torchvision==0.15.2

Test the command to make sure PyTorch is working correctly:

import torch
print(torch.__version__)  # 2.0.1+cu117
import torchvision
print(torchvision.__version__)  # 0.15.2+cu117

You can also use the following command to verify:

python -c "import torchvision; print(torchvision.__version__)"
python -c "import torch; print(torch.__version__)"

Bug6: EncounteredAttributeError: partially initialized module 'cv2' has no attribute '_registerMatType'

参考:AttributeError: partially initialized module ‘cv2’ has no attribute ‘_registerMatType’ (most likely due to a circular import)

pip install opencv-python-headless==4.8.0.74 opencv-python==4.8.0.74

2. Test Engineering

The first input is forward prompts, and the second input is reverse prompts.

Forward Prompts:

A girl,walking in the forest,the sun fell on her body,(masterpiece:1,2),best quality,masterpiece,highres,original,extremely detailed wallpaper,perfect lighting,(extremely detailed CG:1.2),drawing,paintbrush,

Reverse Prompts:

NSFW,(worst quality:2),(low quality:2),(normal quality:2),lowres,normal quality,((monochrome)),((grayscale)),skin spots,acnes,skin blemishes,age spot,(ugly:1.331),(duplicate:1.331),(morbid:1.21),(mutilated:1.21),(tranny:1.331),mutated hands,(poorly drawn hands:1.5),blurry,(bad anatomy:1.21),(bad proportions:1.331),extra limbs,(disfigured:1.331),(missing arms:1.331),(extra legs:1.331),(fused fingers:1.61051),(too many dingers:1.61051),(unclear eyes:1.331),lowers,bad hands,missing fingers,extra digit,bad hands,missing fingers,(((extra arms and legs)))

Restore faces (face repair) need to download the model:

Downloading: "https://github.com/xinntao/facexlib/releases/download/v0.1.0/detection_Resnet50_Final.pth" to stable-diffusion-webui/repositories/CodeFormer/weights/facelib/detection_Resnet50_Final.pth

# 下载失败,手动下载
cd repositories/CodeFormer/weights/facelib/
wget https://github.com/xinntao/facexlib/releases/download/v0.1.0/detection_Resnet50_Final.pth

The configuration information is as follows: Sampling method, Restore faces, CFG Scale

Config

Close-up Prompts

look at viewer,close up,upper body

reference:

Guess you like

Origin blog.csdn.net/u012515223/article/details/131528224