SD text prompt 文生图系列

import torch
from diffusers import StableDiffusionPipeline
model_id = "CompVis/stable-diffusion-v1-4"
device = "cuda"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipe = pipe.to(device)
# pipe.enable_attention_slicing()

prompt = "a photo of an astronaut riding a horse on mars"
image = pipe(prompt).images[0]
image.save("astronaut_rides_horse.png")

如果GPU显存空间有限,可用空间小于4GB,需要确保以float16精度加载StableDiffusionPipeline。

vae = AutoencoderKL.from_pretrained(
		"CompVis/stable-diffusion-v1-4",
		subfolder="vae",
		revision="ebb811dd71cdc38a204ecbdd6ac5d580f529fd8c")

latents = vae.encode(images)
images = vae.decode(latents).sample

你可能感兴趣的:(prompt,人工智能,深度学习)