Skip to content

Commit

Permalink
[Docs] Using diffusers (open-mmlab#428)
Browse files Browse the repository at this point in the history
* [Docs] Using diffusers

* up
  • Loading branch information
patrickvonplaten authored Sep 8, 2022
1 parent f6fb328 commit 234e90c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 60 deletions.
2 changes: 0 additions & 2 deletions docs/source/using-diffusers/conditional_image_generation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express o
specific language governing permissions and limitations under the License.
-->



# Conditional Image Generation

The [`DiffusionPipeline`] is the easiest way to use a pre-trained diffusion system for inference
Expand Down
21 changes: 2 additions & 19 deletions docs/source/using-diffusers/custom.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,6 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express o
specific language governing permissions and limitations under the License.
-->

# Custom Pipeline


# Quicktour

Start using Diffusers🧨 quickly!
To start, use the [`DiffusionPipeline`] for quick inference and sample generations!

```
pip install diffusers
```

## Main classes

### Models

### Schedulers

### Pipeliens


Under construction 🚧
34 changes: 24 additions & 10 deletions docs/source/using-diffusers/img2img.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,37 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express o
specific language governing permissions and limitations under the License.
-->

# Text-Guided Image-to-Image Generation

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

# Quicktour
```python
from torch import autocast
import requests
from PIL import Image
from io import BytesIO

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

```
pip install diffusers
```
# load the pipeline
device = "cuda"
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
"CompVis/stable-diffusion-v1-4", revision="fp16", torch_dtype=torch.float16, use_auth_token=True
).to(device)

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

### Models
response = requests.get(url)
init_image = Image.open(BytesIO(response.content)).convert("RGB")
init_image = init_image.resize((768, 512))

### Schedulers
prompt = "A fantasy landscape, trending on artstation"

### Pipeliens
with autocast("cuda"):
images = pipe(prompt=prompt, init_image=init_image, strength=0.75, guidance_scale=7.5).images

images[0].save("fantasy_landscape.png")
```
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)

38 changes: 28 additions & 10 deletions docs/source/using-diffusers/inpaint.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,41 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express o
specific language governing permissions and limitations under the License.
-->

# Text-Guided Image-Inpainting

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

# Quicktour
```python
from io import BytesIO

Start using Diffusers🧨 quickly!
To start, use the [`DiffusionPipeline`] for quick inference and sample generations!
from torch import autocast
import requests
import PIL

from diffusers import StableDiffusionInpaintPipeline

```
pip install diffusers
```

## Main classes
def download_image(url):
response = requests.get(url)
return PIL.Image.open(BytesIO(response.content)).convert("RGB")

### Models

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

### Pipeliens
init_image = download_image(img_url).resize((512, 512))
mask_image = download_image(mask_url).resize((512, 512))

device = "cuda"
pipe = StableDiffusionInpaintPipeline.from_pretrained(
"CompVis/stable-diffusion-v1-4", revision="fp16", torch_dtype=torch.float16, use_auth_token=True
).to(device)

prompt = "a cat sitting on a bench"
with autocast("cuda"):
images = pipe(prompt=prompt, init_image=init_image, mask_image=mask_image, strength=0.75).images

images[0].save("cat_on_bench.png")
```

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)
21 changes: 2 additions & 19 deletions docs/source/using-diffusers/loading.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,6 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express o
specific language governing permissions and limitations under the License.
-->

# Loading


# Quicktour

Start using Diffusers🧨 quickly!
To start, use the [`DiffusionPipeline`] for quick inference and sample generations!

```
pip install diffusers
```

## Main classes

### Models

### Schedulers

### Pipeliens


Under construction 🚧

0 comments on commit 234e90c

Please sign in to comment.