硬件要求

  • N卡

  • 显卡内存大于4G

  • 显卡驱动最新

软件准备

Git

用于拉取生成程序

Python

要求3.10.6以上的版本

Python 3.10.6 免安装版

安装

记住勾选to PATH选项,这样就不要去手动配置环境了。

在windows下,可用通过where命令,查询python的路径。

python更换国内镜像,解决下载torch、torchvision慢的问题。

1
2
3
4
豆瓣:http://pypi.douban.com/simple/
中科大:https://pypi.mirrors.ustc.edu.cn/simple/
清华:https://pypi.tuna.tsinghua.edu.cn/simple/
阿里云:https://mirrors.aliyun.com/pypi/simple/
1
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/

便捷化启动脚本

START_webui.bat[706B]

AUTOMATIC1111

AI运行程序,运行生成图片的程序,直接从GitHub克隆

1
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git

第一种方案

双击webui-user.bat文件,直接运行程序。

image-20221215153919191

如果出现环境报错,请在生成的venv\pyvenv.cfg文件中,修改python的路径。

这个安装过程相当慢!

安装完毕后,会有一个网址。但我还没有成功过,家里网络差,花了很多时间都没有反映。

第二种方案。

手动安装各种依赖。

  1. repositories文件文件中
  1. 软件本体必要python包
  1. 杂项

手动安装Pytorch

1
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116

image-20221216014117194

安装依赖包

1
2
3
4
#切换至各个依赖文件夹下
cd D:\sdwai\repositories\xxx #如:cd D:\sdwai\repositories\GFPGAN
D:\sdwai\Python310\python.exe setup.py install
D:\sdwai\Python310\python.exe -m pip install xxx #如:D:\sdwai\Python310\python.exe -m pip install gfpgan
1
2
3
4
5
6
#建议安装顺序
D:\sdwai\repositories\GFPGAN-master\setup.py
D:\sdwai\repositories\CLIP-main\setup.py
D:\sdwai\repositories\stable-diffusion\setup.py
D:\sdwai\repositories\k-diffusion\setup.py
D:\sdwai\repositories\taming-transformers\setup.py

image-20221216085328773

1
2
#重新克隆
git clone xxx

image-20221216111326219

image-20221216122715231

NovelAi-models

Ai模型文件

1
magnet:?xt=urn:btih:5bde442da86265b670a3e5ea3163afad2c6f8ecc

下载stablekpt目录中的某个模型即可

image-20221216162514987

下载完毕后

  1. 将模型文件夹中的model.ckpt、config.xml放入...\models\Stable-diffusion 目录中
  2. 然后分别改名为model.ckpt、model.xml。

开始使用

运行START_webui.bat,等等本地网页部署。

正向参数

1
masterpiece, best quality, 1girl, white and purple hair, red buttons, blue hair, transparent sleeves, light smile

负面参数

1
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
  • Sampling Steps是迭代次数,越大越耗时,一般20左右就足够了,太大提升也有限。
  • Sampling method是迭代算法,可以自己试试,感觉Euler和DDIM就不错,不同算法适合的迭代次数不尽相同。
  • WidthHeight是图像大小,不建议开太大,这个模型不太擅长生成大尺寸图片,特别是只有一个人的情况下,而且贼慢,可以考虑后期用waifu2x等工具超分辨率。
  • 接下来三个选项我也没用过。
  • Batch count是连续生成几次,Batch size是一次生成几张。例如Batch size=2,Batch count=3就是每次同时生成两张图片,生成三轮。注意Batch size其实就是利用显卡并行计算,受到显存制约,开太大会爆显存。
  • CFG Scale参数制约度,越高越接近参数(但可能会是强扭的瓜),越低越让AI自由发挥。在img2img中还有一个Denoising strength参数,描述的是图像模仿自由度,越高越自由发挥,越低和参考图像越接近。
  • Seed就是随机种子,可以指定,-1就是随机种子。

报错方案

RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 6.00 GiB total capacity; 5.23 GiB already allocated; 0 bytes free; 5.29 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF

1
2
3
4
5
6
7
8
9
#在webui-user.bat里面,set COMMANDLINE_ARGS=后面加上如下参数
#4G显存:
--precision full --no-half --lowvram --always-batch-cond-uncond
#6G显存:
--precision full --no-half --medvram
#低于5G显存:
--medvram
#低于3G显存:
--lowvram --always-batch-cond-uncond