# How to get intermeidate output images

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-get-intermeidate-output-images%2F29144%3E%5C
**Category:** 🧨 Diffusers\
**Created:** [January 7, 2023, 11:49pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-get-intermeidate-output-images%2F29144 "2023-01-07T23:49:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkackman](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/dkackman/32/56859_2.png) [@dkackman](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdkackman)%5C
**Post date:** [January 7, 2023, 11:49pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-get-intermeidate-output-images%2F29144%2F1 "2023-01-07T23:49:56Z")

</div>

Is it possible to get the images at each denoising step via the Diffusers library? I am sure I’ve seen it done but can’t find where or how.

---

<div class="post-metadata">

**Author:** ![pcuenq](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/pcuenq/32/32135_2.png) [@pcuenq](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fpcuenq)%5C
**Post date:** [January 8, 2023, 11:34am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-get-intermeidate-output-images%2F29144%2F2 "2023-01-08T11:34:39Z")

</div>

Hi @dkackman!

You might want to look at the _callback mechanism_, which sends intermediate latents to a function you specify. You could then decode the latents in that function and visualize them as you need.

[This notebook includes a section about callbacks](https://github.com/fastai/diffusion-nbs/blob/master/stable_diffusion.ipynb) that demonstrates how to use that feature.

Good luck!

---

<div class="post-metadata">

**Author:** ![dkackman](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/dkackman/32/56859_2.png) [@dkackman](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdkackman)%5C
**Post date:** [January 8, 2023, 5:53pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-get-intermeidate-output-images%2F29144%2F3 "2023-01-08T17:53:34Z")

</div>

Oh perfect. I was unclear on how to transform the latents into an image but this exactly what iI was looking for.

```python
vae = pipe.vae
images = []

def latents_callback(i, t, latents):
    latents = 1 / 0.18215 * latents
    image = vae.decode(latents).sample[0]
    image = (image / 2 + 0.5).clamp(0, 1)
    image = image.cpu().permute(1, 2, 0).numpy()
    images.extend(pipe.numpy_to_pil(image))

prompt = "Portrait painting of Jeremy Howard looking happy."
torch.manual_seed(9000)
final_image = pipe(prompt, callback=latents_callback, callback_steps=12).images[0]
images.append(final_image)
image_grid(images, rows=1, cols=len(images))

```

---

<div class="post-metadata">

**Author:** ![venkatesh-thiru](https://avatars.discourse-cdn.com/v4/letter/v/a587f6/32.png) [@venkatesh-thiru](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fvenkatesh-thiru)%5C
**Post date:** [March 17, 2025, 5:55pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-get-intermeidate-output-images%2F29144%2F4 "2025-03-17T17:55:44Z")

</div>

Whats with the scaling in `latents = 1 / 0.18215 * latents`? is it a constant for every VAE? can I still apply the same callback for SD3.5?

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [March 18, 2025, 6:02am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-get-intermeidate-output-images%2F29144%2F5 "2025-03-18T06:02:32Z")

</div>

I think the same method can be used for the Diffusers pipeline.

### Pipeline callbacks

> **[Pipeline callbacks](https://huggingface.co/docs/diffusers/using-diffusers/callback)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

### Explanation of the 0.18215 factor in textual\_inversion?

> <https://github.com/huggingface/diffusers/issues/437>
>
> https://github.com/huggingface/diffusers/blob/b2b3b1a8ab83b020ecaf32f45de3ef2364…4331cf/examples/textual\_inversion/textual\_inversion.py#L501
> 
> Hi, just a small question about the quoted script above which is bothering me: where does this \`0.18215\` number come from? What computation is being done? Is it from some paper? I have seen the same factor elsewhere, too, without explanation. Any guidance would be very helpful, thanks!
