Skip to content

Commit 234e90c

Browse files
[Docs] Using diffusers (open-mmlab#428)
* [Docs] Using diffusers * up
1 parent f6fb328 commit 234e90c

File tree

5 files changed

+56
-60
lines changed

5 files changed

+56
-60
lines changed

docs/source/using-diffusers/conditional_image_generation.mdx

-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express o
1010
specific language governing permissions and limitations under the License.
1111
-->
1212

13-
14-
1513
# Conditional Image Generation
1614

1715
The [`DiffusionPipeline`] is the easiest way to use a pre-trained diffusion system for inference

docs/source/using-diffusers/custom.mdx

+2-19
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,6 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express o
1010
specific language governing permissions and limitations under the License.
1111
-->
1212

13+
# Custom Pipeline
1314

14-
15-
# Quicktour
16-
17-
Start using Diffusers🧨 quickly!
18-
To start, use the [`DiffusionPipeline`] for quick inference and sample generations!
19-
20-
```
21-
pip install diffusers
22-
```
23-
24-
## Main classes
25-
26-
### Models
27-
28-
### Schedulers
29-
30-
### Pipeliens
31-
32-
15+
Under construction 🚧

docs/source/using-diffusers/img2img.mdx

+24-10
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,37 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express o
1010
specific language governing permissions and limitations under the License.
1111
-->
1212

13+
# Text-Guided Image-to-Image Generation
1314

15+
The [`StableDiffusionImg2ImgPipeline`] lets you pass a text prompt and an initial image to condition the generation of new images.
1416

15-
# Quicktour
17+
```python
18+
from torch import autocast
19+
import requests
20+
from PIL import Image
21+
from io import BytesIO
1622

17-
Start using Diffusers🧨 quickly!
18-
To start, use the [`DiffusionPipeline`] for quick inference and sample generations!
23+
from diffusers import StableDiffusionImg2ImgPipeline
1924

20-
```
21-
pip install diffusers
22-
```
25+
# load the pipeline
26+
device = "cuda"
27+
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
28+
"CompVis/stable-diffusion-v1-4", revision="fp16", torch_dtype=torch.float16, use_auth_token=True
29+
).to(device)
2330

24-
## Main classes
31+
# let's download an initial image
32+
url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
2533

26-
### Models
34+
response = requests.get(url)
35+
init_image = Image.open(BytesIO(response.content)).convert("RGB")
36+
init_image = init_image.resize((768, 512))
2737

28-
### Schedulers
38+
prompt = "A fantasy landscape, trending on artstation"
2939

30-
### Pipeliens
40+
with autocast("cuda"):
41+
images = pipe(prompt=prompt, init_image=init_image, strength=0.75, guidance_scale=7.5).images
3142

43+
images[0].save("fantasy_landscape.png")
44+
```
45+
You can also run this example on colab [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/patil-suraj/Notebooks/blob/master/image_2_image_using_diffusers.ipynb)
3246

docs/source/using-diffusers/inpaint.mdx

+28-10
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,41 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express o
1010
specific language governing permissions and limitations under the License.
1111
-->
1212

13+
# Text-Guided Image-Inpainting
1314

15+
The [`StableDiffusionInpaintPipeline`] lets you edit specific parts of an image by providing a mask and text prompt.
1416

15-
# Quicktour
17+
```python
18+
from io import BytesIO
1619

17-
Start using Diffusers🧨 quickly!
18-
To start, use the [`DiffusionPipeline`] for quick inference and sample generations!
20+
from torch import autocast
21+
import requests
22+
import PIL
23+
24+
from diffusers import StableDiffusionInpaintPipeline
1925

20-
```
21-
pip install diffusers
22-
```
2326

24-
## Main classes
27+
def download_image(url):
28+
response = requests.get(url)
29+
return PIL.Image.open(BytesIO(response.content)).convert("RGB")
2530

26-
### Models
2731

28-
### Schedulers
32+
img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
33+
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
2934

30-
### Pipeliens
35+
init_image = download_image(img_url).resize((512, 512))
36+
mask_image = download_image(mask_url).resize((512, 512))
3137

38+
device = "cuda"
39+
pipe = StableDiffusionInpaintPipeline.from_pretrained(
40+
"CompVis/stable-diffusion-v1-4", revision="fp16", torch_dtype=torch.float16, use_auth_token=True
41+
).to(device)
42+
43+
prompt = "a cat sitting on a bench"
44+
with autocast("cuda"):
45+
images = pipe(prompt=prompt, init_image=init_image, mask_image=mask_image, strength=0.75).images
46+
47+
images[0].save("cat_on_bench.png")
48+
```
3249

50+
You can also run this example on colab [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/patil-suraj/Notebooks/blob/master/in_painting_with_stable_diffusion_using_diffusers.ipynb)

docs/source/using-diffusers/loading.mdx

+2-19
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,6 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express o
1010
specific language governing permissions and limitations under the License.
1111
-->
1212

13+
# Loading
1314

14-
15-
# Quicktour
16-
17-
Start using Diffusers🧨 quickly!
18-
To start, use the [`DiffusionPipeline`] for quick inference and sample generations!
19-
20-
```
21-
pip install diffusers
22-
```
23-
24-
## Main classes
25-
26-
### Models
27-
28-
### Schedulers
29-
30-
### Pipeliens
31-
32-
15+
Under construction 🚧

0 commit comments

Comments
 (0)