一、选择服务器
本地安装
通过 https://github.com/AUTOMATIC1111/stable-diffusion-webui,查看是否满足条件,并且磁盘剩余空间要大(我使用的服务器,占用了20多个G,只有一个默认基底模型)。
服务器安装
阿里云提供了云实验室,免安装,也有活动,也可以选择。
腾讯云服务器,https://cloud.tencent.com/act/pro/2023spring?from=yunmember&page=seckill_season,有活动,可选择如下。
本文以在 centos 服务器自己安装为例。
二、安装软件
整个安装过程相对坎坷,遇到问题先看文末的问题列表,如果没有可去谷歌或者 stable-diffusion-webui github issue 中进行搜索。
安装 git
yum install git
安装 python3.10
官方需要 >= python3.10.6,此处安装或者升级 python3 到 python3.10.6,python2 系统自带,如果没有也需要安装,后续 yum 需要用到。
//下载
wget https://www.python.org/ftp/python/3.10.6/Python-3.10.6.tgz
//解压
tar -zxvf Python-3.10.6.tgz
//构建安装
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
// 设置git参数,加快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
三、配置外网访问
如果是本地启动,启动后,“本地ip:port” 访问即可。如果是服务器,启动后,通过“公网ip:port”访问,如果通过域名,需要配置 nginx。
下载 nginx
yum install nginx
配置 nginx
vi /etc/nginx/nginx.conf
修改内容如下:(列出核心修改,其他内容不变)
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,即可。如果没有域名,使用服务器外网IP进行访问即可。最终效果如下图所示,该界面是响应式的,手机也可访问。
四、开始作图
基底模型
基底模型决定了出图的整体风格。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
正向语义
组成:主体定义 + 主体形容 + 正向通用,多个词直接直接英文逗号隔开,无需标准的英语语句语法;权重语法可参考 这里,通常先写出主体定义 + 主体形容,之后根据需求调整权重。
参考:从 https://civitai.com/ 点击模型,查看语义,直接复制或者进行参考;
通用的正向语义词如下所示:
(photorealistic:1.4),best quality,realistic,masterpiece,extremely detailed,highres
用户定义的语义可通过 语义生成器 来做或者使用 chatGPT 来生成。
负向语义
直接写死一下这个就行,或者根据需求进行修改,通用的负向语义词:
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
采样器与采样步数
采样器:全部采样器介绍。我常用的 Euler(基础、快);DPM++ SDE Karras。
采样步数:不断绘制的过程,每一步都是在之前生成的基础上进行精修,通常 20~40 之间。
扩散度
通常 5~10 之间,如果太高,风格会变,色彩过于饱和(油画类)
随机种子
默认 -1,表示随机。如果保持和已生成图片一致,用于图片微调。
其他功能
局部微调
Lora
在基底模型的基础上继续增加 Lora 模型,进行训练。Lora 可去 https://civitai.com/ 进行下载,之后放到 SD的 models/Lora/ 内。
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 配置如下内容
_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代理
第二种方式:本地下载仓库,然后根据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/