stable-diffusion AI 绘画

kyaa111 1年前 ⋅ 368 阅读
  1. git clone
  2. 进入stable-diffusion目录
  3. 在这里注册一个账号: 并生成个token
  4. 安装CUDA
  5. pip install torch -f
  6. pip install -e git+
  7. conda install torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia 选择合适的pytorch-cuda版本
  8. pip install transformers==4.25.1 diffusers invisible-watermark
  9. pip install -e .
  10. huggingface-cli login 输入生成的token
from torch import autocast
from diffusers import StableDiffusionPipeline
import torch

if __name__ == '__main__':
    torch.backends.cudnn.benchmark = True
    torch.backends.cudnn.enabled = True

    pipe = StableDiffusionPipeline.from_pretrained(

    prompt = "a photo of an astronaut riding a horse on mars"
    with autocast("cuda"):
        result = pipe(prompt, height=256, width=256)

    image = result[0][0]"test.png")