AI 绘画工具 Stable Diffusion 本地安装使用教程

2023年 7月 11日 122.2k 0

最近要用到 AI 绘画,所以研究了下目前市面上的 AI 绘画工具,真可谓是琳琅满目,但主流的还是 Stable diffusion 和 Midjourney 两大阵营。

Midjourney 不多说,开箱即用,对新手非常友好,但不免费,Stable diffusion 相对 Midjourney 来说,专业性更强,不易上手,但更灵活,指哪打哪,模型生态丰富,最重要的是免费!

树先生总结了目前使用 Stable diffusion 的几种不同姿势,还没上车的朋友们快跟着我一起上车吧~

SD 镜像网站

推荐指数:★☆☆☆☆

适用人群:浅尝辄止地体验玩家

如果你只想浅尝辄止地体验一下 AI 绘画的魅力,可以考虑使用一些 SD 的在线网站,比如 DreamStudio,可免费生成 200 张图片,之后需要缴费,这类在线网站对生成的图片的调教功能偏弱,无法批量生成图片,体验着玩玩还行,不适合深度玩耍。

AI 绘画工具 Stable Diffusion 本地安装使用教程

云服务器

推荐指数:★★★★☆

适用人群:本地电脑无法运行 Stable diffusion 的玩家

如果你本地电脑不满足安装 Stable diffusion 的条件,可以考虑使用云服务器,现在很多云服务器厂商都自带了 Stable diffusion 的镜像,一键启动,非常方便,就是需要一些费用~

AI 绘画工具 Stable Diffusion 本地安装使用教程

准备工作

这里我们还是白嫖阿里云的机器学习 PAI 平台,使用 A10 显卡,这部分内容之前文章中有介绍。

【注意】:镜像选择选择官方镜像中的 stable-diffusion-webui-env:pytorch1.13-gpu-py310-cu117-ubuntu22.04

AI 绘画工具 Stable Diffusion 本地安装使用教程

项目部署

环境准备好了以后,就可以开始部署工作了。

【说明】:由于Github访问存在不稳定性,如果运行后未出现正常返回结果且提示网络相关原因,例如:Network is unreachableunable to access '``https://github.com/......',您可以重新运行命令。

下载源码

git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
cd stable-diffusion-webui
git checkout a9fed7c364061ae6efb37f797b6b522cb3cf7aa2
mkdir -p repositories && cd repositories
git clone https://github.com/sczhou/CodeFormer.git

下载常用插件

cd stable-diffusion-webui/extensions
git clone https://gitcode.net/mirrors/DominikDoom/a1111-sd-webui-tagcomplete.git
git clone https://gitcode.net/ranting8323/stable-diffusion-webui-localization-zh_CN
cd ..
wget -c http://pai-vision-data-sh.oss-cn-shanghai.aliyuncs.com/aigc-data/webui_config/config.json

下载 chilloutmix 大模型

cd stable-diffusion-webui/models/Stable-diffusion
wget -c https://huggingface.co/naonovn/chilloutmix_NiPrunedFp32Fix/resolve/main/chilloutmix_NiPrunedFp32Fix.safetensors -O chilloutmix_NiPrunedFp32Fix.safetensors

下载额外模型

cd stable-diffusion-webui/repositories/CodeFormer/weights/facelib
wget -c http://pai-vision-data-hz.oss-cn-zhangjiakou.aliyuncs.com/EasyCV/datasets/try_on/detection_Resnet50_Final.pth
wget -c http://pai-vision-data-hz.oss-cn-zhangjiakou.aliyuncs.com/EasyCV/datasets/try_on/parsing_parsenet.pth

mkdir -p stable-diffusion-webui/models/Codeformer
cd stable-diffusion-webui/models/Codeformer 
wget -c http://pai-vision-data-hz.oss-cn-zhangjiakou.aliyuncs.com/EasyCV/datasets/try_on/codeformer-v0.1.0.pth

cd stable-diffusion-webui/embeddings 
wget -c http://pai-vision-data-hz.oss-cn-zhangjiakou.aliyuncs.com/EasyCV/datasets/try_on/ng_deepnegative_v1_75t.pt

cd stable-diffusion-webui/models/Lora
wget -c https://huggingface.co/Kanbara/doll-likeness-series/resolve/main/koreanDollLikeness_v10.safetensors

启动服务

cd stable-diffusion-webui
python -m venv --system-site-packages --symlinks venv
sed -i 's/can_run_as_root=0/can_run_as_root=1/g' webui.sh
./webui.sh --no-download-sd-model --xformers

服务启动成功后,左键点击生成的 URL 即可跳转到 WebUI 前端。

AI 绘画工具 Stable Diffusion 本地安装使用教程

AI 绘画工具 Stable Diffusion 本地安装使用教程

生成第一张图片

# prompt
 
the best quality, ultra-high definition,masterpiece, extreme detail, 8K
1girl, curly hair, detail eyes and mouth, fair skin,big eyes,
white shirt, 
street
 
# negative prompt 
(worst quality:2), (low quality:2), (normal quality:2), lowres, ((monochrome)), ((grayscale)), bad anatomy,DeepNegative, skin spots, acnes, skin blemishes,(fat:1.2),facing away, looking away,tilted head, lowres,bad anatomy,bad hands, missing fingers,extra digit, fewer digits,bad feet,poorly drawn hands,poorly drawn face,mutation,deformed,extra fingers,extra limbs,extra arms,extra legs,malformed limbs,fused fingers,too many fingers,long neck,cross-eyed,mutated hands,polar lowres,bad body,bad proportions,gross proportions,missing arms,missing legs,extra digit, extra arms, extra leg, extra foot,teethcroppe,signature, watermark, username,blurry,cropped,jpeg artifacts,text,error,

AI 绘画工具 Stable Diffusion 本地安装使用教程

泰裤辣!

AI 绘画工具 Stable Diffusion 本地安装使用教程

本地安装

推荐指数:★★★★★

适用人群:本地电脑可以运行 Stable diffusion 的玩家

安装环境

要在本地顺利运行 Stable diffusion,需要满足如下条件:

  • 操作系统 win10 以上
  • 内存 8GB 以上
  • GPU 必须是 N 卡,显存 4GB 以上

以上是最基本的硬件配置。

安装 Python

Python 版本需要 3.10.6,Python 安装可以参考我之前写的这篇。

安装 CUDA

接下来安装 CUDA,CUDA是 Nvidia 显卡的 AI 运算库,Stable diffusion 通过这个库使用显卡资源。命令行输入nvidia-smi,查看自己显卡支持的版本。

AI 绘画工具 Stable Diffusion 本地安装使用教程

然后去 Nvidia CUDA 官网下载支持的版本。

AI 绘画工具 Stable Diffusion 本地安装使用教程

项目部署

下载源码

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

一键启动

这里使用 B 站秋葉的启动器,支持一键启动/修复/更新/模型下载管理,后台回复【qiuye】获取。

AI 绘画工具 Stable Diffusion 本地安装使用教程

运行启动器运行依赖安装依赖包,解压sd-webui启动器.zip,将解压后的文件复制到项目源代码目录下,最后运行A启动器启动项目。

AI 绘画工具 Stable Diffusion 本地安装使用教程

点击一键启动,耐心等待一段时间,直到看到下图代表启动成功。

AI 绘画工具 Stable Diffusion 本地安装使用教程

下载模型

细心的朋友会发现上图有报错,说是没找到 checkpoints,其实就是没有对应的大模型,我们回到秋葉的启动器,在模型管理中下载自己喜欢的大模型即可,也可以去 Civitai 网站下载。

AI 绘画工具 Stable Diffusion 本地安装使用教程

AI 绘画工具 Stable Diffusion 本地安装使用教程

耐心等待下载完成。。。

AI 绘画工具 Stable Diffusion 本地安装使用教程

刷新浏览器访问 http://127.0.0.1:7860 即可看到熟悉的界面。

AI 绘画工具 Stable Diffusion 本地安装使用教程

汉化

依次点击 Extensions --> Available --> Load from加载插件列表,在搜索框输入cn搜索语言包,点击安装

AI 绘画工具 Stable Diffusion 本地安装使用教程

下载完成后,选择 setting --> user interface --> localization,选择 zh_CN,点击 Apply settings 按钮应用设置,再点击 Reload UI 刷新页面。

AI 绘画工具 Stable Diffusion 本地安装使用教程

汉化成功~

生成第一张图片

# prompt
the best quality, ultra-high definition,masterpiece, extreme detail, 8K
1girl, curly hair, detail eyes and mouth, fair skin,big eyes,
white shirt, 
street
 
# negative prompt 
(worst quality:2), (low quality:2), (normal quality:2), lowres, ((monochrome)), ((grayscale)), bad anatomy,DeepNegative, skin spots, acnes, skin blemishes,(fat:1.2),facing away, looking away,tilted head, lowres,bad anatomy,bad hands, missing fingers,extra digit, fewer digits,bad feet,poorly drawn hands,poorly drawn face,mutation,deformed,extra fingers,extra limbs,extra arms,extra legs,malformed limbs,fused fingers,too many fingers,long neck,cross-eyed,mutated hands,polar lowres,bad body,bad proportions,gross proportions,missing arms,missing legs,extra digit, extra arms, extra leg, extra foot,teethcroppe,signature, watermark, username,blurry,cropped,jpeg artifacts,text,error,

AI 绘画工具 Stable Diffusion 本地安装使用教程

相关文章

班迪录屏怎么取消截图水印设置
班迪录屏怎么改存储位置
bandicam录制的视频默认存储在哪
网易云音乐电脑怎么设置播放器样式
酷狗音乐如何创建歌单
酷狗音乐如何单曲循环播放

发布评论