赞
踩
- from diffusers import DiffusionPipeline
- import torch
-
-
- pipe = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
- pipe = pipe.to("mps")
-
- # Recommended if your computer has < 64 GB of RAM
- pipe.enable_attention_slicing()
-
-
- prompt = "便利店开业"
- # First-time "warmup" pass if PyTorch version is 1.13 (see explanation above)
- _ = pipe(prompt, num_inference_steps=1)
-
- images = pipe(prompt=prompt).images[0]
- images.save("output1.png")
Hugging Face 平台提供了基础模型权重以及通用的模型训练框架 diffusers
参考
How to use Stable Diffusion in Apple Silicon (M1/M2)
- from diffusers import StableDiffusionXLPipeline
- import torch
-
- # pipe = StableDiffusionXLPipeline.from_pretrained(
- # "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
- # )
- pipe = StableDiffusionXLPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0")
-
- # pipe.to("cuda")
- pipe = pipe.to("mps")
- # Recommended if your computer has < 64 GB of RAM
- pipe.enable_attention_slicing()
-
- prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
- # First-time "warmup" pass if PyTorch version is 1.13 (see explanation above)
- _ = pipe(prompt, num_inference_steps=1)
- image = pipe(prompt=prompt).images[0]
-
- image.save("sdxl.png")
https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/stable_diffusion_xl
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。