Views
No views yet
eu-common dataset containing common European bird species.uniformer_s_eu-common256px.1import birder
2from birder.inference.classification import infer_image
3
4(net, model_info) = birder.load_pretrained_model("uniformer_s_eu-common", inference=True)
5# Note: A 256x256 variant is available as "uniformer_s_eu-common256px"
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 = "path/to/image.jpeg" # or a PIL image, must be loaded in RGB format
14(out, _) = infer_image(net, image, transform)
15# out is a NumPy array with shape of (1, 707), representing class probabilities.1import birder
2from birder.inference.classification import infer_image
3
4(net, model_info) = birder.load_pretrained_model("uniformer_s_eu-common", 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("uniformer_s_eu-common", 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# [('stage1', torch.Size([1, 64, 96, 96])),
18# ('stage2', torch.Size([1, 128, 48, 48])),
19# ('stage3', torch.Size([1, 320, 24, 24])),
20# ('stage4', torch.Size([1, 512, 12, 12]))]1@misc{li2023uniformerunifyingconvolutionselfattention,
2 title={UniFormer: Unifying Convolution and Self-attention for Visual Recognition},
3 author={Kunchang Li and Yali Wang and Junhao Zhang and Peng Gao and Guanglu Song and Yu Liu and Hongsheng Li and Yu Qiao},
4 year={2023},
5 eprint={2201.09450},
6 archivePrefix={arXiv},
7 primaryClass={cs.CV},
8 url={https://arxiv.org/abs/2201.09450},
9}