git clone https://github.com/CompVis/stable-diffusion.git
- 进入stable-diffusion目录
- 在这里注册一个账号: Hugging Face – The AI community building the future. 并生成个token
- 安装CUDA NVIDIA 安装 CUDA_nvidia cuda_长满头发的程序猿的博客-CSDN博客
pip install torch -f https://download.pytorch.org/whl/torch_stable.html
pip install -e git+ https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers
-
conda install torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia
选择合适的pytorch-cuda
版本 pip install transformers==4.25.1 diffusers invisible-watermark
pip install -e .
-
huggingface-cli login
输入生成的token
from torch import autocast
from diffusers import StableDiffusionPipeline
import torch
if __name__ == '__main__':
# https://github.com/CompVis/stable-diffusion/issues/69#issuecomment-1260722801
torch.backends.cudnn.benchmark = True
torch.backends.cudnn.enabled = True
pipe = StableDiffusionPipeline.from_pretrained(
"CompVis/stable-diffusion-v1-4",
torch_dtype=torch.float16,
use_auth_token=True,
safety_checker=None,
requires_safety_checker=False
).to("cuda")
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]
image.save("test.png")
文章来源地址https://www.toymoban.com/news/detail-541408.html
文章来源:https://www.toymoban.com/news/detail-541408.html
到了这里,关于stable-diffusion AI 绘画的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!