抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

CodingStudio

努力进步

引言

Stable Diffusion的食用指南


0 Windows安装

  1. 安装miniconda, 具体安装地址
    • 默认安装
    • 配置下载源
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      <!-- 1. 设置阿里源为默认源 -->
      pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
      <!-- 该源可解决tb-nightly的问题 -->

      <!-- 还原默认源 -->
      pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple

      <!-- 其他源 -->
      https://pypi.tuna.tsinghua.edu.cn/simple
      https://mirrors.aliyun.com/pypi/simple/
      https://mirrors.163.com/pypi/simple/
      https://pypi.douban.com/simple/
      https://mirror.baidu.com/pypi/simple/
      https://pypi.mirrors.ustc.edu.cn/simple/
      https://mirrors.huaweicloud.com/repository/pypi/simple/
      https://mirrors.cloud.tencent.com/pypi/simple/
    • 创建虚拟环境
      1
      conda create --name sd-webui python=3.10.6
    • 激活虚拟环境
      1
      conda activate sd-webui
  2. 安装git
  3. 安装cudacuDNN, 详见Windows深度学习环境配置
  4. git克隆Stable Diffusion WebUI项目至本地, 注意终端的地址为本地合适的地址
    1
    git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
  5. 进入项目文件夹,运行Stable Diffusion WebUI, 首次运行会安装对应的库
    1
    2
    3
    4
    5
    <!-- 切换目录 -->
    cd stable-diffusion-webui

    <!-- 运行 -->
    webui-user.bat
  6. 安装插件

1 Ubuntu安装

2 ControlNet使用方法

  • 部分模型说明
    • canny主要是边缘检测,属于比较通用的模型
    • Openpose就是传说中的姿势控制专用模型
    • Scribble是手稿模型,适合随手涂鸦然后生成一个精美的画面,可玩性高

3 Ubuntu调教

  • 在Ubuntu中可使用supervisord配置sd-webui进程实现开机自启动
    • 帮助命令
      1
      2
      3
      4
      5
      启动命令:supervisord ctl start stable-webui
      关闭命令:supervisord ctl stop stable-webui
      重启命令:supervisord ctl restart stable-webui
      查看状态:supervisord ctl status stable-webui
      查看日志:tail -f /var/log/stable-webui.log
    • 安装方式
      • 文件/etc/supervisor/conf.d/stable-webui.conf
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        <!-- 编辑文件 -->
        vim /etc/supervisor/conf.d/stable-webui.conf

        <!-- 文件内容 -->
        [program:stable-webui]
        command=/usr/local/miniconda3/bin/python3 launch.py --xformers --no-half-vae --listen --port 8080 --api --enable-insecure-extension-access --opt-channelslast --administrator
        process_name=%(program_name)s
        autorestart=true
        redirect_stderr=true
        stdout_logfile=/var/log/stable-webui.log,/dev/stdout
        stdout_events_enabled=true
        environment=SHELL=/bin/bash
        directory=/hy-tmp/stable-diffusion-webui/
        user=root
    • 设置 supervisord开机自启动
      1. cd /usr/lib/systemd/system/
      2. which supervisord, which supervisorctl,
      3. vi supervisord.service建立supervisord.service文件内容
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        15
        16
        #supervisord.service

        [Unit]
        Description=Supervisor daemon

        [Service]
        Type=forking
        ExecStart=/usr/local/bin/supervisord -c /etc/supervisord.conf
        ExecStop=/usr/local/bin/supervisorctl shutdown
        ExecReload=/usr/local/bin/supervisorctl reload
        KillMode=process
        Restart=on-failure
        RestartSec=42s

        [Install]
        WantedBy=multi-user.target
      4. 启动服务 systemctl enable supervisord, systemctl start supervisord
      5. 查看服务状态 systemctl status supervisord
      6. 验证是否开机自启动 systemctl is-enabled supervisord

4 模型下载

  • 国内使用镜像站下载

    • 推荐使用huggingface-cli进行下载
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      <!-- 安装依赖 python>3.8 -->
      pip install -U huggingface_hub hf-transfer

      <!-- Windows设置环境变量 -->
      setx HF_HUB_ENABLE_HF_TRANSFER 1
      setx HF_ENDPOINT https://hf-mirror.com

      <!-- Linux设置环境变量 -->
      export HF_HUB_ENABLE_HF_TRANSFER=1

      vim ~/.bashrc

      # 在打开文件中的最后一行添加
      export HF_ENDPOINT="https://hf-mirror.com"

      <!-- 下载模型 -->
      huggingface-cli download --token [访问令牌] --resume-download --local-dir-use-symlinks False [模型名] --local-dir [保存位置]

    • 使用git clone
      1
      2
      3
      4
      5
      6
      7
      8
      9
      <!-- 安装 git lfs -->
      git lfs install

      <!-- 直接git clone -->
      git clone ....

      <!-- 不下载大的文件配置方法 -->
      setx GIT_LFS_SKIP_SMUDGE 1
      export GIT_LFS_SKIP_SMUDGE=1
  • 推荐模型

    • SmilingWolf/wd-v1-4-vit-tagger-v2
    • SmilingWolf/wd-v1-4-swinv2-tagger-v2
    • SmilingWolf/wd-v1-4-vit-tagger
    • lllyasviel/ControlNet-v1-1
    • xyn-ai/anything-v4.0
    • stablediffusionapi/anything-v5
    • stablediffusionapi/anything-midjourney
    • Joeythemonster/anything-midjourney-v-4-1
    • gsdf/Counterfeit-V3.0
    • gsdf/Counterfeit-V2.5

5 注意事项

评论