Stable Diffusion in action
In this section, you will learn how to use Stable Diffusion in action. This is done via the utilization of diffusers and transformers and is very easy and convenient.
In order to use Stable Diffusion in the easiest way, you first need to install the following libraries:
pip install diffusers transformers accelerate safetensors
diffusers
is the library we will use to load Stable Diffusion models:
import torch from diffusers import ( StableDiffusionPipeline, DPMSolverMultistepScheduler) model_id = "stabilityai/stable-diffusion-2-1" pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16) pipe.scheduler = DPMSolverMultistepScheduler.from_config( pipe.scheduler.config) pipe = pipe.to("cuda")
Now your pipeline is ready and you can easily use it:
prompt = " hyperrealistic portrait of unicorn" image = pipe(prompt).images...