Stable Diffusion 是熱門的文本到圖像的生成擴散模型,本文介紹了如何準備其 WebUI 環(huán)境。
-
Stability AI
- Stability API Extension for Automatic1111 WebUI
- Stable Diffusion web UI
環(huán)境基礎
- OS: Ubuntu 22.04.2 LTS
- Kernel: 5.19.0
- CPU: AMD Ryzen 7 3700X
- GPU: NVIDIA GeForce RTX 2080 Ti
- RAM: 16GB
環(huán)境安裝
Nvidia 驅(qū)動
# 查看可用驅(qū)動信息
ubuntu-drivers devices
# 安裝 Nvidia 驅(qū)動(可選提示 recommended 的)
sudo apt install nvidia-driver-530
# 查看 Nvidia 驅(qū)動(查看不了,可重登錄或重啟)
nvidia-smi
Anaconda
- Anaconda: https://www.anaconda.com/download
# 安裝 Anaconda, 都 yes
bash Anaconda3-2023.03-1-Linux-x86_64.sh
PyTorch
- PyTorch: https://pytorch.org/
# 創(chuàng)建虛擬環(huán)境
conda create -n sdwebui python=3.10.6 -y
conda activate sdwebui
# 安裝 PyTorch with CUDA
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia -y
檢查 PyTorch 版本,
$ python - <<EOF
import torch
print(torch.__version__, torch.cuda.is_available())
EOF
2.0.1 True
Stable Diffusion WebUI
獲取代碼
sudo apt install git -y
git clone -b v1.3.2 --depth 1 https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
cd stable-diffusion-webui/
export SDWEBUI=`pwd`
獲取模型
從 Civitai 或 HuggingFace 下載模型,
- 現(xiàn)實風格
- majicMIX realistic
- 動漫風格
- DreamShaper
這里選了兩種不同風格的模型,放進 models/Stable-diffusion/
目錄,
mv majicmixRealistic_v5.safetensors $SDWEBUI/models/Stable-diffusion/
mv dreamshaper_6BakedVae.safetensors $SDWEBUI/models/Stable-diffusion/
啟動運行
conda activate sdwebui
# 避免用 venv,就用 conda 虛擬環(huán)境
export VIRTUAL_ENV=sdwebui
# 啟用局域網(wǎng)訪問
export COMMANDLINE_ARGS=" --listen"
# 以上可以直接在 webui-user.sh 配置好,如下
cd $SDWEBUI
vi webui-user.sh
# webui-user.sh
# eval "$(conda shell.bash hook)"
# conda activate sdwebui
# export VIRTUAL_ENV=sdwebui
# export COMMANDLINE_ARGS=" --listen"
# 啟動運行
cd $SDWEBUI
./webui.sh
-
webui-user.sh
可配置指定的 Stable Diffusion 版本等,默認值見$SDWEBUI/modules/launch_utils.py
。 -
webui.sh
啟動運行,默認會用 python venv 準備完整環(huán)境,不過這里讓用已準備的 conda 虛擬環(huán)境了。
等啟動后,瀏覽器打開 http://127.0.0.1:7860/
即可開始使用了。
初步使用
Stable Diffusion checkpoint
選擇模型,于 txt2img
標簽頁寫好 Prompt
Negative Prompt
文本,再 Generate
即可生成圖像。
剛開始使用,可以借用別人的 Prompt
試試:如模型下載頁示例圖像的,或如 PromptHero 等站點分享圖像的。試了下兩模型,效果如下:
majicMIX realistic:
# Prompt
best quality, masterpiece, ultra high res, photorealistic, 1girl, offshoulder, smile,
Portrait
# Negative prompt
ng_deepnegative_v1_75t, (badhandv4:1.2), (worst quality:2), (low quality:2), (normal quality:2), lowres, bad anatomy, bad hands, ((monochrome)), ((grayscale)) watermark, moles
DreamShaper:
# Prompt
(masterpiece, top quality, best quality, official art, beautiful and aesthetic:1.2),(8k, best quality, masterpiece:1.2),CGDivineSwordsw, weapon, armor, solo, holding, horns, glowing, sword, 1boy, holding weapon, planted, male focus, glowing weapon, standing, helmet, gauntlets, holding sword, glowing sword, planted sword, shoulder armor, gradient, gradient background, greaves, pauldrons, (blue glow:1.3), <lora:CGDivineSwordsw_20230611172159:1>
# Negative prompt
(badhandv4:1.2),lowres, bad anatomy,bad arms,text, bad face, error, extra digit, fewer digits, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, {blurry:1.1}, missing arms, missing legs, more than two legs,cowboy,huge_breasts,gigantic_breasts,
后話
Prompt
需要自己多玩,慢慢探索和總結??梢运阉鲃e人分享的經(jīng)驗,也有不少生成或優(yōu)化工具。去理解擴散模型的大概原理,也可能有不少幫助。文章來源:http://www.zghlxwxcb.cn/news/detail-539732.html
GoCoding 個人實踐的經(jīng)驗分享,可關注公眾號!文章來源地址http://www.zghlxwxcb.cn/news/detail-539732.html
到了這里,關于Stable Diffusion WebUI 環(huán)境的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!