johnowhitaker commited on
Commit
9a1c7f1
1 Parent(s): e976bc8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +23 -1
README.md CHANGED
@@ -14,4 +14,26 @@ dataset_info:
14
  ---
15
  # Dataset Card for "latent_celebA_256px"
16
 
17
- [More Information needed](https://github.com/huggingface/datasets/blob/main/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  ---
15
  # Dataset Card for "latent_celebA_256px"
16
 
17
+ Each image is cropped to 256px square and encoded to a 4x32x32 latent representation using the same VAE as that employed by Stable Diffusion
18
+
19
+ Decoding
20
+ ```python
21
+ from diffusers import AutoencoderKL
22
+ from datasets import load_dataset
23
+ from PIL import Image
24
+ import numpy as np
25
+ import torch
26
+ # load the dataset
27
+ dataset = load_dataset('tglcourse/latent_celebA_256px')
28
+ # Load the VAE (requires access - see repo model card for info)
29
+ vae = AutoencoderKL.from_pretrained("CompVis/stable-diffusion-v1-4", subfolder="vae")
30
+ latent = torch.tensor([dataset['train'][0]['latent']]) # To tensor (bs, 4, 32, 32)
31
+ latent = (1 / 0.18215) * latent # Scale to match SD implementation
32
+ with torch.no_grad():
33
+ image = vae.decode(latent).sample[0] # Decode
34
+ image = (image / 2 + 0.5).clamp(0, 1) # To (0, 1)
35
+ image = image.detach().cpu().permute(1, 2, 0).numpy() # To numpy, channels lsat
36
+ image = (image * 255).round().astype("uint8") # (0, 255) and type uint8
37
+ image = Image.fromarray(image) # To PIL
38
+ image # The resulting PIL image
39
+ ```