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

git:

GitHub – CompVis/stable-diffusion: A latent text-to-image diffusion modelCompVis/stable-diffusion-v-1-4-original · Hugging FaceWe’re on a journey to advance and democratize artificial intelligence through open source and open science.

两个文件随便下载一个就可以。重命名为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 Modelshttps://github.com/Stability-AI/stablediffusion

模型下载地址:

stabilityai/stable-diffusion-2-1 · Hugging Facehttps://huggingface.co/stabilityai/stable-diffusion-2-1