三款无需GPU的StableDiffusion生图工具对比

前言

在之前的[使用笔记本电脑搭建本地LLMs大模型环境]我们尝试去搭建了一套无需GPU即可运行的大模型环境。今天我们再来看看三款同样无需GPU(同样支持GPU加速)就能运行的StableDiffusion的使用效果如何。本文演示全部在windows环境下,linux下可自行参考项目地址中的说明。

(1)StableDiffusion webui

从它的名字就可以看出这个项目是自带webui页面的,而且安装和使用也相当的简单,是三款生图工具中最简单一款了,也是大家用最多的一款。

首先确保你的电脑中已经安装了python以及git环境。(注意:python一定要是3.10.6版本的,较高的版本很有可能安装会失败)

git clone项目

windows环境下修改webui-user.bat

@echo off``   ``set PYTHON=``set GIT=``set VENV_DIR=``set COMMANDLINE_ARGS=--use-cpu all --no-half --precision full --skip-torch-cuda-test``   ``call webui.bat

linux环境下修改webui-user.sh

本文中在windows环境下运行.bat文件,然后就会执行程序并自动下载项目所依赖的文件,比如torch,torchvision等,下载模型过程需要使用代理才能下载。如果下载模型文件失败,也可以自动手工下载然后放到/models/Stable-diffusion目录下,我这里下载的是v1-5-pruned-emaonly.safetensors大小是3.97G。

启动成功后,会看到后端提示我本机没有GPU,然后加载模型文件,监听端口7860。

本文涉及模型、插件下载请扫描免费获取哦

在这里插入图片描述

浏览器打开http://127.0.0.1:7860就可以看到页面如下:

接下来在checkpoint下载好的模型,输入prompt text点击generate等待生图。

这里可以的看到sd webui生图时间大概在3分钟左右。我此时选择采样器为Euler a(三款都选择此采样器进行对比),不同的采样器生图时长不同。

**(2)Stable Diffusion cpp

它是用c和c++改写的。没有过多的依赖,其构建也十分的简单。我这里使用docker的方式。

首先git clone项目

构建docker镜像

docker build -t sd .

运行docker

docker run -v /path/to/models:/models -v /path/to/output/:/output sd -m /models/v1-5-pruned-emaonly.safetensors -p "a lovely cat" -v -o /output/output.png

sd cpp需要命令行的方式启动,它的参数如下表

usage: ./bin/sd [arguments]``   ``arguments:`  `-h, --help                         show this help message and exit`  `-M, --mode [MODEL]                 run mode (txt2img or img2img or convert, default: txt2img)`  `-t, --threads N                    number of threads to use during computation (default: -1).`                                     `If threads <= 0, then threads will be set to the number of CPU physical cores`  `-m, --model [MODEL]                path to model`  `--vae [VAE]                        path to vae`  `--taesd [TAESD_PATH]               path to taesd. Using Tiny AutoEncoder for fast decoding (low quality)`  `--control-net [CONTROL_PATH]       path to control net model`  `--embd-dir [EMBEDDING_PATH]        path to embeddings.`  `--stacked-id-embd-dir [DIR]        path to PHOTOMAKER stacked id embeddings.`  `--input-id-images-dir [DIR]        path to PHOTOMAKER input id images dir.`  `--normalize-input                  normalize PHOTOMAKER input id images`  `--upscale-model [ESRGAN_PATH]      path to esrgan model. Upscale images after generate, just RealESRGAN_x4plus_anime_6B supported by now.`  `--upscale-repeats                  Run the ESRGAN upscaler this many times (default 1)`  `--type [TYPE]                      weight type (f32, f16, q4_0, q4_1, q5_0, q5_1, q8_0)`                                     `If not specified, the default is the type of the weight file.`  `--lora-model-dir [DIR]             lora model directory`  `-i, --init-img [IMAGE]             path to the input image, required by img2img`  `--control-image [IMAGE]            path to image condition, control net`  `-o, --output OUTPUT                path to write result image to (default: ./output.png)`  `-p, --prompt [PROMPT]              the prompt to render`  `-n, --negative-prompt PROMPT       the negative prompt (default: "")`  `--cfg-scale SCALE                  unconditional guidance scale: (default: 7.0)`  `--strength STRENGTH                strength for noising/unnoising (default: 0.75)`  `--style-ratio STYLE-RATIO          strength for keeping input identity (default: 20%)`  `--control-strength STRENGTH        strength to apply Control Net (default: 0.9)`                                     `1.0 corresponds to full destruction of information in init image`  `-H, --height H                     image height, in pixel space (default: 512)`  `-W, --width W                      image width, in pixel space (default: 512)`  `--sampling-method {euler, euler_a, heun, dpm2, dpm++2s_a, dpm++2m, dpm++2mv2, lcm}`                                     `sampling method (default: "euler_a")`  `--steps  STEPS                     number of sample steps (default: 20)`  `--rng {std_default, cuda}          RNG (default: cuda)`  `-s SEED, --seed SEED               RNG seed (default: 42, use random seed for < 0)`  `-b, --batch-count COUNT            number of images to generate.`  `--schedule {discrete, karras}      Denoiser sigma schedule (default: discrete)`  `--clip-skip N                      ignore last layers of CLIP network; 1 ignores none, 2 ignores one layer (default: -1)`                                     `<= 0 represents unspecified, will be 1 for SD1.x, 2 for SD2.x`  `--vae-tiling                       process vae in tiles to reduce memory usage`  `--control-net-cpu                  keep controlnet in cpu (for low vram)`  `--canny                            apply canny preprocessor (edge detection)`  `-v, --verbose                      print extra info

使用默认的配置选项,可以看到采样器也是用的euler a,cfg_scale同样是7,steps为20,seed为42与sd webui保持一致。

可以看到后台也是cpu执行,生图用时400多秒,7分多钟(可以看到默认用的weigth type f32,如果想缩短时间可以把weigth type设置为f16)。

出图的效果

(3)Stable Diffusion ncnn

ncnn需要4个模型文件可以到这里下载:

https://mmdeploy-oss.openmmlab.com/sdk/stablediffusion_ncnn-9ed842.zip

全部解压文件到/assets目录中。

设置\Stable-Diffusion-NCNN\x86\exe里面的magic.txt值

512 --height``512 --width``1 -- 0 low raw, 1 high ram``20 --step``42  -- seeds` `1234.jpg --init image` `floating hair, portrait, ((loli)), ((one girl)), cute face, hidden hands, asymmetrical bangs, beautiful detailed eyes, eye shadow, hair ornament, ribbons, bowties, buttons, pleated skirt, (((masterpiece))), ((best quality)), colorful  --positive prompt` `((part of the head)), ((((mutated hands and fingers)))), deformed, blurry, bad anatomy, disfigured, poorly drawn face, mutation, mutated, extra limb, ugly, poorly drawn hands, missing limb, blurry, floating limbs, disconnected limbs, malformed hands, blur, out of focus, long neck, long body, Octane renderer, lowres, bad anatomy, bad hands, text --negative prompt

然后运行stable-diffusion.exe。

或者此工具还有一个ui前端在\Stable-Diffusion-NCNN\Windows\Binary\x64目录中运行stablediffusion.exe界面如下出图效果

由于sd ncnn框架使用Naifu模型,所以看到的是动画类的图片。出图时间大概100秒,由于模型较小,可以说是三个工具中速度最快的。

总结:

sd webui体验感最好,更加贴近商业化使用场景,可自由调整控制的参数也很多,而且还可以集成很多的第三方插件进一步优化出图效果。

资源利用率方面,cpu和内存占用比较平均,出图速度一般。

sd cpp可以看作是sd webui命令行方式的,对普通用户不像sd webui来的那么舒服直接,好处就是不需要安装过多的依赖包。

资源利用率方面,cpu占用较高,内存比较平均,出图速度较慢。

sd cpp是一个为手机端优化过的高性能神经网络推理计算框架,所以这个工具是可以部署在手机端运行的,这是它相较于前两个工具最大的优势。

资源利用率方面,cpu和内存占用较高,出图速度快。

最后下面看几张其他的出图效果:

这里分享给大家一份Adobe大神整理的《AIGC全家桶学习笔记》,相信大家会对AIGC有着更深入、更系统的理解。

有需要的朋友,可以点击下方免费领取!

在这里插入图片描述

AIGC所有方向的学习路线思维导图

这里为大家提供了总的路线图。它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。如果下面这个学习路线能帮助大家将AI利用到自身工作上去,那么我的使命也就完成了:
在这里插入图片描述

AIGC工具库

AIGC工具库是一个利用人工智能技术来生成应用程序的代码和内容的工具集合,通过使用AIGC工具库,能更加快速,准确的辅助我们学习AIGC
在这里插入图片描述

有需要的朋友,可以点击下方卡片免费领取!

在这里插入图片描述

精品AIGC学习书籍手册

书籍阅读永不过时,阅读AIGC经典书籍可以帮助读者提高技术水平,开拓视野,掌握核心技术,提高解决问题的能力,同时也可以借鉴他人的经验,结合自身案例融会贯通。

在这里插入图片描述

AI绘画视频合集

我们在学习的时候,往往书籍源码难以理解,阅读困难,这时候视频教程教程是就很适合了,生动形象加上案例实战,科学有趣才能更方便的学习下去。

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值