当前位置:   article > 正文

stable-diffusion-webui [Centos]安装记录_loading weights [dcd690123c] from e:\sd\stable-dif

loading weights [dcd690123c] from e:\sd\stable-diffusion-webui-master\models

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

本文记录于 2023-08-20,以下方法可能失效,请审慎参考

1. 安装

注意升级 git 到2.x版本 git --version
yum install zlib-devel + https://juejin.cn/post/7071910670056292389

https://zhuanlan.zhihu.com/p/639164507

2. 下载模型

https://huggingface.co/docs/huggingface_hub/main/en/guides/download

yum install git-lfs
git lfs install
  • 1
  • 2

python代码下载模型

https://huggingface.co/stabilityai/stable-diffusion-2-1/tree/main

# pip install huggingface_hub
from huggingface_hub import snapshot_download, hf_hub_download
snapshot_download(repo_id="stabilityai/stable-diffusion-2-1", cache_dir='/your_path/')
hf_hub_download(repo_id="stabilityai/stable-diffusion-2-1", filename="v2-1_768-ema-pruned.safetensors", cache_dir='/your_path/')
hf_hub_download(repo_id="runwayml/stable-diffusion-v1-5", filename="v1-5-pruned-emaonly.safetensors", cache_dir='/your_path/')
  • 1
  • 2
  • 3
  • 4
  • 5

3. 解决报错

  • ImportError: cannot import name 'rank_zero_only' from 'pytorch_lightning.utilities.distributed'

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

from pytorch_lightning.utilities.rank_zero import rank_zero_only 
  • 1
  • ImportError: cannot import name 'get_device' from 'basicsr.utils.misc'

https://github.com/sczhou/CodeFormer/issues/193

# basicsr\utils\misc.py
import torch
def get_device():
    if torch.cuda.is_available():
        return torch.device("cuda")
    else:
        return torch.device("cpu")

def gpu_is_available():
        return torch.cuda.is_available()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

4. UI 模式

Centos服务器部署的 SD

现在在本地windows使用cmd命令,进行端口转发

ssh-keygen -R ip
ssh -L 7860:localhost:7860 user@ip
  • 1
  • 2

或者 使用 mobaxterm 启动隧道 tunneling
在这里插入图片描述

  • 在服务器上启动 python launch.py
$ python launch.py 
Python 3.10.12 (main, Jul  5 2023, 18:54:27) [GCC 11.2.0]
Version: v1.5.1
Commit hash: 68f336bd994bed5442ad95bad6b6ad5564a5409a
Launching Web UI with arguments: 
No module 'xformers'. Proceeding without it.
Loading weights [dcd690123c] from /opt/bdp/stable-diffusion-webui/models/Stable-diffusion/models--stabilityai--stable-diffusion-2-1/snapshots/5cae40e6a2745ae2b01ad92ae5043f95f23644d6/v2-1_768-ema-pruned.safetensors
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
Startup time: 10.9s (launcher: 2.2s, import torch: 2.7s, import gradio: 0.9s, setup paths: 1.2s, other imports: 2.3s, load scripts: 0.7s, create ui: 0.6s, gradio launch: 0.2s).
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

然后在本地浏览器打开 http://localhost:7860/,即可使用远程的SD
在这里插入图片描述

5. API模式

https://zhuanlan.zhihu.com/p/629845245

  • sh webui.sh --nowebui --xformers
  • 或者 后台运行 nohup python launch.py --nowebui --xformers > nohup.out 2>&1 &
(sd) [web@bdp-measure3 stable-diffusion-webui]$ sh webui.sh --nowebui --xformers

################################################################
Install script for stable-diffusion + Web UI
Tested on Debian 11 (Bullseye)
################################################################

################################################################
Running on web user
################################################################

################################################################
Repo already cloned, using it as install directory
################################################################

################################################################
Create and activate python venv
################################################################

################################################################
Launching launch.py...
################################################################
Cannot locate TCMalloc (improves CPU memory usage)
Python 3.8.16 (default, Mar  2 2023, 03:21:46) 
[GCC 11.2.0]
Version: v1.5.1
Commit hash: 68f336bd994bed5442ad95bad6b6ad5564a5409a
Installing xformers
Launching API server with arguments: --nowebui --xformers
Loading weights [6ce0161689] from /opt/bdp/stable-diffusion-webui/models/Stable-diffusion/models--runwayml--stable-diffusion-v1-5/snapshots/c9ab35ff5f2c362e9e22fbafe278077e196057f0/v1-5-pruned-emaonly.safetensors
Startup time: 176.5s (launcher: 151.6s, import torch: 9.7s, import gradio: 2.4s, setup paths: 5.3s, other imports: 3.1s, setup codeformer: 0.2s, load scripts: 2.5s, reload hypernetworks: 0.1s, lora_script.py: 1.7s).
INFO:     Started server process [26450]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:7861 (Press CTRL+C to quit)
Creating model from config: /opt/bdp/stable-diffusion-webui/configs/v1-inference.yaml
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Applying attention optimization: xformers... done.
Model loaded in 158.2s (load weights from disk: 1.9s, create model: 19.9s, apply weights to model: 119.6s, apply half(): 15.2s, move model to device: 1.3s, calculate empty prompt: 0.3s).
INFO:     127.0.0.1:64184 - "GET /docs HTTP/1.1" 200 OK
INFO:     127.0.0.1:64184 - "GET /openapi.json HTTP/1.1" 200 OK
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42

进入 http://localhost:7861/docs 可以查看接口

在这里插入图片描述

import json
import base64
import requests


def submit_post(url: str, data: dict):
    return requests.post(url, data=json.dumps(data))


def save_encoded_image(b64_image: str, output_path: str):
    with open(output_path, 'wb') as image_file:
        image_file.write(base64.b64decode(b64_image))


if __name__ == '__main__':
    txt2img_url = r'http://127.0.0.1:7861/sdapi/v1/txt2img'

    data = {'prompt': 'an old chinese building near by the mountain, and sunset in the sky.',
            'negative_prompt': '',
            'sampler_index': 'DPM++ SDE',
            'seed': 1234,
            'steps': 20,
            'width': 512,
            'height': 512,
            'cfg_scale': 8}

    response = submit_post(txt2img_url, data)
    save_image_path = r'sd-test.png'
    save_encoded_image(response.json()['images'][0], save_image_path)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

给定提示词:an old chinese building near by the mountain, and sunset in the sky.
生成图片如下:
在这里插入图片描述

自定义Stable Diffusion扩展:https://www.jianshu.com/p/82709696f4aa

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/413111
推荐阅读
相关标签
  

闽ICP备14008679号