stable diffusion v1及v2版本 本地部署方法、踩坑

v1版本: 确保你至少有12G显存

git:

GitHub - CompVis/stable-diffusion: A latent text-to-image diffusion modelhttps://github.com/CompVis/stable-diffusion

git clone https://github.com/CompVis/stable-diffusion.git

进入到你下载的路径

conda env create -f environment.yaml
conda activate ldm

模型下载地址:CompVis/stable-diffusion-v-1-4-original · Hugging FaceWe’re on a journey to advance and democratize artificial intelligence through open source and open science.https://huggingface.co/CompVis/stable-diffusion-v-1-4-original

stable diffusion v1及v2版本 本地部署方法、踩坑_第1张图片

两个文件随便下载一个就可以。重命名为model.ckpt,保存到\stable-diffusion\models\ldm\stable-diffusion-v1 目录下面

运行:

python scripts/txt2img.py --prompt "a photograph of an astronaut riding a horse

提示:

Traceback (most recent call last):
  File "scripts/txt2img.py", line 22, in
    from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker
  File "C:\Users\x\.conda\envs\ldm\lib\site-packages\diffusers\__init__.py", line 27, in
    from .pipelines import OnnxRuntimeModel
  File "C:\Users\x\.conda\envs\ldm\lib\site-packages\diffusers\pipelines\__init__.py", line 18, in
    from .dance_diffusion import DanceDiffusionPipeline
  File "C:\Users\x\.conda\envs\ldm\lib\site-packages\diffusers\pipelines\dance_diffusion\__init__.py", line 1, in
    from .pipeline_dance_diffusion import DanceDiffusionPipeline
  File "C:\Users\x\.conda\envs\ldm\lib\site-packages\diffusers\pipelines\dance_diffusion\pipeline_dance_diffusion.py", line 21, in
    from ..pipeline_utils import AudioPipelineOutput, DiffusionPipeline
  File "C:\Users\x\.conda\envs\ldm\lib\site-packages\diffusers\pipelines\pipeline_utils.py", line 64, in
    from transformers.utils import SAFE_WEIGHTS_NAME as TRANSFORMERS_SAFE_WEIGHTS_NAME
ImportError: cannot import name 'SAFE_WEIGHTS_NAME' from 'transformers.utils' (C:\Users\x\.conda\envs\ldm\lib\site-packages\transformers\utils\__init__.py)

这个确实很坑,默认里diffusers版本太高

解决方法:

conda list 查看diffusers版本,为0.14.0.

将这个删掉,

 pip uninstall diffusers

重新安装0.12.1版本

pip install diffusers==0.12.1

或者在创建环境时直接修改 environments.yaml, "diffusers" --> "diffusers==0.12.1"

如果提示:TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。

网络问题,多试几次就好。

如果提示RuntimeError: CUDA out of memory.,加个参数 --n_samples 1

---------------------------------

 

V2版本地址:GitHub - Stability-AI/stablediffusion: High-Resolution Image Synthesis with Latent Diffusion Modelsicon-default.png?t=N176https://github.com/Stability-AI/stablediffusion

 模型下载地址:

stabilityai/stable-diffusion-2-1 · Hugging Faceicon-default.png?t=N176https://huggingface.co/stabilityai/stable-diffusion-2-1

你可能感兴趣的:(python,stable,diffusion,ai)