Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,137 @@
|
|
1 |
-
---
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- image-classification
|
4 |
+
- birder
|
5 |
+
- pytorch
|
6 |
+
library_name: birder
|
7 |
+
license: apache-2.0
|
8 |
+
base_model:
|
9 |
+
- birder-project/hieradet_small_dino-v2
|
10 |
+
---
|
11 |
+
|
12 |
+
# Model Card for hieradet_small_dino-v2-inat21
|
13 |
+
|
14 |
+
HieraDet small image classification model. The model follows a two-stage training process: first, DINOv2 pretraining, then fine-tuned on the `iNaturalist 2021` dataset - <https://github.com/visipedia/inat_comp/tree/master/2021>.
|
15 |
+
|
16 |
+
The model's class-to-index mapping uses original scientific names with full taxonomic rank,
|
17 |
+
a partial mapping to common names can be found here: <https://gitlab.com/birder/birder/-/blob/main/public_datasets_metadata/inat21-mapping.json>
|
18 |
+
|
19 |
+
Note: A 256 x 256 variant of this model is available as `hieradet_small_dino-v2-inat21-256px`.
|
20 |
+
|
21 |
+
## Model Details
|
22 |
+
|
23 |
+
- **Model Type:** Image classification and detection backbone
|
24 |
+
- **Model Stats:**
|
25 |
+
- Params (M): 41.6
|
26 |
+
- Input image size: 384 x 384
|
27 |
+
- **Dataset:** iNaturalist 2021 (10000 classes)
|
28 |
+
|
29 |
+
- **Papers:**
|
30 |
+
- Hiera: A Hierarchical Vision Transformer without the Bells-and-Whistles: <https://arxiv.org/abs/2306.00989>
|
31 |
+
- SAM 2: Segment Anything in Images and Videos: <https://arxiv.org/abs/2408.00714>
|
32 |
+
- DINOv2: Learning Robust Visual Features without Supervision: <https://arxiv.org/abs/2304.07193>
|
33 |
+
|
34 |
+
- **Metrics:**
|
35 |
+
- Top-1 accuracy of 256px model @ 256: 85.52%
|
36 |
+
- Top-1 accuracy of 256px model @ 384: 86.68%
|
37 |
+
- Top-1 accuracy @ 384: 88.64%
|
38 |
+
|
39 |
+
## Model Usage
|
40 |
+
|
41 |
+
### Image Classification
|
42 |
+
|
43 |
+
```python
|
44 |
+
import birder
|
45 |
+
from birder.inference.classification import infer_image
|
46 |
+
|
47 |
+
(net, model_info) = birder.load_pretrained_model("hieradet_small_dino-v2-inat21", inference=True)
|
48 |
+
# Note: A 256x256 variant is available as "hieradet_small_dino-v2-inat21-256px"
|
49 |
+
|
50 |
+
# Get the image size the model was trained on
|
51 |
+
size = birder.get_size_from_signature(model_info.signature)
|
52 |
+
|
53 |
+
# Create an inference transform
|
54 |
+
transform = birder.classification_transform(size, model_info.rgb_stats)
|
55 |
+
|
56 |
+
image = "path/to/image.jpeg" # or a PIL image, must be loaded in RGB format
|
57 |
+
(out, _) = infer_image(net, image, transform)
|
58 |
+
# out is a NumPy array with shape of (1, 10000), representing class probabilities.
|
59 |
+
```
|
60 |
+
|
61 |
+
### Image Embeddings
|
62 |
+
|
63 |
+
```python
|
64 |
+
import birder
|
65 |
+
from birder.inference.classification import infer_image
|
66 |
+
|
67 |
+
(net, model_info) = birder.load_pretrained_model("hieradet_small_dino-v2-inat21", inference=True)
|
68 |
+
|
69 |
+
# Get the image size the model was trained on
|
70 |
+
size = birder.get_size_from_signature(model_info.signature)
|
71 |
+
|
72 |
+
# Create an inference transform
|
73 |
+
transform = birder.classification_transform(size, model_info.rgb_stats)
|
74 |
+
|
75 |
+
image = "path/to/image.jpeg" # or a PIL image
|
76 |
+
(out, embedding) = infer_image(net, image, transform, return_embedding=True)
|
77 |
+
# embedding is a NumPy array with shape of (1, 768)
|
78 |
+
```
|
79 |
+
|
80 |
+
### Detection Feature Map
|
81 |
+
|
82 |
+
```python
|
83 |
+
from PIL import Image
|
84 |
+
import birder
|
85 |
+
|
86 |
+
(net, model_info) = birder.load_pretrained_model("hieradet_small_dino-v2-inat21", inference=True)
|
87 |
+
|
88 |
+
# Get the image size the model was trained on
|
89 |
+
size = birder.get_size_from_signature(model_info.signature)
|
90 |
+
|
91 |
+
# Create an inference transform
|
92 |
+
transform = birder.classification_transform(size, model_info.rgb_stats)
|
93 |
+
|
94 |
+
image = Image.open("path/to/image.jpeg")
|
95 |
+
features = net.detection_features(transform(image).unsqueeze(0))
|
96 |
+
# features is a dict (stage name -> torch.Tensor)
|
97 |
+
print([(k, v.size()) for k, v in features.items()])
|
98 |
+
# Output example:
|
99 |
+
# [('stage1', torch.Size([1, 96, 96, 96])),
|
100 |
+
# ('stage2', torch.Size([1, 192, 48, 48])),
|
101 |
+
# ('stage3', torch.Size([1, 384, 24, 24])),
|
102 |
+
# ('stage4', torch.Size([1, 768, 12, 12]))]
|
103 |
+
```
|
104 |
+
|
105 |
+
## Citation
|
106 |
+
|
107 |
+
```bibtex
|
108 |
+
@misc{ryali2023hierahierarchicalvisiontransformer,
|
109 |
+
title={Hiera: A Hierarchical Vision Transformer without the Bells-and-Whistles},
|
110 |
+
author={Chaitanya Ryali and Yuan-Ting Hu and Daniel Bolya and Chen Wei and Haoqi Fan and Po-Yao Huang and Vaibhav Aggarwal and Arkabandhu Chowdhury and Omid Poursaeed and Judy Hoffman and Jitendra Malik and Yanghao Li and Christoph Feichtenhofer},
|
111 |
+
year={2023},
|
112 |
+
eprint={2306.00989},
|
113 |
+
archivePrefix={arXiv},
|
114 |
+
primaryClass={cs.CV},
|
115 |
+
url={https://arxiv.org/abs/2306.00989},
|
116 |
+
}
|
117 |
+
|
118 |
+
@misc{ravi2024sam2segmentimages,
|
119 |
+
title={SAM 2: Segment Anything in Images and Videos},
|
120 |
+
author={Nikhila Ravi and Valentin Gabeur and Yuan-Ting Hu and Ronghang Hu and Chaitanya Ryali and Tengyu Ma and Haitham Khedr and Roman Rädle and Chloe Rolland and Laura Gustafson and Eric Mintun and Junting Pan and Kalyan Vasudev Alwala and Nicolas Carion and Chao-Yuan Wu and Ross Girshick and Piotr Dollár and Christoph Feichtenhofer},
|
121 |
+
year={2024},
|
122 |
+
eprint={2408.00714},
|
123 |
+
archivePrefix={arXiv},
|
124 |
+
primaryClass={cs.CV},
|
125 |
+
url={https://arxiv.org/abs/2408.00714},
|
126 |
+
}
|
127 |
+
|
128 |
+
@misc{oquab2024dinov2learningrobustvisual,
|
129 |
+
title={DINOv2: Learning Robust Visual Features without Supervision},
|
130 |
+
author={Maxime Oquab and Timothée Darcet and Théo Moutakanni and Huy Vo and Marc Szafraniec and Vasil Khalidov and Pierre Fernandez and Daniel Haziza and Francisco Massa and Alaaeldin El-Nouby and Mahmoud Assran and Nicolas Ballas and Wojciech Galuba and Russell Howes and Po-Yao Huang and Shang-Wen Li and Ishan Misra and Michael Rabbat and Vasu Sharma and Gabriel Synnaeve and Hu Xu and Hervé Jegou and Julien Mairal and Patrick Labatut and Armand Joulin and Piotr Bojanowski},
|
131 |
+
year={2024},
|
132 |
+
eprint={2304.07193},
|
133 |
+
archivePrefix={arXiv},
|
134 |
+
primaryClass={cs.CV},
|
135 |
+
url={https://arxiv.org/abs/2304.07193},
|
136 |
+
}
|
137 |
+
```
|