AI工具箱
Stable Diffusion初体验

Stable Diffusion 是一种文本到图像的潜在扩散模型,由CompVis、Stability AI和LAION的研究人员和工程师创建。它使用来自LAION-5B数据库子集的图像进行训练。

Stable Diffusion web UI是一个基于Gradio库的Stable Diffusion浏览器应用。基于这个web UI,我们可以很方便的基于各种模型进行文本到图片、图片到图片的生成工作。

那么接下来,就让我们一起来体验一下吧!

环境准备

安装Python

如果你的电脑还没有安装Python,可以通过以下链接下载安装包,也可以通过命令行直接安装。

https://www.python.org/downloads/ (opens in a new tab)
https://wiki.python.org/moin/BeginnersGuide/Download (opens in a new tab)

不同操作系统的一些参考命令

Mac: brew install python3

CentOS: yum install python3 python3-devel dnf install python3 python3-devel

Ubuntu: apt-get install python3 python3-dev

安装Git

Git的安装与配置,可以参考以下链接:

https://git-scm.com/downloads (opens in a new tab)
https://git-scm.com/book/en/v2/Getting-Started-Installing-Git (opens in a new tab)
https://training.github.com/downloads/github-git-cheat-sheet/ (opens in a new tab)
https://docs.github.com/en/get-started/quickstart/set-up-git (opens in a new tab)

Stable Diffusion web UI安装与使用

下载

Stable Diffusion web UI的github地址为:

https://github.com/AUTOMATIC1111/stable-diffusion-webui (opens in a new tab)

可以通过执行git clone命令,或者下载压缩包的方式下载代码:

git clone [email protected]:AUTOMATIC1111/stable-diffusion-webui.git

启动

进入stable-diffusion-webui目录,运行:

./webui.sh(Linux)或webui.bat(Windows)

第一次运行,需要等待比较长的时间来下载相关资源(依赖包、模型)。

默认会自动下载一个模型,输出内容如下:

Downloading: "https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors (opens in a new tab)" to /***/stable-diffusion-webui/models/Stable-diffusion/v1-5-pruned-emaonly.safetensors

启动成功后,在控制台将会看到以下提示:

Running on local URL: http://127.0.0.1:7860

体验生成一张图片

使用浏览器打开http://127.0.0.1:7860,即可看到以下webui界面:

界面的第二行有一个Tab菜单栏,默认选择的是txt2img类型。

1.在Prompt输入框输入

a beautiful girl

2.然后点击右边的Generate按钮

稍等片刻,在右下方将会生成一张训练出来的女孩的图片。

(满满的成就感)

参考

https://github.com/AUTOMATIC1111/stable-diffusion-webui (opens in a new tab)