🎨 Stable Diffusion public release
The Stable Diffusion checkpoints are now public and can be loaded by anyone! 🥳
Make sure to accept the license terms on the model page first (requires login): https://huggingface.co/CompVis/stable-diffusion-v1-4
Install the required packages: pip install diffusers==0.2.3 transformers scipy
And log in on your machine using the huggingface-cli login
command.
from torch import autocast
from diffusers import StableDiffusionPipeline, LMSDiscreteScheduler
# this will substitute the default PNDM scheduler for K-LMS
lms = LMSDiscreteScheduler(
beta_start=0.00085,
beta_end=0.012,
beta_schedule="scaled_linear"
)
pipe = StableDiffusionPipeline.from_pretrained(
"CompVis/stable-diffusion-v1-4",
scheduler=lms,
use_auth_token=True
).to("cuda")
prompt = "a photo of an astronaut riding a horse on mars"
with autocast("cuda"):
image = pipe(prompt)["sample"][0]
image.save("astronaut_rides_horse.png")
The safety checker
Following the model authors' guidelines and code, the Stable Diffusion inference results will now be filtered to exclude unsafe content. Any images classified as unsafe will be returned as blank. To check if the safety module is triggered programmaticaly, check the nsfw_content_detected
flag like so:
outputs = pipe(prompt)
image = outputs
if any(outputs["nsfw_content_detected"]):
print("Potential unsafe content was detected in one or more images. Try again with a different prompt and/or seed.")
Improvements and bugfixes
- add add_noise method in LMSDiscreteScheduler, PNDMScheduler by @patil-suraj in #227
- hotfix for pdnm test by @natolambert in #220
- Restore
is_modelcards_available
in.utils
by @pcuenca in #224 - Update README for 0.2.3 release by @pcuenca in #225
- Pipeline to device by @pcuenca in #210
- fix safety check by @patil-suraj in #217
- Add safety module by @patil-suraj in #213
- Support one-string prompts and custom image size in LDM by @anton-l in #212
- Add
is_torch_available
,is_flax_available
by @anton-l in #204 - Revive
make quality
by @anton-l in #203 - [StableDiffusionPipeline] use default params in call by @patil-suraj in #196
- fix test_from_pretrained_hub_pass_model by @patil-suraj in #194
- Match params with official Stable Diffusion lib by @apolinario in #192
Full Changelog: v0.2.2...v0.2.3