patrickvonplaten
commited on
Commit
•
8594b43
1
Parent(s):
62f3958
add diffusers example
Browse files
README.md
CHANGED
@@ -60,6 +60,49 @@ The model is intended for research purposes only. Possible research areas and ta
|
|
60 |
|
61 |
Excluded uses are described below.
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
### Out-of-Scope Use
|
64 |
|
65 |
The model was not trained to be factual or true representations of people or events,
|
|
|
60 |
|
61 |
Excluded uses are described below.
|
62 |
|
63 |
+
### Diffusers
|
64 |
+
|
65 |
+
```
|
66 |
+
pip install diffusers transformers accelerate --upgrade
|
67 |
+
```
|
68 |
+
|
69 |
+
- **Text-to-image**:
|
70 |
+
|
71 |
+
SDXL-Turbo does not make use of `guidance_scale` or `negative_prompt`, we disable it with `guidance_scale=0.0`.
|
72 |
+
Preferably, the model generates images of size 512x512 but higher image sizes work as well.
|
73 |
+
A **single step** is enough to generate high quality images.
|
74 |
+
|
75 |
+
```py
|
76 |
+
from diffusers import AutoPipelineForText2Image
|
77 |
+
import torch
|
78 |
+
|
79 |
+
pipe = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16")
|
80 |
+
pipe.to("cuda")
|
81 |
+
|
82 |
+
prompt = "A cinematic shot of a baby racoon wearing an intricate italian priest robe."
|
83 |
+
|
84 |
+
image = pipe(prompt=prompt, num_inference_steps=1, guidance_scale=0.0).images[0]
|
85 |
+
```
|
86 |
+
|
87 |
+
- **Image-to-image**:
|
88 |
+
|
89 |
+
When using SDXL-Turbo for image-to-image generation, make sure that `num_inference_steps` * `strength` is larger or equal
|
90 |
+
to 1. The image-to-image pipeline will run for `int(num_inference_steps * strength)` steps, *e.g.* 0.5 * 2.0 = 1 step in our example
|
91 |
+
below.
|
92 |
+
|
93 |
+
```py
|
94 |
+
from diffusers import AutoPipelineForImage2Image
|
95 |
+
from diffusers.utils import load_image
|
96 |
+
|
97 |
+
pipe = AutoPipelineForImage2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16")
|
98 |
+
|
99 |
+
init_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png").resize((512, 512))
|
100 |
+
|
101 |
+
prompt = "cat wizard, gandalf, lord of the rings, detailed, fantasy, cute, adorable, Pixar, Disney, 8k"
|
102 |
+
|
103 |
+
image = pipe(prompt, image=init_image, num_inference_steps=2, strength=0.5, guidance_scale=0.0).images[0]
|
104 |
+
```
|
105 |
+
|
106 |
### Out-of-Scope Use
|
107 |
|
108 |
The model was not trained to be factual or true representations of people or events,
|