当前位置: 首页 > 分享发现 > 在Windows系统上成功安装Easy Diffusion(Stable Diffusion)并实现AI生成艺术图像

在Windows系统上成功安装Easy Diffusion(Stable Diffusion)并实现AI生成艺术图像

发布于:2023-2-26 分享发现 10条评论 6,941 views
本站提供Linux服务器运维,自动化脚本编写等服务,如有需要请联系博主微信:xiaozme

最近AI绘图非常热门,尝试了一些网上的在线工具,但在线工具免费次数有限,若要获得更多的使用次数,所需付费的价格也并不低廉。xiaoz得知可以通过本地搭建“Stable Diffusion”来实现本机AI绘制“艺术图像”,这样就无需支付高额费用了,嘿嘿。

什么是Stable Diffusion

Stable Diffusion是由计算机科学家和艺术家一起开发的,它使用深度学习算法和稳定扩散过程来生成艺术图像。具体来说,它使用一种称为随机游走的算法来创建图像,这种算法通过对像素值进行微小的、随机的变化来模拟稳定扩散过程中的路径漫步。该算法还使用神经网络技术来学习并生成不同的图像风格。

Stable Diffusion可以生成非常美丽和复杂的艺术作品,其应用包括艺术创作、图像生成、视觉效果设计等。如果您对此感兴趣,可以通过在线搜索了解更多信息,或者尝试使用该工具进行艺术创作。

开始之前

在网上搜索了一下“Stable Diffusion”的搭建过程,结果发现这一过程十分复杂,看得我都想放弃了。就在我正准备放弃的时候,在Github上发现了一个名为“Easy Diffusion”的项目,它提供了一键安装Stable Diffusion所需的各种环境、模型等依赖,从而大大降低了安装难度。

本文旨在分享并记录xiaoz安装“Easy Diffusion”的过程,尽管这个工具简化了很多步骤,但安装仍然具有一定难度,推荐对计算机有一定了解的朋友尝试。

准备工作

  1. 可科学上网的TZ(能访问Github)
  2. 一台配置不太差的电脑,CPU和显卡配置越高越好(xiaoz的配置是AMD 3600 + RTX 3050勉强凑合)
  3. 听说过HTTP代理,了解HTTP代理如何使用(可将ss转为HTTP代理,请自行去研究)

下载Easy Diffusion

下载地址:https://github.com/cmdr2/stable-diffusion-ui/releases/download/v2.5.15/stable-diffusion-ui-windows.zip

后续的更新版本可以在这里查看:https://github.com/cmdr2/stable-diffusion-ui/releases

设置HTTP代理

Easy Diffusion会从国外网络下载大量的内容,比如Python环境、绘图模型等,国内网络访问困难或者几乎无法访问,因此我们需要让Windows的命令行可以科学上网才行。

打开你的CMD命令行,输入下面的命令设置HTTP代理:

set http_proxy=http://127.0.0.1:10809
set https_proxy=http://127.0.0.1:10809

http://127.0.0.1:10809为您的HTTP代理地址,如果您不清楚这是啥,建议直接放弃。

安装Easy Diffusion

将上面下载好的压缩包stable-diffusion-ui-windows.zip解压到任意一个目录。然后:

  1. 打开stable-diffusion-ui目录
  2. 双击运行Start Stable Diffusion UI.cmd这个脚本

接下来就是漫长的等待,可能会出现一些错误,我把我遇到的错误整理到了下方。

如果提示Python包下载超时:

HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.

可通过设置pip镜像源解决,Easy Diffusion会单独为您安装一个Python 3.8的环境,我们需要设置pip镜像源。下面的命令将Easy Diffusion的pip镜像源设置为了阿里云镜像:

cd D:\stable-diffusion-ui\installer_files\env\Scripts>
d:
pip.exe config set global.index-url https://mirrors.aliyun.com/pypi/simple/

如果遇到模型下载失败的提示错误,可以直接去Google或者Github搜索模型的名字下载,然后放到models的指定目录下即可。

我整理了部分模型下载地址:

Easy Diffusion安装遇到报错注意看报错提示信息,然后可以尝试通过上述办法手动解决,手动解决后重新运行Start Stable Diffusion UI.cmd脚本即可。

xiaoz在安装过程中遇到了Python包安装超时和模型下载错误的问题,通过上述方法已经成功手动解决了。每个人的情况不尽相同,建议灵活变通并在网上搜索解决方法。

运行Easy Diffusion

安装成功后会自动打开浏览器地址http://localhost:9000/看到WEB界面,接下来就可以根据你的喜好生成“艺术图像”啦,具体的一些使用方法xiaoz还在进一步研究,欢迎留言讨论。

取消HTTP代理

安装完毕后我们可以取消Windows命令行的HTTP代理了:

set http_proxy=
set https_proxy=

此文部分内容参考了:https://github.com/cmdr2/stable-diffusion-ui


发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注


已有10条评论


  1. 你好,在生成图像时,有以下错误:Error: Could not load the stable-diffusion model! Reason: Ran out of input。
    然后我去Start SelfTest,出现以下情况:11 specs, 7 failures
    Error during loading: Uncaught TypeError: Failed to execute ‘observe’ on ‘MutationObserver’: parameter 1 is not of type ‘Node’. in http://localhost:9000/plugins/core/Autoscroll.plugin.js?t=1689756567091 line 15
    Error during loading: Uncaught ReferenceError: editorModifierTagsList is not defined in http://localhost:9000/plugins/core/modifiers-toggle.plugin.js?t=1689756567091 line 23
    Error during loading: Uncaught TypeError: Cannot read properties of null (reading ‘lastElementChild’) in http://localhost:9000/plugins/core/tiled-image-download.plugin.js?t=1689756567091 line 31

  2. 您好,请问我安装的时候出现了这个:WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘ProxyError(‘Cannot connect to proxy.’, timeout(‘_ssl.c:1106: The handshake operation timed out’))’: /simple/sdkit/
    这是什么意思呢,怎么解决呢,我找了半天没找到解决办法

  3. Install dir: E:\EasyDiffusion\
    E:\EasyDiffusion\installer_files\env\Library\bin\git.exe
    git version 2.40.0.windows.1
    E:\EasyDiffusion\installer_files\env\Library\bin\conda.bat
    E:\EasyDiffusion\installer_files\env\Scripts\conda.exe
    conda 22.11.1

    “Easy Diffusion – v2”

    “Easy Diffusion’s git repository was already installed. Updating from main..”
    fatal: detected dubious ownership in repository at ‘E:/EasyDiffusion/sd-ui-files’
    ‘E:/EasyDiffusion/sd-ui-files’ is owned by:
    ‘S-1-5-32-544’
    but the current user is:
    ‘S-1-5-21-209254591-902328384-1615578707-500’
    To add an exception for this directory, call:

    git config –global –add safe.directory E:/EasyDiffusion/sd-ui-files
    fatal: detected dubious ownership in repository at ‘E:/EasyDiffusion/sd-ui-files’
    ‘E:/EasyDiffusion/sd-ui-files’ is owned by:
    ‘S-1-5-32-544’
    but the current user is:
    ‘S-1-5-21-209254591-902328384-1615578707-500’
    To add an exception for this directory, call:

    git config –global –add safe.directory E:/EasyDiffusion/sd-ui-files
    fatal: detected dubious ownership in repository at ‘E:/EasyDiffusion/sd-ui-files’
    ‘E:/EasyDiffusion/sd-ui-files’ is owned by:
    ‘S-1-5-32-544’
    but the current user is:
    ‘S-1-5-21-209254591-902328384-1615578707-500’
    To add an exception for this directory, call:

    git config –global –add safe.directory E:/EasyDiffusion/sd-ui-files
    493 File(s) copied
    1 file(s) copied.
    1 file(s) copied.
    1 file(s) copied.
    1 file(s) copied.
    1 file(s) copied.
    1 file(s) copied.
    1 file(s) copied.
    1 file(s) copied.
    A subdirectory or file tmp already exists.

    Hotfixed broken JSON file from OpenAI
    “torch and torchvision have already been installed.”
    “sdkit is already installed.”

    我的启动提示这个,也没跳出WEB页面

  4. 你好,安装成功了,但是在使用面部修复时出错:
    File “G:\EasyDiffusion\ui\easydiffusion\task_manager.py”, line 333, in thread_render
    model_manager.reload_models_if_necessary(renderer.context, task.task_data)
    File “G:\EasyDiffusion\ui\easydiffusion\model_manager.py”, line 119, in reload_models_if_necessary
    action_fn(context, model_type, scan_model=False) # we’ve scanned them already
    File
    “G:\EasyDiffusion\installer_files\env\lib\site-packages\sdkit\models\model_loader\__init__.py”, line
    25, in load_model
    context.models = models.load_model(context, **kwargs)
    File “G:\EasyDiffusion\installer_files\env\lib\site-packages\sdkit\models\model_loader\gfpgan.py”,
    line 15, in load_model
    return GFPGANer(
    File “G:\EasyDiffusion\installer_files\env\lib\site-packages\gfpgan\utils.py”, line 79, in
    __init__
    self.face_helper = FaceRestoreHelper(
    File
    “G:\EasyDiffusion\installer_files\env\lib\site-packages\facexlib\utils\face_restoration_helper.py”,
    line 103, in __init__
    self.face_parse = init_parsing_model(model_name=’parsenet’, device=self.device,
    model_rootpath=model_rootpath)
    File “G:\EasyDiffusion\installer_files\env\lib\site-packages\facexlib\parsing\__init__.py”, line
    20, in init_parsing_model
    load_net = torch.load(model_path, map_location=lambda storage, loc: storage)
    File “G:\EasyDiffusion\installer_files\env\lib\site-packages\torch\serialization.py”, line 795, in
    load
    return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
    File “G:\EasyDiffusion\installer_files\env\lib\site-packages\torch\serialization.py”, line 1020,
    in _legacy_load
    typed_storage._storage._set_from_file(
    RuntimeError: unexpected EOF, expected 182161 more bytes. The file might be corrupted.

    10:25:32.667 INFO cuda:0 Session 1681611921995 task 2990767779456 failed! task_manager.py:355

    1. 我也是时不时的会出现一些错误,然后重启下脚本就好了,你可以试试,如果还是不行的话可以去Github上反馈下。