AI painting tool Stable Diffusion local installation and use

Recently, I want to use AI painting, so I studied the current AI painting tools on the market, which can be described as a dazzling array, but the mainstream is still the two camps of Stable diffusion and Midjourney.

Not much to say about Midjourney, it works out of the box and is very friendly to novices, but it is not free. Compared with Midjourney, Stable diffusion is more professional and difficult to use, but it is more flexible. It's free!

Mr. Shu summed up several different postures of using Stable diffusion at present. Friends who have not gotten on the car, please follow me to get on the car~

SD mirror site

Recommended Index: ★☆☆☆☆

Applicable people: Experience players with a taste

If you just want to experience the charm of AI painting briefly, you can consider using some SD online websites, such as DreamStudio, which can generate 200 pictures for free, and you need to pay later. These online websites have weak adjustment functions for the generated pictures. Unable to generate pictures in batches, it’s okay to experience and play, but not suitable for in-depth play.

Cloud Server

Recommended index: ★★★★☆

Applicable people: players whose local computer cannot run Stable diffusion

If your local computer does not meet the conditions for installing Stable diffusion, you can consider using a cloud server. Now many cloud server manufacturers have their own images of Stable diffusion. One-click startup is very convenient, but it requires some fees~

Preparation

Here we are still using Alibaba Cloud's machine learning PAI platform for free, using the A10 graphics card, which was introduced in the previous article.

Deploy an open source large model MOSS for free

[Note]: Mirror selection select stable-diffusion-webui-env:pytorch1.13-gpu-py310-cu117-ubuntu22.04 in the official mirror

project deployment

After the environment is ready, the deployment can begin.

[Note]: Due to the instability of Github access, if there is no normal return result after running and prompts for network-related reasons, for example: , Network is unreachable, unable to access '``https://github.com/......'you can run the command again.

download source code

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

Download common plug-ins

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 前端。

生成第一张图片

# prompt
<lora:koreanDollLikeness_v10:1> 
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,

泰裤辣!

本地安装

推荐指数:★★★★★

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

安装环境

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

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

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

安装 Python

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

【保姆级】Python最新版开发环境搭建,看这一篇就够了

安装 CUDA

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

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

项目部署

下载源码

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

一键启动

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

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

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

下载模型

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

耐心等待下载完成。。。

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

汉化

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

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

汉化成功~

生成第一张图片

# 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,

好了,就到这里,Stable diffusion 的玩法很多,这里只是最基本的文生图功能,就已经很强大了,其他的就交给你们自己去探索吧。

Guess you like

Origin juejin.im/post/7246960365736345660