| 49 | |
| 50 | |
| 51 | class ImageVisualizer: |
| 52 | def __call__(self, *images) -> Image: |
| 53 | # images: list of tensors that is not normalized in shape of [b c h w] |
| 54 | images = [i for i in images if i is not None] # hack to exclude None (e.g. x0 is noise) |
| 55 | images = torch.stack(images) # [n b c h w] |
| 56 | images = einops.rearrange(images, 'n b c h w -> (b h) (n w) c') |
| 57 | images = images / 2 + 0.5 |
| 58 | images = images.cpu().numpy() |
| 59 | images = np.clip(images, 0, 1) |
| 60 | images = (images * 255).astype(np.uint8) |
| 61 | images = Image.fromarray(images) |
| 62 | return images |
| 63 | |
| 64 | |
| 65 | class T2IVisualizer: |
nothing calls this directly
no outgoing calls
no test coverage detected