johnowhitaker
commited on
Commit
·
8ebccbf
1
Parent(s):
1c8a416
Update README.md
Browse files
README.md
CHANGED
@@ -37,4 +37,26 @@ dataset_info:
|
|
37 |
---
|
38 |
# Dataset Card for "latent_lsun_church_128px"
|
39 |
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
---
|
38 |
# Dataset Card for "latent_lsun_church_128px"
|
39 |
|
40 |
+
Each image is cropped to 128px square and encoded to a 4x16x16 latent representation using the same VAE as that employed by Stable Diffusion
|
41 |
+
|
42 |
+
Decoding
|
43 |
+
```python
|
44 |
+
from diffusers import AutoencoderKL
|
45 |
+
from datasets import load_dataset
|
46 |
+
from PIL import Image
|
47 |
+
import numpy as np
|
48 |
+
import torch
|
49 |
+
# load the dataset
|
50 |
+
dataset = load_dataset('tglcourse/latent_lsun_church_128px')
|
51 |
+
# Load the VAE (requires access - see repo model card for info)
|
52 |
+
vae = AutoencoderKL.from_pretrained("CompVis/stable-diffusion-v1-4", subfolder="vae")
|
53 |
+
latent = torch.tensor([dataset['train'][0]['latent']]) # To tensor (bs, 4, 16, 16)
|
54 |
+
latent = (1 / 0.18215) * latent # Scale to match SD implementation
|
55 |
+
with torch.no_grad():
|
56 |
+
image = vae.decode(latent).sample[0] # Decode
|
57 |
+
image = (image / 2 + 0.5).clamp(0, 1) # To (0, 1)
|
58 |
+
image = image.detach().cpu().permute(1, 2, 0).numpy() # To numpy, channels lsat
|
59 |
+
image = (image * 255).round().astype("uint8") # (0, 255) and type uint8
|
60 |
+
image = Image.fromarray(image) # To PIL
|
61 |
+
image # The resulting PIL image
|
62 |
+
```
|