当前位置:首页|资讯|Stable Diffusion|AI绘画|人工智能|机器学习

AMD卡启动Stable Diffusion AI绘画的方法(干货教程)

作者:我要刷牙发布时间:2023-02-26

因为一直想学会怎么用AI画(炼)画(金),这两天研究清楚了怎么在自家电脑上跑Stable Diffusion。作为一个机器学习、人工智能的外行(略懂),我想从自己的经验,用和我同样的人能听懂的方式,讲一讲如何在本地搭建Stable Diffusion。希望大家都能创作出自己心仪的画作。


Stable Diffusion各组分的关系

Stable Diffusion是算法本身,本质上是一个python包。

Stable Diffusion WebUI是使用该算法的图形化界面。不借助WebUI也可以使用Stable Diffusion,但是要写python程序。图形界面中,最普及的是AUTOMATIC1111。当然网络上也有各式社区成员提供的自己写的WebUI,本质上功能都是一样的。但AUTOMATIC1111用的人多,能找到的信息多,功能全面,而且眼下更新速度很快。


在有了算法和图形化界面之后,你需要给算法提供一个模型。这个模型决定了画出来的画风是什么样子的,例如NovelAI就是Stable Diffusion的一个二次元向的模型。

ckpt文件是Stable Diffusion模型的文件格式,下载后,放置在根目录下的model文件夹里的,stable diffusion子文件夹里面。不同的模型是在不同的数据集上训练出来的。例如Waifu Diffusion是在Danbooru动漫图片库中训练出来的,训练的tag就是数据库中社区成员们贡献的tag。Danbooru的健全版是Safebooru。

有的模型使用safetensor文件,可以和ckpt文件一样使用,一样也放到model文件夹里的stable diffusion子文件夹里面。


vae是variable autoencoder的意思。在Stable Diffusion WebUI的settings里面,stable diffusion那一栏,有一个“SD VAE”,在这里可以选择载入vae组分。使用vae组分可以让图片的色彩变得更好。

安装Stable Diffusion以及WebUI


基本的AMD卡安装方法在这里:

https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Install-and-Run-on-AMD-GPUs

Automatic1111的GitHub页面在这里:

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


Mac/Linux+AMD 安装法:

  1. 安装python 3.10.6。如果是anaconda,先用conda create -n <环境名> python=3.10.6设置一个python 3.10.6的虚拟环境,然后activate这个环境。环境名你可以叫sd(stable diffusion)

  2. 安装git(https://git-scm.com/)

  3. ***重要*** 打开webui-user.sh文件进行编辑,找到export COMMANDLINE_ARGS这一行,在后面写上"--precision full --no-half --skip-torch-cuda-test"

  4. 在命令行运行webui.sh

  5. 安装完成

启动Stable Diffusion:

  1. cd到stable diffusion的根目录

  2. activate python 3.10.6的环境

  3. 运行:python launch.py --precision full --no-half --skip-torch-cuda-test --opt-split-attention-v1

  4. 复制shell里面显示的本地网址,在浏览器里面打开就可以了

  5. 如果发现内存不够,在启动launch.py时加上--medvram 或者 --lowvram

Windows+AMD安装法

  1. 安装python 3.10.6,在python官网上下载安装程序,***重要*** 在安装的第一个窗口下方勾选“将python添加到path”。

  2. 安装git

  3. Windows+AMD使用AUTOMATIC1111的directml这一个fork,在这个页面的第一段:https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Install-and-Run-on-AMD-GPUs

  4. ***重要*** 下载github上的文件后,进入网站上的repositories文件夹,下载这个文件夹里的k-diffusion和stable-diffusion-stability-ai两个文件夹,移动到本地repositories文件夹里面的位置。

  5. 运行webui-user.bat

  6. 安装完成

启动Stable Diffusion:

  1. 在命令提示符中cd到Stable Diffusion所在的根目录

  2. 运行python launch.py --precision full --no-half --opt-split-attention-v1

  3. 复制shell里面显示的本地网址,在浏览器里面打开就可以了

  4. 如果发现内存不够,在启动launch.py时加上--medvram or --lowvram

Diffusion模型

安装好以后,需要下载至少一个模型进行画图。这里附上几个好用的模型链接,都是开源的。

CompVis Stable Diffusion v-1-4(默认):https://huggingface.co/CompVis/stable-diffusion-v-1-4-original

我知道你们想要的是什么!——

Waifu Diffusion:https://huggingface.co/hakurei/waifu-diffusion-v1-4/tree/main

DosMix:https://civitai.com/models/6250/dosmix 

    DosMix的二次元版:https://civitai.com/models/6437/anidosmix

    DosMix的三次元版(非常真实!):https://civitai.com/models/6925/realdosmix


VAE(改善色彩,放在/model/VAE下面,在WebUI的Settings->Stable Diffusion->SD VAE中启用):

    MSE:https://huggingface.co/stabilityai/sd-vae-ft-mse-original/blob/main/vae-ft-mse-840000-ema-pruned.ckpt

    kl-f8-anime2:https://huggingface.co/hakurei/waifu-diffusion-v1-4/blob/main/vae/kl-f8-anime2.ckpt

DosMix必须要使用VAE,不然看起来图片是灰灰的,色彩不够。

测试

完成安装后,可以使用以下tag进行测试:

模型 Waifu Diffusion 2


Positive prompt:masterpiece, best quality, 1girl, green hair, sweater, looking at viewer, upper body, beanie, outdoors, watercolor, night, turtleneck

Negative prompt: longbody, lowres, bad anatomy, bad hands, cropped, low quality, worst quality

Steps: 20, Sampler: Euler a, CFG scale: 7, Seed: 2114573465, Size: 512x512, Model hash: c76e0962bc, Model: wd-1-4-anime_e2

(官方示例prompt)green hair, sweater, looking at viewer, upper body, beanie, outdoors, watercolor, night, turtleneck

Positive prompt: masterpiece, best quality, 1girl, black semi-long, black hair, swimsuit, white bikini, looking at viewer, upper body, beach, seaside, blue sky, outdoors, sandy beach

Negative prompt: longbody, lowres, bad anatomy, bad hands, cropped, low quality, worst quality

Steps: 20, Sampler: Euler a, CFG scale: 7, Seed: 3616288369, Size: 512x512, Model hash: c76e0962bc, Model: wd-1-4-anime_e2

black semi-long, black hair, swimsuit, white bikini, looking at viewer, upper body, beach, seaside, blue sky, outdoors, sandy beach

Positive prompt: masterpiece, best quality, 1girl, pink pajama, beige hair, bob hair, sister, bedroom, morning, sunlight, window, indoors, upper body, selfie, imouto, brown eyes, fluffy

Negative prompt: longbody, lowres, bad anatomy, bad hands, extra digit, fewer digits, missing fingers, cropped, low quality, worst quality

Steps: 20, Sampler: Euler a, CFG scale: 7, Seed: 3065561171, Size: 512x512, Model hash: c76e0962bc, Model: wd-1-4-anime_e2

pink pajama, beige hair, bob hair, sister, bedroom, morning, sunlight, window, indoors, upper body, selfie, imouto, brown eyes, fluffy

Positive prompt: masterpiece, best quality, 1girl, watercolor, highschool girl, black hair, bob hair, brown eyes, looking up, sailor uniform, rainy, bluish grey background, blurry background, upper body

Negative prompt: longbody, lowres, bad anatomy, bad hands, extra digit, fewer digits, missing fingers, cropped, low quality, worst quality, detailed background, large breast, wet clothes

Steps: 20, Sampler: Euler a, CFG scale: 7, Seed: 1693703419, Size: 512x512, Model hash: c76e0962bc, Model: wd-1-4-anime_e2

highschool girl, black hair, bob hair, brown eyes, looking up, sailor uniform, rainy, bluish grey background, blurry background, upper body; Negative: large breast, wet clothes

祝大家好运!


Copyright © 2024 aigcdaily.cn  北京智识时代科技有限公司  版权所有  京ICP备2023006237号-1