Views
No views yet
1import torch
2import birder
3from PIL import Image
4
5(net, model_info) = birder.load_pretrained_model("vit_l16_mim_400", inference=True)
6
7# Get the image size the model was trained on
8size = birder.get_size_from_signature(model_info.signature)
9
10# Create an inference transform
11transform = birder.classification_transform(size, model_info.rgb_stats)
12
13image = Image.open("path/to/image.jpeg")
14input_tensor = transform(image).unsqueeze(dim=0)
15with torch.inference_mode():
16 embedding = net.embedding(input_tensor)
17 # embedding is a tensor with shape of (1, 1024)1@misc{dosovitskiy2021imageworth16x16words,
2 title={An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale},
3 author={Alexey Dosovitskiy and Lucas Beyer and Alexander Kolesnikov and Dirk Weissenborn and Xiaohua Zhai and Thomas Unterthiner and Mostafa Dehghani and Matthias Minderer and Georg Heigold and Sylvain Gelly and Jakob Uszkoreit and Neil Houlsby},
4 year={2021},
5 eprint={2010.11929},
6 archivePrefix={arXiv},
7 primaryClass={cs.CV},
8 url={https://arxiv.org/abs/2010.11929},
9}
10
11@misc{he2021maskedautoencodersscalablevision,
12 title={Masked Autoencoders Are Scalable Vision Learners},
13 author={Kaiming He and Xinlei Chen and Saining Xie and Yanghao Li and Piotr Dollár and Ross Girshick},
14 year={2021},
15 eprint={2111.06377},
16 archivePrefix={arXiv},
17 primaryClass={cs.CV},
18 url={https://arxiv.org/abs/2111.06377},
19}