dn6 HF Staff commited on
Commit
e6d2e0a
·
verified ·
1 Parent(s): e244d68

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +33 -3
README.md CHANGED
@@ -12,14 +12,14 @@ tags:
12
 
13
  # About
14
 
15
- Tiny AutoEncoder trained on the latent space of [black-forest-labs/FLUX.2-dev](https://huggingface.co/black-forest-labs/FLUX.2-dev)'s autoencoder. Works to convert between latent and image space up to 20x faster and in 28x fewer parameters at the expense of a small amount of quality.
16
 
17
  Code for this model is available [here](https://huggingface.co/fal/FLUX.2-Tiny-AutoEncoder/blob/main/flux2_tiny_autoencoder.py).
18
 
19
  # Round-Trip Comparisons
20
 
21
  | Source | Image |
22
- | ------ | ----- |
23
  | https://www.pexels.com/photo/mirror-lying-on-open-book-11495792/ | ![compare_autoencoders_1](https://cdn-uploads.huggingface.co/production/uploads/64429aaf7feb866811b12f73/u7ZnjY8FAwu09-iyEC_um.png) |
24
  | https://www.pexels.com/photo/brown-hummingbird-selective-focus-photography-1133957/ | ![compare_autoencoders_2](https://cdn-uploads.huggingface.co/production/uploads/64429aaf7feb866811b12f73/ZzvJu3VfrzlvZ7bDDASog.png) |
25
  | https://www.pexels.com/photo/person-with-body-painting-1209843/ | ![compare_autoencoders_3](https://cdn-uploads.huggingface.co/production/uploads/64429aaf7feb866811b12f73/B56LPhLYiGT0ffnBVIRbP.png) |
@@ -51,4 +51,34 @@ with torch.inference_mode():
51
 
52
  recon_image = F.to_pil_image(recon)
53
  recon_image.save("reconstituted.png")
54
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  # About
14
 
15
+ Tiny AutoEncoder trained on the latent space of [black-forest-labs/FLUX.2-dev](https://huggingface.co/black-forest-labs/FLUX.2-dev)'s autoencoder. Works to convert between latent and image space up to 20x faster and in 28x fewer parameters at the expense of a small amount of quality.
16
 
17
  Code for this model is available [here](https://huggingface.co/fal/FLUX.2-Tiny-AutoEncoder/blob/main/flux2_tiny_autoencoder.py).
18
 
19
  # Round-Trip Comparisons
20
 
21
  | Source | Image |
22
+ | ------ | ----- |
23
  | https://www.pexels.com/photo/mirror-lying-on-open-book-11495792/ | ![compare_autoencoders_1](https://cdn-uploads.huggingface.co/production/uploads/64429aaf7feb866811b12f73/u7ZnjY8FAwu09-iyEC_um.png) |
24
  | https://www.pexels.com/photo/brown-hummingbird-selective-focus-photography-1133957/ | ![compare_autoencoders_2](https://cdn-uploads.huggingface.co/production/uploads/64429aaf7feb866811b12f73/ZzvJu3VfrzlvZ7bDDASog.png) |
25
  | https://www.pexels.com/photo/person-with-body-painting-1209843/ | ![compare_autoencoders_3](https://cdn-uploads.huggingface.co/production/uploads/64429aaf7feb866811b12f73/B56LPhLYiGT0ffnBVIRbP.png) |
 
51
 
52
  recon_image = F.to_pil_image(recon)
53
  recon_image.save("reconstituted.png")
54
+ ```
55
+
56
+ ## Use with Diffusers 🧨
57
+
58
+ ```py
59
+ import torch
60
+ import torchvision.transforms.functional as F
61
+ from diffusers import AutoModel
62
+ from diffusers.utils import load_image
63
+
64
+ device = torch.device("cuda")
65
+ tiny_vae = AutoModel.from_pretrained(
66
+ "fal/FLUX.2-Tiny-AutoEncoder",
67
+ trust_remote_code=True,
68
+ torch_dtype=torch.bfloat16
69
+ ).to(device)
70
+
71
+ pil_image = load_image("/path/to/image.png")
72
+ image_tensor = F.to_tensor(pil_image)
73
+ image_tensor = image_tensor.unsqueeze(0) * 2.0 - 1.0
74
+ image_tensor = image_tensor.to(device, dtype=tiny_vae.dtype)
75
+
76
+ with torch.inference_mode():
77
+ latents = tiny_vae.encode(image_tensor, return_dict=False)
78
+ recon = tiny_vae.decode(latents, return_dict=False)
79
+ recon = recon.squeeze(0).clamp(-1, 1) / 2.0 + 0.5
80
+ recon = recon.float().detach().cpu()
81
+
82
+ recon_image = F.to_pil_image(recon)
83
+ recon_image.save("reconstituted.png")
84
+ ```