Skip to content

Commit 3c1b493

Browse files
authored
Changed code that converts tensors to PIL images in the write_your_own_pipeline notebook (huggingface#4489)
changed code that converts tensors to PIL images
1 parent e731ae0 commit 3c1b493

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

docs/source/en/using-diffusers/write_own_pipeline.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ This is the entire denoising process, and you can use this same pattern to write
9494
>>> from PIL import Image
9595
>>> import numpy as np
9696

97-
>>> image = (input / 2 + 0.5).clamp(0, 1)
98-
>>> image = image.cpu().permute(0, 2, 3, 1).numpy()[0]
99-
>>> image = Image.fromarray((image * 255).round().astype("uint8"))
97+
>>> image = (input / 2 + 0.5).clamp(0, 1).squeeze()
98+
>>> image = (image.permute(1, 2, 0) * 255).round().to(torch.uint8).cpu().numpy()
99+
>>> image = Image.fromarray(image)
100100
>>> image
101101
```
102102

@@ -267,11 +267,11 @@ with torch.no_grad():
267267
Lastly, convert the image to a `PIL.Image` to see your generated image!
268268

269269
```py
270-
>>> image = (image / 2 + 0.5).clamp(0, 1)
271-
>>> image = image.detach().cpu().permute(0, 2, 3, 1).numpy()
270+
>>> image = (image / 2 + 0.5).clamp(0, 1).squeeze()
271+
>>> image = (image.permute(1, 2, 0) * 255).to(torch.uint8).cpu().numpy()
272272
>>> images = (image * 255).round().astype("uint8")
273-
>>> pil_images = [Image.fromarray(image) for image in images]
274-
>>> pil_images[0]
273+
>>> image = Image.fromarray(image)
274+
>>> image
275275
```
276276

277277
<div class="flex justify-center">

0 commit comments

Comments
 (0)