Install Stable Diffusion WebUI on Ubuntu 22.04.2 LTS

1. Environment

  • OS:Ubuntu 22.04 LTS
  • Kernel:5.15.0-60-generic
  • CPU: Intel(R) Xeon(R) Gold 6278C CPU @ 2.60GHz, 8vCPUs
  • GPU: 1 * NVIDIA V100-PCIe-32G
  • RAM: 64GB
  • system disk:512 GiB
  • data disk: 2048 GiB
  • Stable Diffusion WebUI version:0cc0ee1 (2023/2/20)

2. Download Stable Diffusion models

Go to HuggingFace or Civitai to find a model.

Use wget command to download the model

bash 复制代码
wget https://huggingface.co/andite/anything-v4.0/blob/main/anything-v4.5-pruned.ckpt

Here are some good models for your reference.

2.1. Realistic style models

Stable Diffusion, the original model published by CompVis and StabilityAI.

Chilloutmix

Deliberate

2.2. Anime style models

I would suggest you to start from "Anything" model if you want to draw anime artworks.

Anything

Waifu Diffusion

Hentai Diffusion

DreamShaper

OrangeMix3

3. Install Stable Diffusion WebUI

3.1. Install dependencies

1.Install proprietary Nvidia drivers in order to use CUDA. Then reboot.

复制代码
sudo apt update
sudo apt purge *nvidia*
# List available drivers for your GPU
ubuntu-drivers list
sudo apt install nvidia-driver-525

2.Follow the instructions on Nvidia Developers to install CUDA. Reboot again.

复制代码
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin
sudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/12.1.0/local_installers/cuda-repo-ubuntu2204-12-1-local_12.1.0-530.30.02-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2204-12-1-local_12.1.0-530.30.02-1_amd64.deb
sudo cp /var/cuda-repo-ubuntu2204-12-1-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda

3.Verify the installation

|---------------------------|
| nvidia-smi nvcc --version |

4.Install Python, wget, git

|------------------------------------------------------------------|
| sudo apt install python3 python3-pip python3-virtualenv wget git |

5.Because we need a Pyhon 3.6 enviroment for SD WebUi, we have to install Anaconda

|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| wgt https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh chmod +x Miniconda3-latest-Linux-x86_64.sh bash Miniconda3-latest-Linux-x86_64.sh # Confirm everything and install it |

6.Create a virtual environment of Python 3.10.6

|-------------------------------------------|
| conda create --name sdwebui python=3.10.6 |

3.2. Clone Stable Diffusion WebUI repository

1.Clone the repository of Stable Diffusion WebUI

|----------------------------------------------------------------------------|
| cd ~ git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git |

2.Move .ckpt models to stable-diffusion-webui

|-----------------------------------------------------------------------------------|
| mv ~/anything-v4.5-pruned.ckpt ~/stable-diffusion-webui/models/Stable-diffusion/ |

3.Enter the virtual enviroment

|------------------------|
| conda activate sdwebui |

4.If you want to activate virtual environment in a bash script, add these on the top of webui-user.sh

|--------------------------------------------------------|
| eval "$(conda shell.bash hook)" conda activate sdwebui |

3.3. Setup commandline arguments

According to Wiki,we have to change some commdanline arguments in order to start SD WebUI.

Edit webui-user.sh

|-------------------|
| vim webui-user.sh |

If the VRAM of GPU is lower than 4GB, add: COMMANDLINE_ARGS=--medvram --opt-split-attention

If your PC has RAM lower than 8GB, add: COMMANDLINE_ARGS=--lowvram --opt-split-attention

You could also add --listen so you can access the WebUI from other PC on the same network. Or add --share to generate a public Gradio link for accessing WebUI while deploying SD WebUI to servers.

3.4. Launch Stable Diffusion WebUI

1.Run webui.sh, it will install all the dependencies. Then a link should pop up: http://127.0.0.1:7860

|------------|
| ./webui.sh |

2.To access WebUI from other PC on the same network,enter http://<IP of the PC>:7860 in the address bar of your browser. Don't forget to open firewall port

|-----------------------------------------|
| sudo ufw allow 7860/tcp sudo ufw reload |

3.5. How to update Stable Diffusion WebUI

1.Get current branch

|----------------------------|
| git rev-parse --short HEAD |

2.Pull latest files

|----------|
| git pull |

3.If something is broken after updating, roll back to the previous branch

|-----------------------|
| git checkout "branch" |

4. How to use Stable Diffusion WebUI

4.1. Prompts

Use "Prompts" and "Ngative Prompts" to tell AI what to draw.

See Vodly Artist name and Danbooru tags for choosing prompts.

For example, to draw Jeanne from Fate/Grand Order, we type the name of the character and characteristics of her body in the prompt fields.

|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| jeanne d'arc from fate grand order, girl, (best quality), (masterpiece), (high detail), ((full face)), sharp, ((looking at viewer)), ((detailed pupils)), (thick thighs), (((full body))), (large breasts), vagina, nude, nipples |

Then type negative prompts.

|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts,signature, watermark, username, blurry, artist name |

4.2. Text to image

  1. Go to SD WebUI, type the prompts

  2. Check Restore faces

  3. Clcik Generate butoon, it will start generate a image

  4. You shall see the result at the right panel

All generated images will be stored at stable-diffusion-webui/outputs

You can also increase the value of Batch count so it will generate multiple images in one run.

4.3. Imge to image

  1. Type the prompts

  2. Upload a image. Check Restore faces. Clcik Generate.

You can change the value of CFG Scale and Denoising strength. The lower the value of Denoising strength is, the output would be more similar the original image.

Click Interrogate Deepboooru to generate prompts automatically accodring to the image you uploaded.

References

相关推荐
大柏怎么被偷了18 分钟前
【Linux】进程等待
linux·运维·服务器
偶像你挑的噻1 小时前
12-Linux驱动开发- SPI子系统
linux·驱动开发·stm32·嵌入式硬件
松涛和鸣2 小时前
16、C 语言高级指针与结构体
linux·c语言·开发语言·数据结构·git·算法
念风2 小时前
[lvgl]如何优雅地向lv_port_linux中添加tslib支持
linux
自由的好好干活3 小时前
使用Qoder编写ztdaq的C#跨平台示例总结
linux·windows·c#·qoder
赖small强3 小时前
【Linux 网络基础】libwebsockets HTTPS 服务端实现机制详解
linux·网络·https·tls·libwebsockets
optimistic_chen4 小时前
【Redis 系列】Redis详解
linux·数据库·redis·缓存·xsheel
低客的黑调4 小时前
了解JVM 结构和运行机制,从小白编程Java 大佬
java·linux·开发语言
想唱rap4 小时前
C++ map和set
linux·运维·服务器·开发语言·c++·算法
CodeByV4 小时前
【Linux】Ext 系列文件系统深度解析:从磁盘到软硬链接
linux·服务器