共计 2415 个字符,预计需要花费 7 分钟才能阅读完成。
Stable Diffusion 介绍
Stable Diffusion 是 2022 年发布的从文本到图像的生成模型,可以根据文字描述生成详细的图片。具有文生图,图生图等多种功能,另外我认为最重要的是可以在本地部署、训练自己的模型,让 AI 完全按照自己的想法生成目标风格的内容。这个东西是由 StabilityAI、CompVis 和 Runway 这三家公司合作开发的,得到了 EleutherAI 和 LAION 的支持。与以前的文本生成图像模型不同的是,Stable Diffusion 的代码和模型权重已经公开发布,可以在大多数硬件配置较好的电脑上都可以运行。
本文主要讲解在自己电脑上安装 Stable Diffusion 的过程,以及在该过程中所踩的坑。文末有惊喜~
Stable Diffusion 本地安装过程
本人电脑配置:Apple M1 pro 芯片 16g 内存 硬盘可用空间 350G+
电脑配置要求:Mac 电脑 M1 或者 M2 芯片 内存至少 8G 硬盘可用空间至少 10G
1. 安装 homebrew
打开电脑 terminal/ 终端在 terminal 内复制执行下面这段代码(官方版):
/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”
推荐 国内镜像版:
/bin/bash -c “$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)”
检测是否安装成功 homebrew,如果显示版本信息则安装成功
brew -v
2. 安装 Python
在 terminal/ 终端窗口运行:
brew install cmake protobuf rust python@3.10 git wget
3. 安装 stable-diffusion-webui
如果没有安装 git,先使用以下代码安装 git:
brew install git
然后使用 git 把 stable diffusion webui 的 github 开源程序全部克隆到自己的电脑本地,执行代码如下:
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
4. 下载 Stable Diffusion 绘画模型
这里以 Stable Diffusion 2.1 训练模型为例
下载网址:
https://huggingface.co/stabilityai/stable-diffusion-2-1
在该网站页面上点击 Files and Versions 跳转到新的页面,然后点击 v2-1_768-ema-pruned.ckpt 下载该模型,下好之后将其放在 Stable-diffusion-webui>Models>Stable-diffusion 文件夹里。
5. 运行 stable-diffusion-webui
在 terminal/ 终端窗口进入到 stable-diffusion-webui 目录里:
cd stable-diffusion-webui
然后执行 webui.sh 脚本:
./webui.sh
特别注意:这一步可能需要花费较长时间,因为会下载几个 sd 必需的应用,另外可能会发生各种问题:
问题 1:报错如下
ERROR: Could not find a version that satisfies the requirement torch==1.12.1 (from versions: none)
ERROR: No matching distribution found for torch==1.12.1
解决方法:
下载安装 Python 3.10.6 及以上版本
问题 2:报错如下
致命错误:无法访问 ‘git+https://github.com/openai/CLIP.git/’:The requested URL returned
致命错误:无法访问 ‘https://github.com/TencentARC/GFPGAN.git/’:HTTP/2 stream 1 was not
closed cleanly before end of the underlying stream
解决方法:
用访达 (finder) 打开 stable-diffusion-webui 文件夹,找到 launch.py 文件,用系统自带的文本编辑软件打开,搜索报错链接内容,比如:
git+https://github.com/openai/CLIP.git
然后在该链接前面 https://ghproxy.com/ 即可解决问题。加上 https://ghproxy.com/ 后以上链接变成:
git+https://ghproxy.com/https://github.com/openai/CLIP.git
问题 3:报错如下
RuntimeError: “LayerNormKernelImpl” not implemented for ‘Half’
解决方法:
在 stable-diffusion-webui 文件夹里面打开 webui-user.sh 文件,添加以下内容:
export COMMANDLINE_ARGS=”–skip-torch-cuda-test –precision full –no-half”
然后在运行以下代码:
./webui.sh –skip-torch-cuda-test –precision full –no-half
运行完毕后 显示:Running on local URL: http://127.0.0.1:7860 To create a public link, set `share=True` in `launch()`
在浏览器中打开 http://127.0.0.1:7860,即可运行 Stable Diffusion WebUI。
惊喜来了~ 以下图片来源于网络,完全由 Stable Diffusion 生成
