Views
No views yet
1import birder
2from birder.inference.classification import infer_image
3
4# Option 1: manual setup (more control over preprocessing)
5(net, model_info) = birder.load_pretrained_model("vit_b16_pn_biotrove-clip-o", 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)
14(net, model_info, transform) = birder.load_pretrained_model_and_transform("vit_b16_pn_biotrove-clip-o", inference=True)
15
16image = "path/to/image.jpeg" # or a PIL image
17(out, embedding) = infer_image(net, image, transform, return_embedding=True)
18# embedding is a NumPy array with shape of (1, 768)1from PIL import Image
2import birder
3
4(net, model_info, transform) = birder.load_pretrained_model_and_transform("vit_b16_pn_biotrove-clip-o", 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, 768, 14, 14]))]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{yang2025biotrovelargecuratedimage,
12 title={BioTrove: A Large Curated Image Dataset Enabling AI for Biodiversity},
13 author={Chih-Hsuan Yang and Benjamin Feuer and Zaki Jubery and Zi K. Deng and Andre Nakkab and Md Zahid Hasan and Shivani Chiranjeevi and Kelly Marshall and Nirmal Baishnab and Asheesh K Singh and Arti Singh and Soumik Sarkar and Nirav Merchant and Chinmay Hegde and Baskar Ganapathysubramanian},
14 year={2025},
15 eprint={2406.17720},
16 archivePrefix={arXiv},
17 primaryClass={cs.CV},
18 url={https://arxiv.org/abs/2406.17720},
19}
20
21@software{ilharco_gabriel_2021_5143773,
22 author={Ilharco, Gabriel and Wortsman, Mitchell and Wightman, Ross and Gordon, Cade and Carlini, Nicholas and Taori, Rohan and Dave, Achal and Shankar, Vaishaal and Namkoong, Hongseok and Miller, John and Hajishirzi, Hannaneh and Farhadi, Ali and Schmidt, Ludwig},
23 title={OpenCLIP},
24 year={2021},
25 doi={10.5281/zenodo.5143773},
26}