Update README.md
Browse files
README.md
CHANGED
|
@@ -23,23 +23,29 @@ Code for this model is available [here](https://huggingface.co/fal/FLUX.2-Tiny-A
|
|
| 23 |
| https://www.pexels.com/photo/brown-hummingbird-selective-focus-photography-1133957/ |  |
|
| 24 |
| https://www.pexels.com/photo/person-with-body-painting-1209843/ |  |
|
| 25 |
|
| 26 |
-
# Usage
|
| 27 |
|
| 28 |
```py
|
| 29 |
import torch
|
| 30 |
-
import torchvision.
|
| 31 |
|
| 32 |
from PIL import Image
|
| 33 |
from flux2_tiny_autoencoder import Flux2TinyAutoEncoder
|
| 34 |
|
| 35 |
-
tiny_vae = Flux2TinyAutoEncoder.from_pretrained(
|
|
|
|
|
|
|
|
|
|
| 36 |
tiny_vae.eval()
|
| 37 |
|
| 38 |
-
pil_image = Image.open("/path/to/
|
|
|
|
|
|
|
| 39 |
|
| 40 |
with torch.inference_mode():
|
| 41 |
-
latents = tiny_vae.encode(
|
| 42 |
-
recon = tiny_vae.decode(latents)
|
|
|
|
| 43 |
|
| 44 |
recon_image = F.to_pil_image(recon)
|
| 45 |
recon_image.save("reconstituted.png")
|
|
|
|
| 23 |
| https://www.pexels.com/photo/brown-hummingbird-selective-focus-photography-1133957/ |  |
|
| 24 |
| https://www.pexels.com/photo/person-with-body-painting-1209843/ |  |
|
| 25 |
|
| 26 |
+
# Example Usage
|
| 27 |
|
| 28 |
```py
|
| 29 |
import torch
|
| 30 |
+
import torchvision.transforms.functional as F
|
| 31 |
|
| 32 |
from PIL import Image
|
| 33 |
from flux2_tiny_autoencoder import Flux2TinyAutoEncoder
|
| 34 |
|
| 35 |
+
tiny_vae = Flux2TinyAutoEncoder.from_pretrained(
|
| 36 |
+
"fal/FLUX.2-Tiny-AutoEncoder",
|
| 37 |
+
device="cuda"
|
| 38 |
+
)
|
| 39 |
tiny_vae.eval()
|
| 40 |
|
| 41 |
+
pil_image = Image.open("/path/to/image.png")
|
| 42 |
+
image_tensor = F.to_tensor(pil_image)
|
| 43 |
+
image_tensor = image_tensor.unsqueeze(0) * 2.0 - 1.0
|
| 44 |
|
| 45 |
with torch.inference_mode():
|
| 46 |
+
latents = tiny_vae.encode(image_tensor, return_dict=False)
|
| 47 |
+
recon = tiny_vae.decode(latents, return_dict=False)
|
| 48 |
+
recon = recon.squeeze(0).clamp(-1, 1) / 2.0 + 0.5
|
| 49 |
|
| 50 |
recon_image = F.to_pil_image(recon)
|
| 51 |
recon_image.save("reconstituted.png")
|