Commit
•
0904434
1
Parent(s):
42d246e
Add diffusers examples (#3)
Browse files- Add diffusers examples (c2126d1346b4e1e863d90396142d087146d7f881)
Co-authored-by: Suraj Patil <valhalla@users.noreply.huggingface.co>
README.md
CHANGED
@@ -14,7 +14,7 @@ The model is trained from scratch 550k steps at resolution `256x256` on a subset
|
|
14 |
![image](https://github.com/Stability-AI/stablediffusion/blob/main/assets/stable-samples/txt2img/merged-0003.png?raw=true)
|
15 |
|
16 |
- Use it with the [`stablediffusion`](https://github.com/Stability-AI/stablediffusion) repository: download the `512-base-ema.ckpt` [here](https://huggingface.co/stabilityai/stable-diffusion-2-base/resolve/main/512-base-ema.ckpt).
|
17 |
-
- Use it with 🧨 diffusers
|
18 |
|
19 |
## Model Details
|
20 |
- **Developed by:** Robin Rombach, Patrick Esser
|
@@ -33,6 +33,36 @@ The model is trained from scratch 550k steps at resolution `256x256` on a subset
|
|
33 |
year = {2022},
|
34 |
pages = {10684-10695}
|
35 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
# Uses
|
38 |
|
@@ -152,4 +182,4 @@ Based on that information, we estimate the following CO2 emissions using the [Ma
|
|
152 |
pages = {10684-10695}
|
153 |
}
|
154 |
|
155 |
-
*This model card was written by: Robin Rombach, Patrick Esser and David Ha and is based on the [Stable Diffusion v1](https://github.com/CompVis/stable-diffusion/blob/main/Stable_Diffusion_v1_Model_Card.md) and [DALL-E Mini model card](https://huggingface.co/dalle-mini/dalle-mini).*
|
|
|
14 |
![image](https://github.com/Stability-AI/stablediffusion/blob/main/assets/stable-samples/txt2img/merged-0003.png?raw=true)
|
15 |
|
16 |
- Use it with the [`stablediffusion`](https://github.com/Stability-AI/stablediffusion) repository: download the `512-base-ema.ckpt` [here](https://huggingface.co/stabilityai/stable-diffusion-2-base/resolve/main/512-base-ema.ckpt).
|
17 |
+
- Use it with 🧨 [`diffusers`](https://huggingface.co/stabilityai/stable-diffusion-2-base#model-details#Examples)
|
18 |
|
19 |
## Model Details
|
20 |
- **Developed by:** Robin Rombach, Patrick Esser
|
|
|
33 |
year = {2022},
|
34 |
pages = {10684-10695}
|
35 |
}
|
36 |
+
|
37 |
+
|
38 |
+
## Examples
|
39 |
+
|
40 |
+
Using the [🤗's Diffusers library](https://github.com/huggingface/diffusers) to run Stable Diffusion 2 in a simple and efficient manner.
|
41 |
+
|
42 |
+
```bash
|
43 |
+
pip install --upgrade git+https://github.com/huggingface/diffusers.git transformers accelerate scipy
|
44 |
+
```
|
45 |
+
Running the pipeline (if you don't swap the scheduler it will run with the default PNDM/PLMS scheduler, in this example we are swapping it to EulerDiscreteScheduler):
|
46 |
+
|
47 |
+
```python
|
48 |
+
from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
|
49 |
+
|
50 |
+
model_id = "stabilityai/stable-diffusion-2-base"
|
51 |
+
|
52 |
+
# Use the Euler scheduler here instead
|
53 |
+
scheduler = EulerDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")
|
54 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, revision="fp16", torch_dtype=torch.float16)
|
55 |
+
pipe = pipe.to("cuda")
|
56 |
+
|
57 |
+
prompt = "a photo of an astronaut riding a horse on mars"
|
58 |
+
image = pipe(prompt).images[0]
|
59 |
+
|
60 |
+
image.save("astronaut_rides_horse.png")
|
61 |
+
```
|
62 |
+
|
63 |
+
**Notes**:
|
64 |
+
- Despite not being a dependency, we highly recommend you to install [xformers](https://github.com/facebookresearch/xformers) for memory efficient attention (better performance)
|
65 |
+
- If you have low GPU RAM available, make sure to add a `pipe.enable_attention_slicing()` after sending it to `cuda` for less VRAM usage (to the cost of speed)
|
66 |
|
67 |
# Uses
|
68 |
|
|
|
182 |
pages = {10684-10695}
|
183 |
}
|
184 |
|
185 |
+
*This model card was written by: Robin Rombach, Patrick Esser and David Ha and is based on the [Stable Diffusion v1](https://github.com/CompVis/stable-diffusion/blob/main/Stable_Diffusion_v1_Model_Card.md) and [DALL-E Mini model card](https://huggingface.co/dalle-mini/dalle-mini).*
|