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("naflex_i_vit_so400m_p16_ap_c1_siglip-v2-webli", 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 a NaFlex inference transform
11patch_size = net.stem_stride
12max_seq_len = (size[0] // patch_size) * (size[1] // patch_size)
13transform = birder.naflex_transform(patch_size, max_seq_len, model_info.rgb_stats)
14
15# Option 2: helper (quick start with NaFlex preprocessing)
16net, model_info, transform = birder.load_pretrained_model_and_transform(
17 "naflex_i_vit_so400m_p16_ap_c1_siglip-v2-webli",
18 inference=True,
19 naflex=True,
20)
21
22image = "path/to/image.jpeg" # or a PIL image
23out, embedding = infer_image(net, image, transform, return_embedding=True)
24# embedding is a NumPy array with shape of (1, 1152)1from PIL import Image
2import birder
3
4net, model_info, transform = birder.load_pretrained_model_and_transform("naflex_i_vit_so400m_p16_ap_c1_siglip-v2-webli", 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, 1152, 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{alabdulmohsin2024gettingvitshapescaling,
12 title={Getting ViT in Shape: Scaling Laws for Compute-Optimal Model Design},
13 author={Ibrahim Alabdulmohsin and Xiaohua Zhai and Alexander Kolesnikov and Lucas Beyer},
14 year={2024},
15 eprint={2305.13035},
16 archivePrefix={arXiv},
17 primaryClass={cs.CV},
18 url={https://arxiv.org/abs/2305.13035},
19}
20
21@misc{tschannen2025siglip2multilingualvisionlanguage,
22 title={SigLIP 2: Multilingual Vision-Language Encoders with Improved Semantic Understanding, Localization, and Dense Features},
23 author={Michael Tschannen and Alexey Gritsenko and Xiao Wang and Muhammad Ferjad Naeem and Ibrahim Alabdulmohsin and Nikhil Parthasarathy and Talfan Evans and Lucas Beyer and Ye Xia and Basil Mustafa and Olivier Hénaff and Jeremiah Harmsen and Andreas Steiner and Xiaohua Zhai},
24 year={2025},
25 eprint={2502.14786},
26 archivePrefix={arXiv},
27 primaryClass={cs.CV},
28 url={https://arxiv.org/abs/2502.14786},
29}