johnowhitaker
commited on
Commit
·
eac45f7
1
Parent(s):
24e6903
Update README.md
Browse files
README.md
CHANGED
@@ -21,4 +21,26 @@ dataset_info:
|
|
21 |
---
|
22 |
# Dataset Card for "latent_afhqv2_512px"
|
23 |
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
---
|
22 |
# Dataset Card for "latent_afhqv2_512px"
|
23 |
|
24 |
+
Each image is cropped to 512px square and encoded to a 4x64x64 latent representation using the same VAE as that employed by Stable Diffusion
|
25 |
+
|
26 |
+
Decoding
|
27 |
+
```python
|
28 |
+
from diffusers import AutoencoderKL
|
29 |
+
from datasets import load_dataset
|
30 |
+
from PIL import Image
|
31 |
+
import numpy as np
|
32 |
+
import torch
|
33 |
+
# load the dataset
|
34 |
+
dataset = load_dataset('tglcourse/latent_lsun_church_256px')
|
35 |
+
# Load the VAE (requires access - see repo model card for info)
|
36 |
+
vae = AutoencoderKL.from_pretrained("CompVis/stable-diffusion-v1-4", subfolder="vae")
|
37 |
+
latent = torch.tensor([dataset['train'][0]['latent']]) # To tensor (bs, 4, 64, 3264
|
38 |
+
latent = (1 / 0.18215) * latent # Scale to match SD implementation
|
39 |
+
with torch.no_grad():
|
40 |
+
image = vae.decode(latent).sample[0] # Decode
|
41 |
+
image = (image / 2 + 0.5).clamp(0, 1) # To (0, 1)
|
42 |
+
image = image.detach().cpu().permute(1, 2, 0).numpy() # To numpy, channels lsat
|
43 |
+
image = (image * 255).round().astype("uint8") # (0, 255) and type uint8
|
44 |
+
image = Image.fromarray(image) # To PIL
|
45 |
+
image # The resulting PIL image
|
46 |
+
```
|