Views
No views yet
ImageNet-21K dataset.1import birder
2from birder.inference.classification import infer_image
3
4(net, model_info) = birder.load_pretrained_model("vit_reg4_m16_rms_avg_i-jepa-imagenet21k", inference=True)
5
6# Get the image size the model was trained on
7size = birder.get_size_from_signature(model_info.signature)
8
9# Create an inference transform
10transform = birder.classification_transform(size, model_info.rgb_stats)
11
12image = "path/to/image.jpeg" # or a PIL image, must be loaded in RGB format
13(out, _) = infer_image(net, image, transform)
14# out is a NumPy array with shape of (1, 19167), representing class probabilities.1import birder
2from birder.inference.classification import infer_image
3
4(net, model_info) = birder.load_pretrained_model("vit_reg4_m16_rms_avg_i-jepa-imagenet21k", inference=True)
5
6# Get the image size the model was trained on
7size = birder.get_size_from_signature(model_info.signature)
8
9# Create an inference transform
10transform = birder.classification_transform(size, model_info.rgb_stats)
11
12image = "path/to/image.jpeg" # or a PIL image
13(out, embedding) = infer_image(net, image, transform, return_embedding=True)
14# embedding is a NumPy array with shape of (1, 512)1from PIL import Image
2import birder
3
4(net, model_info) = birder.load_pretrained_model("vit_reg4_m16_rms_avg_i-jepa-imagenet21k", inference=True)
5
6# Get the image size the model was trained on
7size = birder.get_size_from_signature(model_info.signature)
8
9# Create an inference transform
10transform = birder.classification_transform(size, model_info.rgb_stats)
11
12image = Image.open("path/to/image.jpeg")
13features = net.detection_features(transform(image).unsqueeze(0))
14# features is a dict (stage name -> torch.Tensor)
15print([(k, v.size()) for k, v in features.items()])
16# Output example:
17# [('neck', torch.Size([1, 512, 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{assran2023selfsupervisedlearningimagesjointembedding,
22 title={Self-Supervised Learning from Images with a Joint-Embedding Predictive Architecture},
23 author={Mahmoud Assran and Quentin Duval and Ishan Misra and Piotr Bojanowski and Pascal Vincent and Michael Rabbat and Yann LeCun and Nicolas Ballas},
24 year={2023},
25 eprint={2301.08243},
26 archivePrefix={arXiv},
27 primaryClass={cs.CV},
28 url={https://arxiv.org/abs/2301.08243},
29}