一、選擇服務(wù)器
本地安裝
通過 https://github.com/AUTOMATIC1111/stable-diffusion-webui,查看是否滿足條件,并且磁盤剩余空間要大(我使用的服務(wù)器,占用了20多個G,只有一個默認基底模型)。
服務(wù)器安裝
阿里云提供了云實驗室,免安裝,也有活動,也可以選擇。
騰訊云服務(wù)器,https://cloud.tencent.com/act/pro/2023spring?from=yunmember&page=seckill_season,有活動,可選擇如下。
本文以在 centos 服務(wù)器自己安裝為例。
二、安裝軟件
整個安裝過程相對坎坷,遇到問題先看文末的問題列表,如果沒有可去谷歌或者 stable-diffusion-webui github issue 中進行搜索。
安裝 git
yum install git
安裝 python3.10
官方需要 >= python3.10.6,此處安裝或者升級 python3 到 python3.10.6,python2 系統(tǒng)自帶,如果沒有也需要安裝,后續(xù) yum 需要用到。
//下載
wget https://www.python.org/ftp/python/3.10.6/Python-3.10.6.tgz
//解壓
tar -zxvf Python-3.10.6.tgz
//構(gòu)建安裝
cd Python-3.10.6/
./configure
make && make install
// python與python3命令換軟連
mv /usr/bin/python /usr/bin/python.bak
mv /usr/bin/python3 /usr/bin/python3.bak
ln -s /usr/local/bin/python3.10 /usr/bin/python
ln -s /usr/local/bin/python3.10 /usr/bin/python3
// pip換軟連
ln -s /usr/local/bin/pip3 /usr/bin/pip
ln -s /usr/local/bin/pip3 /usr/bin/pip3
修改 yum 配置文件
sudo vi yum // 修改 #!/usr/bin/python 為 #!/usr/bin/python2.7
sudo vi /usr/libexec/urlgrabber-ext-down // 修改 #!/usr/bin/python 為 #!/usr/bin/python2.7
安裝 stable-diffusion-webui
// 設(shè)置git參數(shù),加快clone速度
git config --global http.postBuffer 524288000
// clone
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
// 安裝依賴庫
cd stable-diffusion-webui/
sudo pip install -r requirements_versions.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
啟動 stable-diffusion-webui
nohup python -u launch.py --listen --port 8008 > runtime.log 2>&1 &
啟動過程中會下載較多的倉庫,耐心等待,或者按照問題列表的方式進行處理。查看日志。標識啟動成功。
Model loaded in 3.3s (create model: 0.5s, apply weights to model: 0.7s, apply half(): 0.3s, load VAE: 1.2s, move model to device: 0.6s).
Running on local URL: http://0.0.0.0:8008
三、配置外網(wǎng)訪問
如果是本地啟動,啟動后,“本地ip:port” 訪問即可。如果是服務(wù)器,啟動后,通過“公網(wǎng)ip:port”訪問,如果通過域名,需要配置 nginx。
下載 nginx
yum install nginx
配置 nginx
vi /etc/nginx/nginx.conf
修改內(nèi)容如下:(列出核心修改,其他內(nèi)容不變)
server {
listen 80;
server_name www.xxx.cn; // 域名或者 localhost
...
location / {
proxy_pass http://127.0.0.1:8008; // 代理地址,即stable-diffusion 地址
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
在這里我使用的是域名的方式。瀏覽器訪問 http://www.xxx.cn,即可。如果沒有域名,使用服務(wù)器外網(wǎng)IP進行訪問即可。最終效果如下圖所示,該界面是響應(yīng)式的,手機也可訪問。
四、開始作圖
基底模型
基底模型決定了出圖的整體風格。SD 自帶了一個 v1-5-pruned-emaonly.safetensors,還可以從 https://civitai.com/ 選擇下載合適的 checkpoint 類型的模型,上傳到 SD 的 models/Stable-diffusion/ 目錄里,我安裝了如下三個模型:
- 默認:v1-5-pruned-emaonly.safetensors
- 通用逼真人物:chilloutmix_NiPrunedFp32Fix.safetensors
- 蒂法專用模型:tifaMeenow_tifaV2.safetensors
正向語義
組成:主體定義 + 主體形容 + 正向通用,多個詞直接直接英文逗號隔開,無需標準的英語語句語法;權(quán)重語法可參考 這里,通常先寫出主體定義 + 主體形容,之后根據(jù)需求調(diào)整權(quán)重。
參考:從 https://civitai.com/ 點擊模型,查看語義,直接復制或者進行參考;
通用的正向語義詞如下所示:
(photorealistic:1.4),best quality,realistic,masterpiece,extremely detailed,highres
用戶定義的語義可通過 語義生成器 來做或者使用 chatGPT 來生成。
負向語義
直接寫死一下這個就行,或者根據(jù)需求進行修改,通用的負向語義詞:
multiple breasts, (mutated hands and fingers:1.5 ), (long body :1.3), (mutation, poorly drawn :1.2) , black-white, bad anatomy, liquid body, liquid tongue, disfigured, malformed, mutated, anatomical nonsense, text font ui, error, malformed hands, long neck, blurred, lowers, lowres, bad anatomy, bad proportions, bad shadow, uncoordinated body, unnatural body, fused breasts, bad breasts, huge breasts, poorly drawn breasts, extra breasts, liquid breasts, heavy breasts, missing breasts, huge haunch, huge thighs, huge calf, bad hands, fused hand, missing hand, disappearing arms, disappearing thigh, disappearing calf, disappearing legs, fused ears, bad ears, poorly drawn ears, extra ears, liquid ears, heavy ears, missing ears, fused animal ears, bad animal ears, poorly drawn animal ears, extra animal ears, liquid animal ears, heavy animal ears, missing animal ears, text, ui, error, missing fingers, missing limb, fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with more than 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit, colorful tongue, black tongue, cropped, watermark, username, blurry, JPEG artifacts, signature, 3D, 3D game, 3D game scene, 3D character, malformed feet, extra feet, bad feet, poorly drawn feet, fused feet, missing feet, extra shoes, bad shoes, fused shoes, more than two shoes, poorly drawn shoes, bad gloves, poorly drawn gloves, fused gloves, bad cum, poorly drawn cum, fused cum, bad hairs, poorly drawn hairs, fused hairs, big muscles, ugly, bad face, fused face, poorly drawn face, cloned face, big face, long face, bad eyes, fused eyes poorly drawn eyes, extra eyes, malformed limbs, more than 2 nipples, missing nipples, different nipples, fused nipples, bad nipples, poorly drawn nipples, black nipples, colorful nipples, gross proportions. short arm, (((missing arms))), missing thighs, missing calf, missing legs, mutation, duplicate, morbid, mutilated, poorly drawn hands, more than 1 left hand, more than 1 right hand, deformed, (blurry), disfigured, missing legs, extra arms, extra thighs, more than 2 thighs, extra calf, fused calf, extra legs, bad knee, extra knee, more than 2 legs, bad tails, bad mouth, fused mouth, poorly drawn mouth, bad tongue, tongue within mouth, too long tongue, black tongue, big mouth, cracked mouth, bad mouth, dirty face, dirty teeth, dirty pantie, fused pantie, poorly drawn pantie, fused cloth, poorly drawn cloth, bad pantie, yellow teeth, thick lips, bad cameltoe, colorful cameltoe, bad asshole, poorly drawn asshole, fused asshole, missing asshole, bad anus, bad pussy, bad crotch, bad crotch seam, fused anus, fused pussy, fused anus, fused crotch, poorly drawn crotch, fused seam, poorly drawn anus, poorly drawn pussy, poorly drawn crotch, poorly drawn crotch seam, bad thigh gap, missing thigh gap, fused thigh gap, liquid thigh gap, poorly drawn thigh gap, poorly drawn anus, bad collarbone, fused collarbone, missing collarbone, liquid collarbone, strong girl, obesity, worst quality, low quality, normal quality, liquid tentacles, bad tentacles, poorly drawn tentacles, split tentacles, fused tentacles, missing clit, bad clit, fused clit, colorful clit, black clit, liquid clit, QR code, bar code, censored, safety panties, safety knickers, beard, furry ,pony, pubic hair, mosaic, excrement, faeces, shit
采樣器與采樣步數(shù)
采樣器:全部采樣器介紹。我常用的 Euler(基礎(chǔ)、快);DPM++ SDE Karras。
采樣步數(shù):不斷繪制的過程,每一步都是在之前生成的基礎(chǔ)上進行精修,通常 20~40 之間。
擴散度
通常 5~10 之間,如果太高,風格會變,色彩過于飽和(油畫類)
隨機種子
默認 -1,表示隨機。如果保持和已生成圖片一致,用于圖片微調(diào)。
其他功能
局部微調(diào)
Lora
在基底模型的基礎(chǔ)上繼續(xù)增加 Lora 模型,進行訓練。Lora 可去 https://civitai.com/ 進行下載,之后放到 SD的 models/Lora/ 內(nèi)。
ControllNet
AI 模仿原始圖的動作進行繪畫,用于指定動作繪制。
五、一些示例
示例1
正向語義:
best quality, masterpiece, highres, 1girl,china dress,hair ornament,necklace, jewelry,Beautiful face,upon_body, tyndall effect,photorealistic, dark studio, rim lighting, two tone lighting,(high detailed skin:1.2), 8k uhd, dslr, soft lighting, high quality, volumetric lighting, candid, Photograph, high resolution, 4k, 8k, Bokeh
負向語義:
上面通用的負向語義
其他配置:
最終效果:
示例2
附、遇到的報錯和阻塞
1、安裝Python3后yum無法使用
解決方案:https://blog.csdn.net/zsl10/article/details/52315319
2、python setup.py bdist_wheel 報錯
解決方案:https://blog.csdn.net/qq_40236497/article/details/125633599
3、ModuleNotFoundError: No module named '_ctypes'
解決方案:https://blog.51cto.com/u_15162069/2887202
4、ModuleNotFoundError: No module named '_ssl'
解決方案:安裝 openssl-1.1.1,配置python,重新安裝python
第一步:安裝 openssl-1.1.1
cd /home/
wget http://www.openssl.org/source/openssl-1.1.1.tar.gz --no-check-certificate
tar -zxf openssl-1.1.1.tar.gz
cd openssl-1.1.1/
mkdir /usr/local/openssl
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl
make && make install
第二步:配置 Python
vi /home/Python-3.10.6/Modules/Setup 配置如下內(nèi)容
_socket socketmodule.c
OPENSSL=/usr/local/openssl
_ssl _ssl.c \
-I$(OPENSSL)/include -L$(OPENSSL)/lib \
-lssl -lcrypto
第三步:重新安裝 Python
cd /home/Python-3.10.6/
make clean
./configure
make && make install
5、ModuleNotFoundError: No module named '_bz2'
yum install bzip2-devel
之后重新安裝 Python。
6、ModuleNotFoundError: No module named '_lzma'
yum install -y xz-devel
之后重新安裝 Python。
7、git -C unknown option
https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/8193
8、啟動過程 clone 各種倉庫慢
第一種方式:配置git代理
第二種方式:本地下載倉庫,然后根據(jù)clone慢導致的報錯上傳到指定位置,并且進行重命名。例如。/home/stable-diffusion-webui/repositories/taming-transformers/
8、啟動過程中下載模型慢
Downloading: "https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors" to /home/stable-diffusion-webui/models/Stable-diffusion/v1-5-pruned-emaonly.safetensors
手動下載 v1-5-pruned-emaonly.safetensors,然后上傳到 /home/stable-diffusion-webui/models/Stable-diffusion/