Views
No views yet
git clone https://github.com/wearepal/visual-word-tokenizer.gitattention_mask flag that is unused for the vision transformer. Add the following line to the input of self.encoder:1attention_mask=getattr(hidden_states, 'attention_mask', None),
21from examples.modeling_clip import CLIPModel
2
3from vwt.inter import wrap_model
4
5
6model = CLIPModel.from_pretrained('openai/clip-vit-base-patch16')
7
8# load your pre-processing dataset here...
9pre_process_data = ['A list of images', '...'] # dummy data
10
11# initializing an intra-image tokenizer
12wrap_model(model.vision_model, thresh=0.1)
13
14vwt = model.vision_model.embeddings
15vwt.learn_words(
16 split,
17 vocab_size=1000, # number of visual words
18 batch_size=1024 # batch size for clustering
19)
20# deploy the model for inference on your downstream task...
21
22# saving the visual word vocabulary
23vwt.save_pretrained('pre_process_data')
24
25# reusing the visual word vocabulary
26new_model = AutoModel.from_pretrained('openai/clip-vit-base-patch16')
27wrap_model(new_model.vision_model, thresh=0.1)
28
29new_vwt = model.vision_model.embeddings
30new_vwt.load_words('pre_process_data/vocab.pt')
311from huggingface_hub import snapshot_download
2
3from examples.modeling_clip import CLIPModel
4from vwt.inter import wrap_model
5
6
7model = CLIPModel.from_pretrained('openai/clip-vit-base-patch16')
8
9# initializing an intra-image tokenizer
10wrap_model(model.vision_model, thresh=0.1)
11
12vwt = model.vision_model.embeddings
13
14# downloading the visual word vocabulary
15snapshot_download(repo_id='LeonidasY/inter-image-imgnet-100', local_dir='tokenizer')
16# snapshot_download(repo_id='LeonidasY/inter-image-imgnet-1000', local_dir='tokenizer')
17# snapshot_download(repo_id='LeonidasY/inter-image-imgnet-10000', local_dir='tokenizer')
18
19# loading the visual word vocabulary
20vwt.load_words('tokenizer/vocab.pt')
21
22# deploy the model for inference on your downstream task...
23@misc{gee2024efficientonlineinferencevision,
title={Efficient Online Inference of Vision Transformers by Training-Free Tokenization},
author={Leonidas Gee and Wing Yan Li and Viktoriia Sharmanska and Novi Quadrianto},
year={2024},
eprint={2411.15397},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2411.15397},
}