Views
No views yet
1import birder
2from birder.inference.classification import infer_image
3
4# Option 1: manual setup (more control over preprocessing)
5net, model_info = birder.load_pretrained_model("vit_reg4_so150m_p14_avg_mim-bio", 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
13# Option 2: helper (quick start with default preprocessing)
14net, model_info, transform = birder.load_pretrained_model_and_transform("vit_reg4_so150m_p14_avg_mim-bio", inference=True)
15
16image = "path/to/image.jpeg" # or a PIL image
17out, embedding = infer_image(net, image, transform, return_embedding=True)
18# embedding is a NumPy array with shape of (1, 896)1from PIL import Image
2import birder
3
4net, model_info, transform = birder.load_pretrained_model_and_transform("vit_reg4_so150m_p14_avg_mim-bio", inference=True)
5
6image = Image.open("path/to/image.jpeg")
7features = net.detection_features(transform(image).unsqueeze(0))
8# features is a dict (stage name -> torch.Tensor)
9print([(k, v.size()) for k, v in features.items()])
10# Output example:
11# [('stage1', torch.Size([1, 896, 16, 16]))]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{darcet2024visiontransformersneedregisters,
12 title={Vision Transformers Need Registers},
13 author={Timothée Darcet and Maxime Oquab and Julien Mairal and Piotr Bojanowski},
14 year={2024},
15 eprint={2309.16588},
16 archivePrefix={arXiv},
17 primaryClass={cs.CV},
18 url={https://arxiv.org/abs/2309.16588},
19}
20
21@misc{alabdulmohsin2024gettingvitshapescaling,
22 title={Getting ViT in Shape: Scaling Laws for Compute-Optimal Model Design},
23 author={Ibrahim Alabdulmohsin and Xiaohua Zhai and Alexander Kolesnikov and Lucas Beyer},
24 year={2024},
25 eprint={2305.13035},
26 archivePrefix={arXiv},
27 primaryClass={cs.CV},
28 url={https://arxiv.org/abs/2305.13035},
29}
30
31@misc{fu2025rethinkingpatchdependencemasked,
32 title={Rethinking Patch Dependence for Masked Autoencoders},
33 author={Letian Fu and Long Lian and Renhao Wang and Baifeng Shi and Xudong Wang and Adam Yala and Trevor Darrell and Alexei A. Efros and Ken Goldberg},
34 year={2025},
35 eprint={2401.14391},
36 archivePrefix={arXiv},
37 primaryClass={cs.CV},
38 url={https://arxiv.org/abs/2401.14391},
39}