【AI作画】使用stable-diffusion-webui搭建AI作画平台

news2025/7/12 8:02:52

一、安装配置Anaconda

进入官网下载安装包https://www.anaconda.com/并安装,然后将Anaconda配置到环境变量中。

在这里插入图片描述

打开命令行,依次通过如下命令创建Python运行虚拟环境。

conda env create novelai python==3.10.6
E:\workspace\02_Python\novalai>conda info --envs
# conda environments:
#
base                  *  D:\anaconda3
novelai                  D:\anaconda3\envs\novelai
conda activate novelai

二、安装CUDA

笔者的显卡为NVIDIA,需安装NVIDIA的开发者工具进入官网https://developer.nvidia.com/,根据自己计算机的系统情况,选择合适的安装包下载安装。

在这里插入图片描述

打开安装程序后,依照提示完成安装。
在这里插入图片描述在这里插入图片描述在这里插入图片描述

安装完成后,在命令窗口输入如下命令,输出CUDA版本即安装成功。

C:\Users\yefuf>nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:41:10_Pacific_Daylight_Time_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0

三、安装pytorch

进入官网https://pytorch.org/,根据计算机配置选择合适的版本进行安装。这里需要注意的是CUDA的平台选择,先打开NVIDIA控制面板-帮助-系统信息-组件查看CUDA版本,官网上选择的计算平台需要低于计算机的NVIDIA版本。
在这里插入图片描述
配置选择完成后,官网会生成相应的安装命令。
在这里插入图片描述
将安装命令复制出,命令窗口执行安装即可。

conda install pytorch torchvision torchaudio pytorch-cuda=11.6 -c pytorch -c nvidia

当查到Pytorch官网推荐的CUDA版本跟你的显卡版本不匹配时,就需要根据官网的CUDA版本找到对应的显卡驱动版本并升级显卡驱动,对应关系可通过https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html查看
在这里插入图片描述

四、安装git

进入git官网https://git-scm.com/,下载安装即可。

五、搭建stable-diffusion-webui

进入项目地址https://github.com/AUTOMATIC1111/stable-diffusion-webui,通过git将项目克隆下来。

git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
Cloning into 'stable-diffusion-webui'...
remote: Enumerating objects: 10475, done.
remote: Counting objects: 100% (299/299), done.
remote: Compressing objects: 100% (199/199), done.
remote: Total 10475 (delta 178), reused 199 (delta 100), pack-reused 10176
Receiving objects: 100% (10475/10475), 23.48 MiB | 195.00 KiB/s, done.
Resolving deltas: 100% (7312/7312), done.

克隆下载扩展库。

git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui-aesthetic-gradients “extensions/aesthetic-gradients”
Cloning into 'extensions/aesthetic-gradients'...
remote: Enumerating objects: 21, done.
remote: Counting objects: 100% (21/21), done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 21 (delta 3), reused 18 (delta 3), pack-reused 0
Receiving objects: 100% (21/21), 1.09 MiB | 1.34 MiB/s, done.
Resolving deltas: 100% (3/3), done.
git clone https://github.com/yfszzx/stable-diffusion-webui-images-browser “extensions/images-browser”
Cloning into 'extensions/images-browser'...
remote: Enumerating objects: 118, done.
remote: Counting objects: 100% (118/118), done.
remote: Compressing objects: 100% (70/70), done.
remote: Total 118 (delta 42), reused 65 (delta 24), pack-reused 0
Receiving objects: 100% (118/118), 33.01 KiB | 476.00 KiB/s, done.
Resolving deltas: 100% (42/42), done.

克隆完成后,extensions目录会多如下文件夹:
在这里插入图片描述
下载模型库https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Dependencies,并将下载的.ckpt

放到models/Stable-diffusion文件夹中。模型很大,推荐使用下载器。
在这里插入图片描述
安装项目所需的Python依赖库。

pip install -r requirements.txt

在这里插入图片描述
安装完成之后,运行如下命令,顺利的话,当程序加载完成模型之后,会自动打开http://127.0.0.1:7860/显示平台主页。

python launch.py --autolaunch

进入平台的设置页面,选择语言为中文,重启程序之后,即可看到页面显示为中文。

在这里插入图片描述
在界面中输入作画内容的正向提示词(画想要什么特征)和反向提示词(画不想要什么特征),点击生成即可开始自动作画。

在这里插入图片描述
如上述的提示词作出的画如图(由于随机种子不同,生成的画会有差异)。
在这里插入图片描述

六、如何设置提示词

这里建议使用元素法典https://docs.qq.com/doc/DWHl3am5Zb05QbGVs,上面有前人整理好的提示词及效果,以供参考。
在这里插入图片描述

七、可能遇到的问题

1、GitHub访问不了或访问慢

一般为DNS解析问题,需要修改本地host文件,增加配置内容,绕过域名解析,达到加速访问的目的。

访问https://www.ipaddress.com/,分别输入github.comgithub.global.ssl.fastly.net,获取域名对应的IP地址。
在这里插入图片描述
在这里插入图片描述
打开系统的Host文件,将IP和域名的对应关系配置到Host文件中。
在这里插入图片描述
配置文件内容如下:

140.82.114.4	github.com
199.232.5.194	github.global.ssl.fastly.net

执行命令ipconfig /flushdns刷新DNS即可。

2、pip安装依赖库慢或常下载失败

pip安装依赖库时默认选择国外的源,安装速度会非常慢,可以考虑切换为国内源,常用的国内源如下:

阿里云 https://mirrors.aliyun.com/pypi/simple/ 
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/ 
豆瓣(douban) https://pypi.douban.com/simple/ 
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/ 
中国科学技术大学 https://pypi.mirrors.ustc.edu.cn/simple/

在安装依赖库时,可使用pip install -i 源 空格 安装包名称进行源的选择,如pip install -i https://mirrors.aliyun.com/pypi/simple numpy

也可以通过增加配置文件,使安装依赖库时默认选择国内的源,在用户目录下增加pip.ini文件。
在这里插入图片描述
在文件中写入如下内容。

[global]
timeout = 60000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

[install]
use-mirrors = true
mirrors = https://pypi.tuna.tsinghua.edu.cn

3、安装CLIP时提示Connection was aborted, errno 10053

出错时的错误打印如下:

(novelai) E:\workspace\02_Python\novalai\stable-diffusion-webui>python launch.py
Python 3.10.6 | packaged by conda-forge | (main, Oct 24 2022, 16:02:16) [MSC v.1916 64 bit (AMD64)]
Commit hash: b8f2dfed3c0085f1df359b9dc5b3841ddc2196f0
Installing clip
Traceback (most recent call last):
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\launch.py", line 251, in <module>
    prepare_enviroment()
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\launch.py", line 178, in prepare_enviroment
    run_pip(f"install {clip_package}", "clip")
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\launch.py", line 63, in run_pip
    return run(f'"{python}" -m pip {args} --prefer-binary{index_url_line}', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}")
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\launch.py", line 34, in run
    raise RuntimeError(message)
RuntimeError: Couldn't install clip.
Command: "D:\anaconda3\envs\novelai\python.exe" -m pip install git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1 --prefer-binary
Error code: 1
stdout: Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1
  Cloning https://github.com/openai/CLIP.git (to revision d50d76daa670286dd6cacf3bcd80b5e4823fc8e1) to c:\users\yefuf\appdata\local\temp\pip-req-build-f8w7kbzg

stderr:   Running command git clone --filter=blob:none --quiet https://github.com/openai/CLIP.git 'C:\Users\yefuf\AppData\Local\Temp\pip-req-build-f8w7kbzg'
  fatal: unable to access 'https://github.com/openai/CLIP.git/': OpenSSL SSL_read: Connection was aborted, errno 10053
  error: subprocess-exited-with-error

  git clone --filter=blob:none --quiet https://github.com/openai/CLIP.git 'C:\Users\yefuf\AppData\Local\Temp\pip-req-build-f8w7kbzg' did not run successfully.
  exit code: 128

  See above for output.

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

git clone --filter=blob:none --quiet https://github.com/openai/CLIP.git 'C:\Users\yefuf\AppData\Local\Temp\pip-req-build-f8w7kbzg' did not run successfully.
exit code: 128

See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

通过访CLIP项目GitHub主页,发现该项目可以通过如下命令进行安装解决。

pip install ftfy regex tqdm
pip install git+https://github.com/openai/CLIP.git

4、项目启动中提示Connection was reset in connection to github.com

出错时的错误打印如下:

(novelai) E:\workspace\02_Python\novalai\stable-diffusion-webui>python launch.py
Python 3.10.6 | packaged by conda-forge | (main, Oct 24 2022, 16:02:16) [MSC v.1916 64 bit (AMD64)]
Commit hash: b8f2dfed3c0085f1df359b9dc5b3841ddc2196f0
Cloning Stable Diffusion into repositories\stable-diffusion...
Cloning Taming Transformers into repositories\taming-transformers...
Traceback (most recent call last):
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\launch.py", line 251, in <module>
    prepare_enviroment()
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\launch.py", line 201, in prepare_enviroment
    git_clone(taming_transformers_repo, repo_dir('taming-transformers'), "Taming Transformers", taming_transformers_commit_hash)
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\launch.py", line 85, in git_clone
    run(f'"{git}" clone "{url}" "{dir}"', f"Cloning {name} into {dir}...", f"Couldn't clone {name}")
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\launch.py", line 34, in run
    raise RuntimeError(message)
RuntimeError: Couldn't clone Taming Transformers.
Command: "git" clone "https://github.com/CompVis/taming-transformers.git" "repositories\taming-transformers"
Error code: 128
stdout: <empty>
stderr: Cloning into 'repositories\taming-transformers'...
fatal: unable to access 'https://github.com/CompVis/taming-transformers.git/': OpenSSL SSL_connect: Connection was reset in connection to github.com:443

在命令窗口中输入如下命令,然后重新运行程序,但实际操作下来,仍有较大概率在克隆项目的过程中失败。

git config --global http.postBuffer 524288000
git config --global http.sslVerify "false"

查看lauch.py中的代码可以发现,程序在启动时有对依赖项目进行检查,如项目不存在,则克隆下来。

def prepare_enviroment():
    torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113")
    requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt")
    commandline_args = os.environ.get('COMMANDLINE_ARGS', "")

    gfpgan_package = os.environ.get('GFPGAN_PACKAGE', "git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379")
    clip_package = os.environ.get('CLIP_PACKAGE', "git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1")
    deepdanbooru_package = os.environ.get('DEEPDANBOORU_PACKAGE', "git+https://github.com/KichangKim/DeepDanbooru.git@d91a2963bf87c6a770d74894667e9ffa9f6de7ff")

    xformers_windows_package = os.environ.get('XFORMERS_WINDOWS_PACKAGE', 'https://github.com/C43H66N12O12S2/stable-diffusion-webui/releases/download/f/xformers-0.0.14.dev0-cp310-cp310-win_amd64.whl')

    stable_diffusion_repo = os.environ.get('STABLE_DIFFUSION_REPO', "https://github.com/CompVis/stable-diffusion.git")
    taming_transformers_repo = os.environ.get('TAMING_REANSFORMERS_REPO', "https://github.com/CompVis/taming-transformers.git")
    k_diffusion_repo = os.environ.get('K_DIFFUSION_REPO', 'https://github.com/crowsonkb/k-diffusion.git')
    codeformer_repo = os.environ.get('CODEFORMET_REPO', 'https://github.com/sczhou/CodeFormer.git')
    blip_repo = os.environ.get('BLIP_REPO', 'https://github.com/salesforce/BLIP.git')

    stable_diffusion_commit_hash = os.environ.get('STABLE_DIFFUSION_COMMIT_HASH', "69ae4b35e0a0f6ee1af8bb9a5d0016ccb27e36dc")
    taming_transformers_commit_hash = os.environ.get('TAMING_TRANSFORMERS_COMMIT_HASH', "24268930bf1dce879235a7fddd0b2355b84d7ea6")
    k_diffusion_commit_hash = os.environ.get('K_DIFFUSION_COMMIT_HASH', "f4e99857772fc3a126ba886aadf795a332774878")
    codeformer_commit_hash = os.environ.get('CODEFORMER_COMMIT_HASH', "c5b4593074ba6214284d6acd5f1719b6c5d739af")
    blip_commit_hash = os.environ.get('BLIP_COMMIT_HASH', "48211a1594f1321b00f14c9f7a5b4813144b2fb9")

因此,我们打开git bash重新执行上述两条git命令,预先将项目克隆下来。

git clone https://github.com/CompVis/taming-transformers.git "repositories\taming-transformers"

git clone https://github.com/crowsonkb/k-diffusion.git "repositories\k-diffusion"

git clone https://github.com/sczhou/CodeFormer.git "repositories\CodeFormer"

git clone https://github.com/salesforce/BLIP.git "repositories\BLIP"

克隆完成之后如图:
在这里插入图片描述

5、项目启动中提示CUDA out of memory

出错时的错误打印如下:

(novelai) E:\workspace\02_Python\novalai\stable-diffusion-webui>python launch.py
Python 3.10.6 | packaged by conda-forge | (main, Oct 24 2022, 16:02:16) [MSC v.1916 64 bit (AMD64)]
Commit hash: b8f2dfed3c0085f1df359b9dc5b3841ddc2196f0
Fetching updates for BLIP...
Checking out commit for BLIP with hash: 48211a1594f1321b00f14c9f7a5b4813144b2fb9...
Installing requirements for CodeFormer
Installing requirements for Web UI
Launching Web UI with arguments:
Moving sd-v1-4.ckpt from E:\workspace\02_Python\novalai\stable-diffusion-webui\models to E:\workspace\02_Python\novalai\stable-diffusion-webui\models\Stable-diffusion.
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
making attention of type 'vanilla' with 512 in_channels
Working with z of shape (1, 4, 32, 32) = 4096 dimensions.
making attention of type 'vanilla' with 512 in_channels
Downloading: 100%|██████████████████████████████████████████████████████████████████| 939k/939k [00:00<00:00, 1.26MB/s]
Downloading: 100%|███████████████████████████████████████████████████████████████████| 512k/512k [00:01<00:00, 344kB/s]
Downloading: 100%|████████████████████████████████████████████████████████████████████████████| 389/389 [00:00<?, ?B/s]
Downloading: 100%|████████████████████████████████████████████████████████████████████████████| 905/905 [00:00<?, ?B/s]
Downloading: 100%|████████████████████████████████████████████████████████████████████████| 4.41k/4.41k [00:00<?, ?B/s]
Downloading: 100%|████████████████████████████████████████████████████████████████| 1.59G/1.59G [03:56<00:00, 7.23MB/s]
Loading weights [7460a6fa] from E:\workspace\02_Python\novalai\stable-diffusion-webui\models\Stable-diffusion\sd-v1-4.ckpt
Global Step: 470000
Traceback (most recent call last):
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\launch.py", line 252, in <module>
    start()
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\launch.py", line 247, in start
    webui.webui()
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\webui.py", line 148, in webui
    initialize()
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\webui.py", line 83, in initialize
    modules.sd_models.load_model()
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\modules\sd_models.py", line 252, in load_model
    sd_model.to(shared.device)
  File "D:\anaconda3\envs\novelai\lib\site-packages\pytorch_lightning\core\mixins\device_dtype_mixin.py", line 113, in to
    return super().to(*args, **kwargs)
  File "D:\anaconda3\envs\novelai\lib\site-packages\torch\nn\modules\module.py", line 987, in to
    return self._apply(convert)
  File "D:\anaconda3\envs\novelai\lib\site-packages\torch\nn\modules\module.py", line 639, in _apply
    module._apply(fn)
  File "D:\anaconda3\envs\novelai\lib\site-packages\torch\nn\modules\module.py", line 639, in _apply
    module._apply(fn)
  File "D:\anaconda3\envs\novelai\lib\site-packages\torch\nn\modules\module.py", line 639, in _apply
    module._apply(fn)
  [Previous line repeated 2 more times]
  File "D:\anaconda3\envs\novelai\lib\site-packages\torch\nn\modules\module.py", line 662, in _apply
    param_applied = fn(param)
  File "D:\anaconda3\envs\novelai\lib\site-packages\torch\nn\modules\module.py", line 985, in convert
    return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None, non_blocking)
torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 2.00 GiB total capacity; 1.68 GiB already allocated; 0 bytes free; 1.72 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

根据提示,先尝试用如下命令改变pytorch配置,仍旧报错!

set PYTORCH_CUDA_ALLOC_CONF=garbage_collection_threshold:0.6,max_split_size_mb:128

尝试增加代码with torch.no_grad(),使内存就不会分配参数梯度的空间,仍旧报错!
在这里插入图片描述
由于提示内存溢出,先通过控制面板->所有控制面板项->管理工具->系统信息,查看显卡内存大小。
在这里插入图片描述
官方推荐的显卡内存大小为4GB以上,而笔者的显卡内存只有2GB,显然GPU不符合要求。查看项目的命令选项,发现项目支持CPU计算--use-cpu

(novelai) E:\workspace\02_Python\novalai\stable-diffusion-webui>python launch.py -h
Python 3.10.6 | packaged by conda-forge | (main, Oct 24 2022, 16:02:16) [MSC v.1916 64 bit (AMD64)]
Commit hash: b8f2dfed3c0085f1df359b9dc5b3841ddc2196f0
Installing requirements for Web UI
Launching Web UI with arguments: -h
usage: launch.py [-h] [--config CONFIG] [--ckpt CKPT] [--ckpt-dir CKPT_DIR] [--gfpgan-dir GFPGAN_DIR]
                 [--gfpgan-model GFPGAN_MODEL] [--no-half] [--no-half-vae] [--no-progressbar-hiding]
                 [--max-batch-count MAX_BATCH_COUNT] [--embeddings-dir EMBEDDINGS_DIR]
                 [--hypernetwork-dir HYPERNETWORK_DIR] [--localizations-dir LOCALIZATIONS_DIR] [--allow-code]
                 [--medvram] [--lowvram] [--lowram] [--always-batch-cond-uncond] [--unload-gfpgan]
                 [--precision {full,autocast}] [--share] [--ngrok NGROK] [--ngrok-region NGROK_REGION]
                 [--enable-insecure-extension-access] [--codeformer-models-path CODEFORMER_MODELS_PATH]
                 [--gfpgan-models-path GFPGAN_MODELS_PATH] [--esrgan-models-path ESRGAN_MODELS_PATH]
                 [--bsrgan-models-path BSRGAN_MODELS_PATH] [--realesrgan-models-path REALESRGAN_MODELS_PATH]
                 [--scunet-models-path SCUNET_MODELS_PATH] [--swinir-models-path SWINIR_MODELS_PATH]
                 [--ldsr-models-path LDSR_MODELS_PATH] [--clip-models-path CLIP_MODELS_PATH] [--xformers]
                 [--force-enable-xformers] [--deepdanbooru] [--opt-split-attention] [--opt-split-attention-invokeai]
                 [--opt-split-attention-v1] [--disable-opt-split-attention]
                 [--use-cpu {all,sd,interrogate,gfpgan,swinir,esrgan,scunet,codeformer} [{all,sd,interrogate,gfpgan,swinir,esrgan,scunet,codeformer} ...]]
                 [--listen] [--port PORT] [--show-negative-prompt] [--ui-config-file UI_CONFIG_FILE]
                 [--hide-ui-dir-config] [--freeze-settings] [--ui-settings-file UI_SETTINGS_FILE] [--gradio-debug]
                 [--gradio-auth GRADIO_AUTH] [--gradio-img2img-tool {color-sketch,editor}] [--opt-channelslast]
                 [--styles-file STYLES_FILE] [--autolaunch] [--theme THEME] [--use-textbox-seed]
                 [--disable-console-progressbars] [--enable-console-prompts] [--vae-path VAE_PATH]
                 [--disable-safe-unpickle] [--api] [--nowebui] [--ui-debug-mode] [--device-id DEVICE_ID]
                 [--administrator] [--cors-allow-origins CORS_ALLOW_ORIGINS] [--tls-keyfile TLS_KEYFILE]
                 [--tls-certfile TLS_CERTFILE] [--server-name SERVER_NAME]

options:
  -h, --help            show this help message and exit
  --config CONFIG       path to config which constructs model
  --ckpt CKPT           path to checkpoint of stable diffusion model; if specified, this checkpoint will be added to
                        the list of checkpoints and loaded
  --ckpt-dir CKPT_DIR   Path to directory with stable diffusion checkpoints
  --gfpgan-dir GFPGAN_DIR
                        GFPGAN directory
  --gfpgan-model GFPGAN_MODEL
                        GFPGAN model file name
  --no-half             do not switch the model to 16-bit floats
  --no-half-vae         do not switch the VAE model to 16-bit floats
  --no-progressbar-hiding
                        do not hide progressbar in gradio UI (we hide it because it slows down ML if you have hardware
                        acceleration in browser)
  --max-batch-count MAX_BATCH_COUNT
                        maximum batch count value for the UI
  --embeddings-dir EMBEDDINGS_DIR
                        embeddings directory for textual inversion (default: embeddings)
  --hypernetwork-dir HYPERNETWORK_DIR
                        hypernetwork directory
  --localizations-dir LOCALIZATIONS_DIR
                        localizations directory
  --allow-code          allow custom script execution from webui
  --medvram             enable stable diffusion model optimizations for sacrificing a little speed for low VRM usage
  --lowvram             enable stable diffusion model optimizations for sacrificing a lot of speed for very low VRM
                        usage
  --lowram              load stable diffusion checkpoint weights to VRAM instead of RAM
  --always-batch-cond-uncond
                        disables cond/uncond batching that is enabled to save memory with --medvram or --lowvram
  --unload-gfpgan       does not do anything.
  --precision {full,autocast}
                        evaluate at this precision
  --share               use share=True for gradio and make the UI accessible through their site
  --ngrok NGROK         ngrok authtoken, alternative to gradio --share
  --ngrok-region NGROK_REGION
                        The region in which ngrok should start.
  --enable-insecure-extension-access
                        enable extensions tab regardless of other options
  --codeformer-models-path CODEFORMER_MODELS_PATH
                        Path to directory with codeformer model file(s).
  --gfpgan-models-path GFPGAN_MODELS_PATH
                        Path to directory with GFPGAN model file(s).
  --esrgan-models-path ESRGAN_MODELS_PATH
                        Path to directory with ESRGAN model file(s).
  --bsrgan-models-path BSRGAN_MODELS_PATH
                        Path to directory with BSRGAN model file(s).
  --realesrgan-models-path REALESRGAN_MODELS_PATH
                        Path to directory with RealESRGAN model file(s).
  --scunet-models-path SCUNET_MODELS_PATH
                        Path to directory with ScuNET model file(s).
  --swinir-models-path SWINIR_MODELS_PATH
                        Path to directory with SwinIR model file(s).
  --ldsr-models-path LDSR_MODELS_PATH
                        Path to directory with LDSR model file(s).
  --clip-models-path CLIP_MODELS_PATH
                        Path to directory with CLIP model file(s).
  --xformers            enable xformers for cross attention layers
  --force-enable-xformers
                        enable xformers for cross attention layers regardless of whether the checking code thinks you
                        can run it; do not make bug reports if this fails to work
  --deepdanbooru        enable deepdanbooru interrogator
  --opt-split-attention
                        force-enables Doggettx's cross-attention layer optimization. By default, it's on for torch
                        cuda.
  --opt-split-attention-invokeai
                        force-enables InvokeAI's cross-attention layer optimization. By default, it's on when cuda is
                        unavailable.
  --opt-split-attention-v1
                        enable older version of split attention optimization that does not consume all the VRAM it can
                        find
  --disable-opt-split-attention
                        force-disables cross-attention layer optimization
  --use-cpu {all,sd,interrogate,gfpgan,swinir,esrgan,scunet,codeformer} [{all,sd,interrogate,gfpgan,swinir,esrgan,scunet,codeformer} ...]
                        use CPU as torch device for specified modules
  --listen              launch gradio with 0.0.0.0 as server name, allowing to respond to network requests
  --port PORT           launch gradio with given server port, you need root/admin rights for ports < 1024, defaults to
                        7860 if available
  --show-negative-prompt
                        does not do anything
  --ui-config-file UI_CONFIG_FILE
                        filename to use for ui configuration
  --hide-ui-dir-config  hide directory configuration from webui
  --freeze-settings     disable editing settings
  --ui-settings-file UI_SETTINGS_FILE
                        filename to use for ui settings
  --gradio-debug        launch gradio with --debug option
  --gradio-auth GRADIO_AUTH
                        set gradio authentication like "username:password"; or comma-delimit multiple like
                        "u1:p1,u2:p2,u3:p3"
  --gradio-img2img-tool {color-sketch,editor}
                        gradio image uploader tool: can be either editor for ctopping, or color-sketch for drawing
  --opt-channelslast    change memory type for stable diffusion to channels last
  --styles-file STYLES_FILE
                        filename to use for styles
  --autolaunch          open the webui URL in the system's default browser upon launch
  --theme THEME         launches the UI with light or dark theme
  --use-textbox-seed    use textbox for seeds in UI (no up/down, but possible to input long seeds)
  --disable-console-progressbars
                        do not output progressbars to console
  --enable-console-prompts
                        print prompts to console when generating with txt2img and img2img
  --vae-path VAE_PATH   Path to Variational Autoencoders model
  --disable-safe-unpickle
                        disable checking pytorch models for malicious code
  --api                 use api=True to launch the api with the webui
  --nowebui             use api=True to launch the api instead of the webui
  --ui-debug-mode       Don't load model to quickly launch UI
  --device-id DEVICE_ID
                        Select the default CUDA device to use (export CUDA_VISIBLE_DEVICES=0,1,etc might be needed
                        before)
  --administrator       Administrator rights
  --cors-allow-origins CORS_ALLOW_ORIGINS
                        Allowed CORS origins
  --tls-keyfile TLS_KEYFILE
                        Partially enables TLS, requires --tls-certfile to fully function
  --tls-certfile TLS_CERTFILE
                        Partially enables TLS, requires --tls-keyfile to fully function
  --server-name SERVER_NAME
                        Sets hostname of server

尝试构造如下运行参数,--use-cpu all使所有模块均使用CPU计算,--lowram --always-batch-cond-uncond使用低内存配置选项,程序可以成功运行。

(novelai) E:\workspace\02_Python\novalai\stable-diffusion-webui>python launch.py --lowram --always-batch-cond-uncond --use-cpu all
Python 3.10.6 | packaged by conda-forge | (main, Oct 24 2022, 16:02:16) [MSC v.1916 64 bit (AMD64)]
Commit hash: b8f2dfed3c0085f1df359b9dc5b3841ddc2196f0
Installing requirements for Web UI
Launching Web UI with arguments: --lowram --always-batch-cond-uncond --use-cpu all
Warning: caught exception 'Expected a cuda device, but got: cpu', memory monitor disabled
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
making attention of type 'vanilla' with 512 in_channels
Working with z of shape (1, 4, 32, 32) = 4096 dimensions.
making attention of type 'vanilla' with 512 in_channels
Loading weights [7460a6fa] from E:\workspace\02_Python\novalai\stable-diffusion-webui\models\Stable-diffusion\sd-v1-4.ckpt
Global Step: 470000
Applying cross attention optimization (Doggettx).
Model loaded.
Loaded a total of 0 textual inversion embeddings.
Embeddings:
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.

然而,开始作画时提示RuntimeError: "LayerNormKernelImpl" not implemented for 'Half'错误!如果安装网上的处理方法,将half函数在工程中替换为float函数,则会出现device不匹配问题。

Traceback (most recent call last):
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\modules\ui.py", line 185, in f
    res = list(func(*args, **kwargs))
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\webui.py", line 57, in f
    res = func(*args, **kwargs)
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\modules\txt2img.py", line 48, in txt2img
    processed = process_images(p)
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\modules\processing.py", line 423, in process_images
    res = process_images_inner(p)
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\modules\processing.py", line 508, in process_images_inner
    uc = prompt_parser.get_learned_conditioning(shared.sd_model, len(prompts) * [p.negative_prompt], p.steps)
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\modules\prompt_parser.py", line 138, in get_learned_conditioning
    conds = model.get_learned_conditioning(texts)
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\repositories\stable-diffusion\ldm\models\diffusion\ddpm.py", line 558, in get_learned_conditioning
    c = self.cond_stage_model(c)
  File "D:\anaconda3\envs\novelai\lib\site-packages\torch\nn\modules\module.py", line 1190, in _call_impl
    return forward_call(*input, **kwargs)
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\modules\sd_hijack.py", line 338, in forward
    z1 = self.process_tokens(tokens, multipliers)
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\extensions\aesthetic-gradients\aesthetic_clip.py", line 202, in __call__
    z = self.process_tokens(remade_batch_tokens, multipliers)
  File "E:\workspace\02_Python\novalai\stable-diffusion-webui\modules\sd_hijack.py", line 353, in process_tokens
    outputs = self.wrapped.transformer(input_ids=tokens, output_hidden_states=-opts.CLIP_stop_at_last_layers)
  File "D:\anaconda3\envs\novelai\lib\site-packages\torch\nn\modules\module.py", line 1190, in _call_impl
    return forward_call(*input, **kwargs)
  File "D:\anaconda3\envs\novelai\lib\site-packages\transformers\models\clip\modeling_clip.py", line 722, in forward
    return self.text_model(
  File "D:\anaconda3\envs\novelai\lib\site-packages\torch\nn\modules\module.py", line 1190, in _call_impl
    return forward_call(*input, **kwargs)
  File "D:\anaconda3\envs\novelai\lib\site-packages\transformers\models\clip\modeling_clip.py", line 643, in forward
    encoder_outputs = self.encoder(
  File "D:\anaconda3\envs\novelai\lib\site-packages\torch\nn\modules\module.py", line 1190, in _call_impl
    return forward_call(*input, **kwargs)
  File "D:\anaconda3\envs\novelai\lib\site-packages\transformers\models\clip\modeling_clip.py", line 574, in forward
    layer_outputs = encoder_layer(
  File "D:\anaconda3\envs\novelai\lib\site-packages\torch\nn\modules\module.py", line 1190, in _call_impl
    return forward_call(*input, **kwargs)
  File "D:\anaconda3\envs\novelai\lib\site-packages\transformers\models\clip\modeling_clip.py", line 316, in forward
    hidden_states = self.layer_norm1(hidden_states)
  File "D:\anaconda3\envs\novelai\lib\site-packages\torch\nn\modules\module.py", line 1190, in _call_impl
    return forward_call(*input, **kwargs)
  File "D:\anaconda3\envs\novelai\lib\site-packages\torch\nn\modules\normalization.py", line 190, in forward
    return F.layer_norm(
  File "D:\anaconda3\envs\novelai\lib\site-packages\torch\nn\functional.py", line 2515, in layer_norm
    return torch.layer_norm(input, normalized_shape, weight, bias, eps, torch.backends.cudnn.enabled)
RuntimeError: "LayerNormKernelImpl" not implemented for 'Half'

考虑到--use-cpu参数可以指定模块,则尝试使工程中的部分模块用CPU计算,其余在可用内存方位内用GPU计算,最终构造参数如下,项目可成功作画。

然而,此方式作画效率非常低,一般每张图片约5-6分钟。当参数设置较大时,会达到数小时。因此如果有条件可以升级计算机的显卡配置,或租赁云服务器效果会更好。


(novelai) E:\workspace\02_Python\novalai\stable-diffusion-webui>python launch.py --lowram --always-batch-cond-uncond  --precision full --no-half --opt-split-attention-v1 --use-cpu sd --autolaunch
Python 3.10.6 | packaged by conda-forge | (main, Oct 24 2022, 16:02:16) [MSC v.1916 64 bit (AMD64)]
Commit hash: b8f2dfed3c0085f1df359b9dc5b3841ddc2196f0
Installing requirements for Web UI
Launching Web UI with arguments: --lowram --always-batch-cond-uncond --precision full --no-half --opt-split-attention-v1 --use-cpu sd
Warning: caught exception 'Expected a cuda device, but got: cpu', memory monitor disabled
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
making attention of type 'vanilla' with 512 in_channels
Working with z of shape (1, 4, 32, 32) = 4096 dimensions.
making attention of type 'vanilla' with 512 in_channels
Loading weights [7460a6fa] from E:\workspace\02_Python\novalai\stable-diffusion-webui\models\Stable-diffusion\sd-v1-4.ckpt
Global Step: 470000
Applying v1 cross attention optimization.
Model loaded.
Loaded a total of 0 textual inversion embeddings.
Embeddings:
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 20/20 [06:30<00:00, 19.50s/it]
Total progress: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████| 20/20 [06:10<00:00, 18.51s/it]

参考文献:

AI作画保姆级教程来了!逆天,太强了!

【作者:墨叶扶风http://blog.csdn.net/yefufeng】

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/406168.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

基于FPGA 的TDC设计更好的选择——易灵思Quantum架构FPGA

时间数据转换器(TDC)常被用于测量时间间隔&#xff0c;被广泛应用于飞行时间测量领域。分辨率是一个重要的参数&#xff0c;但TDC线性度将直接影响整个系统的精度。尤其是近年来迅猛增长的汽车自动驾驶&#xff08;ADAS&#xff09;领域&#xff0c;利用光测距的激光雷达&#…

GCN-图卷积神经网络算法简单实现(含python代码)

本文是就实现GCN算法模型进行的代码介绍&#xff0c;上一篇文章是GCN算法的原理和模型介绍。 代码中用到的Cora数据集&#xff1a; 链接&#xff1a;https://pan.baidu.com/s/1SbqIOtysKqHKZ7C50DM_eA 提取码&#xff1a;pfny 文章目录 目的 一、数据集介绍 二、实现过程讲…

[闪存 2.1] 闪存芯片物理结构与_SLC/MLC/TLC/QLC

固态硬盘(Solid State Drives),简称SSD。它是一种电脑存储设备,由闪存(FLASH)、 闪存控制器、高速缓存(DRAM)组成。这是是固态硬盘的三个基本部件,对性能有关键影响。 闪存芯片简介闪存颗粒是固态

MySQL数据库的基础语法总结(1)

MySql一.数据库,数据表的基本操作1.数据库的基本操作2. 数据表的基本操作2.1 数据库的数据类型2.1.1 整数类型2.1.2 浮点数类型和定点数类型2.1.3 字符串类型2.1.4 日期与时间类型2.2 数据表的基本操作2.2.1 创建一个数据表2.2.2 查看数据表2.2.3 查看表的基本信息的MySQL指令2…

设计模式(上)

目录 1.设计模式概述 1.什么是设计模式 2.学习设计模式的意义 3.23种设计模式 4.七大设计原则 2.创建者模式 1.单例模式 2.工厂模式 3.抽象工厂模式 4.建造者模式 5.原型模式 3.结构型模式 1.适配器模式 2.桥接模式 3.代理模式 4.组合模式 5.装饰模式 6.享元…

[架构之路-24]:目标系统 - 系统软件 - C语言的结构与程序的工作原理 - 程序控制、函数调用栈、函数调用性能优化

目录 前言&#xff1a; 第1章 结构化程序与分层编程系统 1.1 计算机软硬件模型 1.2 程序的经典框架&#xff1a;算法数据结构 1.3 程序的结构化框架 1.4 程序的层次模型 1.5 程序设计的层次模型 第2章 C语言概述 2.1 C语言本质 2.2 C语言关键字 2.3 C语言在编程语言的…

js算法 字母大小写转换

题目&#xff1a;输入字符串将大写转换成小写&#xff0c;小写转换成大写&#xff1f; js字母大小写转换方法&#xff1a; 1、转换成大写&#xff1a;toUpperCase() 2、转换成小写&#xff1a;toLowerCase()方法一&#xff1a;把输入的字符串转成数组用split&#xff08;&…

chatgpt 无法登录报错Access denied、OpenAl‘s services are not available in yourcountry. (error=unsupported )

一、主要解决有账号无法登录问题&#xff0c;共包含两种情况。 1、Oops! OpenAls services are not available in yourcountry.(errorunsupported country) 2、Access denied You do not have access to chat.openai.com. The site owner may have set restrictions that p…

Linux命令之nano命令

一、nano命令简介 nano是一个小型、免费、友好的编辑器&#xff0c;旨在取代非免费Pine包中的默认编辑器Pico。nano不仅复制了Pico的外观&#xff0c;还实现了Pico中一些缺失&#xff08;或默认禁用&#xff09;的功能&#xff0c;例如“搜索和替换”和“转到行号和列号”。nan…

Element Plus的el-tree-select组件,懒加载 + 数据回显

目录一、背景说明二、使用1. dom2.methods三、回显一、背景说明 技术&#xff1a;Vue3 Element Plus需求&#xff1a;在选择组织机构时以树结构下拉展示。用到组件&#xff1a;TreeSelect 树形选择组件&#xff08;el-tree-select&#xff09; 官网文档地址&#xff1a; ht…

Vue如何启动项目

文章目录 文章目录 前言 一、首先了解vue-cli脚手架 二、安装脚手架 三、启动项目 总结 前言 废话就不多说了&#xff0c;直接进入正题 一、首先了解vue-cli脚手架 vue-cli 是一个基于 Vue.js 进行快速开发的完整系统 vue-cli是 基于 webpack 构建 vue 前端模块工程环境webpa…

Vue.js介绍

目录 一、 Vue.js是什么 二、 Vue.js优点 三、 前提条件 四、 安装Vue 1. 直接用 script 标签 引入 2. 命令行工具 (CLI) 3. 其他方法或细节应用 五、声明式渲染 六、 理解什么是MVVM MVVM模式的组成部分 MVVM优点 一、 Vue.js是什么 Vue.js (vue读音 /vjuː/&am…

【CSS扩展】VUE如何使用或修改element plus中自带的CSS全局变量来定义样式

目录 一、CSS声明全局变量 二、使用el plus 和 el ui的自带样式 1、element plus—— var.scss位置 2、element ui—— var.scss位置 三、修改el plus 和 el ui中的自定义样式变量&#xff08;方法一致&#xff09; 本萌新最近在写网页时使用到了element plus中自带的CSS全…

Vue中如何解决跨域问题

跨域 跨域报错是前端开发中非常经典的一个错误&#xff0c;报错如下 Access to XMLHttpRequest at ...... from origin ...... has been blocked by CORS policy: No Access-Control-Allow-Origin header is present on the requested resource. 跨域错误源自于浏览器的同源…

《中秋佳节倍思亲》——2022年这场中秋

中秋佳夜&#xff0c;圆的是月&#xff0c;满的是情&#xff0c;但一人终究扛下离愁 作为一个杭漂者&#xff0c;虽不及北漂般艰难困苦&#xff0c;但也举步维艰啊&#xff01; 或许&#xff0c;这对我而言&#xff0c;正是一个别样的中秋&#xff0c;也正是一个值得我一生纪念…

多端统一开发解决方案---Taro

Taro 一套代码&#xff0c;多端运行&#xff0c;释放双手的摸鱼神器 文章目录Taro 一套代码&#xff0c;多端运行&#xff0c;释放双手的摸鱼神器1. 简介2. 准备工作2.1 安装及使用2.1.1 开发者工具2.1.2 tarojs2.1安装tarojs工具3. Taro 使用4.限制5.路由跳转汇总6.注意事项7.…

vue3:安装配置sass

目录 前言&#xff1a; 1. 安装sass 2. 新建style目录&#xff0c;存放scss文件 3. main.ts 4. vite.config.ts 5. Test.vue 前言&#xff1a; 对于前端开发人员来说&#xff0c;css预处理的语言已经是家常便饭了&#xff0c;如sass&#xff0c;less等等&#xff0c;那么…

深度学习实战 1 YOLOv5结合BiFPN

目录 1. BiFPN论文简介 2. 在Common.py中添加定义模块(Concat) 3. 将类名加入进去&#xff0c;修改yolo.py 4. 修改train.py 5. 修改配置文件yolov5.yaml 1. BiFPN论文简介 论文《EfficientDet: Scalable and Efficient Object Detection》地址&#xff1a;https://arxiv…

微信小程序云开发的具体使用教程

小程序云开发介绍 云开发官方文档 一个小程序在开发时&#xff0c;除了考虑界面功能逻辑外&#xff0c;还需要后端的数据支持。而为了获得后端的数据支持&#xff0c;开发者需要提前考虑服务器、存储和数据库等需求&#xff0c;并且会花费时间精力在部署应用、依赖上。因此官方…

【JavaScript 逆向】网易易盾滑块逆向分析

声明本文章中所有内容仅供学习交流&#xff0c;相关链接做了脱敏处理&#xff0c;若有侵权&#xff0c;请联系我立即删除&#xff01;案例目标验证码&#xff1a;aHR0cHM6Ly9kdW4uMTYzLmNvbS90cmlhbC9qaWdzYXc以上均做了脱敏处理&#xff0c;Base64 编码及解码方式&#xff1a;…