Views
No views yet
FlexTok d18-d28 DFN model directly from HuggingFace Hub, call:1from flextok.flextok_wrapper import FlexTokFromHub
2model = FlexTokFromHub.from_pretrained('EPFL-VILAB/flextok_d18_d28_dfn').eval()model.safetensors checkpoint in this repository manually and loading it using our helper functions:1from hydra.utils import instantiate
2from flextok.utils.checkpoint import load_safetensors
3
4ckpt, config = load_safetensors('/path/to/model.safetensors')
5model = instantiate(config).eval()
6model.load_state_dict(ckpt)1from flextok.utils.demo import imgs_from_urls
2# Load example images of shape (B, 3, 256, 256), normalized to [-1,1]
3imgs = imgs_from_urls(urls=['https://storage.googleapis.com/flextok_site/nb_demo_images/0.png'])
4
5# tokens_list is a list of [1, 256] discrete token sequences
6tokens_list = model.tokenize(imgs)1k_keep = 64 # For example, only keep the first 64 out of 256 tokens
2tokens_list = [t[:,:k_keep] for t in tokens_list]1# tokens_list is a list of [1, l] discrete token sequences, with l <= 256
2# reconst is a [B, 3, 256, 256] tensor, normalized to [-1,1]
3reconst = model.detokenize(
4 tokens_list,
5 timesteps=20, # Number of denoising steps
6 guidance_scale=7.5, # Classifier-free guidance scale
7 perform_norm_guidance=True, # See https://arxiv.org/abs/2410.02416
8)@article{flextok,
title={{FlexTok}: Resampling Images into 1D Token Sequences of Flexible Length},
author={Roman Bachmann and Jesse Allardice and David Mizrahi and Enrico Fini and O{\u{g}}uzhan Fatih Kar and Elmira Amirloo and Alaaeldin El-Nouby and Amir Zamir and Afshin Dehghan},
journal={arXiv 2025},
year={2025},
}