wenbowen commited on
Commit
611951a
·
verified ·
1 Parent(s): e835725

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +272 -0
README.md ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Model Card for DINOv2-S/B/L/g
2
+
3
+ These are Vision Transformer models trained following the method described in the papers:
4
+ "DINOv2: Learning Robust Visual Features without Supervision"
5
+ and
6
+ "Vision Transformers Need Registers".
7
+
8
+ We provide 8 models:
9
+ - 1 ViT-g trained from scratch with 3 ViT-S/B/L models distilled from the ViT-g, without registers.
10
+ - 1 ViT-g trained from scratch with 3 ViT-S/B/L models distilled from the ViT-g, with registers.
11
+
12
+ ## Model Details
13
+ The model takes an image as input and returns a class token and patch tokens, and optionally 4 register tokens.
14
+
15
+ The embedding dimension is:
16
+ - 384 for ViT-S.
17
+ - 768 for ViT-B.
18
+ - 1024 for ViT-L.
19
+ - 1536 for ViT-g.
20
+
21
+ The models follow a Transformer architecture, with a patch size of 14. In the case of registers, we add 4 register tokens, learned during training, to the input sequence after the patch embedding.
22
+
23
+ For a 224x224 image, this results in 1 class token + 256 patch tokens, and optionally 4 register tokens.
24
+
25
+ The models can accept larger images provided the image shapes are multiples of the patch size (14).
26
+ If this condition is not verified, the model will crop to the closest smaller multiple of the patch size.
27
+
28
+ ### Model Description
29
+
30
+ - **Developed by:** Meta AI
31
+ - **Model type:** Vision Transformer
32
+ - **License:** Apache License 2.0
33
+
34
+ - **Repository:** https://github.com/facebookresearch/dinov2
35
+ - **Paper:** https://arxiv.org/abs/2304.07193
36
+ - **Demo:** https://dinov2.metademolab.com/
37
+
38
+ ## Uses
39
+
40
+ The models are vision backbones providing multi-purpose features for downstream tasks.
41
+
42
+ ### Direct Use
43
+
44
+ The models can be used without fine-tuning, with downstream classifiers as simple as linear layers, to obtain competitive results:
45
+ - on depth estimation, semantic segmentation, using linear layers.
46
+ - on image classification, using k-NN classifiers on the class token.
47
+ - on image classification, with logistic regression classifiers applied on the class token.
48
+ - on image classification, with a linear layer applied on the class token and the average of the patch tokens.
49
+ - on image retrieval using nearest neighbors.
50
+
51
+ ### Downstream Use
52
+
53
+ It is technically possible to perform fine-tuning on the models, for small gains (we measured +2% on ImageNet-1k classification).
54
+ We recommend keeping this as a very last step and only when necessary, as the features already provide good performance out-of-the-box.
55
+
56
+ ## Bias, Risks, and Limitations
57
+
58
+ Despite improvements thanks to the training method not using annotations, we still observe significant biases in our models toward rich households from Western countries.
59
+
60
+ ### Recommendations
61
+
62
+ We expect fine-tuning will increase the biases in the features produced by the model as they will be tuned to the fine-tuning labels.
63
+
64
+ ## How to Get Started with the Model
65
+
66
+ Use the code below to get started with the model.
67
+
68
+ ```python
69
+ import torch
70
+
71
+ # DINOv2
72
+ dinov2_vits14 = torch.hub.load('facebookresearch/dinov2', 'dinov2_vits14')
73
+ dinov2_vitb14 = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitb14')
74
+ dinov2_vitl14 = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitl14')
75
+ dinov2_vitg14 = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitg14')
76
+
77
+ # DINOv2 with registers
78
+ dinov2_vits14_reg = torch.hub.load('facebookresearch/dinov2', 'dinov2_vits14_reg')
79
+ dinov2_vitb14_reg = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitb14_reg')
80
+ dinov2_vitl14_reg = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitl14_reg')
81
+ dinov2_vitg14_reg = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitg14_reg')
82
+ ```
83
+
84
+ ## Training Details
85
+
86
+ ### Training Data
87
+
88
+ - **Training data:** LVD-142M (see paper)
89
+ - **Training regime:** fp16 using PyTorch-FSDP mixed-precision.
90
+
91
+ ### Training Procedure
92
+
93
+ - **Training objective:**
94
+ - DINO self-distillation loss with multi-crop
95
+ - iBOT masked-image modeling loss
96
+ - KoLeo regularization on [CLS] tokens
97
+ - **Architectures:**
98
+ - ViT-S (21M params): Patch size 14, embedding dimension 384, 6 heads, MLP FFN
99
+ - ViT-B (86M params): Patch size 14, embedding dimension 768, 12 heads, MLP FFN
100
+ - ViT-L (0.3B params): Patch size 14, embedding dimension 1024, 16 heads, MLP FFN
101
+ - ViT-g (1.1B params): Patch size 14, embedding dimension 1536, 24 heads, SwiGLU FFN
102
+ - **Distillation:**
103
+ - Distillation follows the standard DINOv2 pretraining procedure, except the teacher is a pretrained ViT-g, frozen.
104
+
105
+ ## Evaluation
106
+
107
+ We refer users to the associated papers for the evaluation protocols.
108
+
109
+ <table>
110
+ <tr>
111
+ <th colspan="2"></th>
112
+ <th colspan="3">ImageNet-1k</th>
113
+ <th>NYU-Depth v2</th>
114
+ <th>SUN-RGBD</th>
115
+ <th>ADE20k</th>
116
+ <th>iNaturalist 2018</th>
117
+ <th>Oxford-H</th>
118
+ </tr>
119
+ <tr>
120
+ <th rowspan="2">model</th>
121
+ <th rowspan="2">with <br /> registers</th>
122
+ <th>classif. (acc)</th>
123
+ <th>classif. (acc)</th>
124
+ <th>classif. V2 (acc)</th>
125
+ <th>depth (RMSE)</th>
126
+ <th>depth (RMSE)</th>
127
+ <th>segm. (mAP)</th>
128
+ <th>classif. (acc)</th>
129
+ <th>retrieval (mAP)</th>
130
+ </tr>
131
+ <tr>
132
+ <!-- <th>^</th> -->
133
+ <th>k-NN</th>
134
+ <th>linear</th>
135
+ <th>linear</th>
136
+ <th>linear<br />4 layers</th>
137
+ <th>NYU-D transfer</th>
138
+ <th>multiscale</th>
139
+ <th>linear</th>
140
+ <th>nearest neighbor</th>
141
+ </tr>
142
+ <tr>
143
+ <td>ViT-S/14</td>
144
+ <td align="center">:x:</td>
145
+ <td align="right">79.0%</td>
146
+ <td align="right">81.1%</td>
147
+ <td align="right">70.8%</td>
148
+ <td align="right">0.417</td>
149
+ <td align="right">0.431</td>
150
+ <td align="right">47.2</td>
151
+ <td align="right">69.5%</td>
152
+ <td align="right">43.2</td>
153
+ </tr>
154
+ <tr>
155
+ <td>ViT-S/14</td>
156
+ <td align="center">:white_check_mark:</td>
157
+ <td align="right">79.1%</td>
158
+ <td align="right">80.9%</td>
159
+ <td align="right">71.0%</td>
160
+ <td align="right">N/A</td>
161
+ <td align="right">N/A</td>
162
+ <td align="right">N/A</td>
163
+ <td align="right">67.6%</td>
164
+ <td align="right">39.5</td>
165
+ </tr>
166
+ <tr>
167
+ <td>ViT-B/14</td>
168
+ <td align="center">:x:</td>
169
+ <td align="right">82.1%</td>
170
+ <td align="right">84.5%</td>
171
+ <td align="right">74.9%</td>
172
+ <td align="right">0.362</td>
173
+ <td align="right">0.400</td>
174
+ <td align="right">51.3</td>
175
+ <td align="right">76.3%</td>
176
+ <td align="right">49.5</td>
177
+ </tr>
178
+ <td>ViT-B/14</td>
179
+ <td align="center">:white_check_mark:</td>
180
+ <td align="right">82.0%</td>
181
+ <td align="right">84.6%</td>
182
+ <td align="right">75.6%</td>
183
+ <td align="right">N/A</td>
184
+ <td align="right">N/A</td>
185
+ <td align="right">N/A</td>
186
+ <td align="right">73.8%</td>
187
+ <td align="right">51.0</td>
188
+ </tr>
189
+ <tr>
190
+ <td>ViT-L/14</td>
191
+ <td align="center">:x:</td>
192
+ <td align="right">83.5%</td>
193
+ <td align="right">86.3%</td>
194
+ <td align="right">77.6%</td>
195
+ <td align="right">0.333</td>
196
+ <td align="right">0.396</td>
197
+ <td align="right">53.1</td>
198
+ <td align="right">79.8%</td>
199
+ <td align="right">54.0</td>
200
+ </tr>
201
+ <tr>
202
+ <td>ViT-L/14</td>
203
+ <td align="center">:white_check_mark:</td>
204
+ <td align="right">83.8%</td>
205
+ <td align="right">86.7%</td>
206
+ <td align="right">78.5%</td>
207
+ <td align="right">N/A</td>
208
+ <td align="right">N/A</td>
209
+ <td align="right">N/A</td>
210
+ <td align="right">80.9%</td>
211
+ <td align="right">55.7</td>
212
+ </tr>
213
+ <tr>
214
+ <td>ViT-g/14</td>
215
+ <td align="center">:x:</td>
216
+ <td align="right">83.5%</td>
217
+ <td align="right">86.5%</td>
218
+ <td align="right">78.4%</td>
219
+ <td align="right">0.298</td>
220
+ <td align="right">0.362</td>
221
+ <td align="right">53.0</td>
222
+ <td align="right">81.6%</td>
223
+ <td align="right">52.3</td>
224
+ </tr>
225
+ <tr>
226
+ <tr>
227
+ <td>ViT-g/14</td>
228
+ <td align="center">:white_check_mark:</td>
229
+ <td align="right">83.7%</td>
230
+ <td align="right">87.1%</td>
231
+ <td align="right">78.8%</td>
232
+ <td align="right">N/A</td>
233
+ <td align="right">N/A</td>
234
+ <td align="right">N/A</td>
235
+ <td align="right">81.5%</td>
236
+ <td align="right">58.2</td>
237
+ </tr>
238
+ </table>
239
+
240
+ ## Environmental Impact
241
+
242
+ - **Hardware Type:** Nvidia A100
243
+ - **Hours used:** 22,000 for ViT-g, 4,500 for ViT-S distillation, 5,300 for ViT-B distillation, 8,000 for ViT-L distillation
244
+ - **Cloud Provider:** Private infra
245
+ - **Compute Region:** USA
246
+ - **Carbon Emitted:** 7t CO2eq
247
+
248
+ #### Hardware
249
+
250
+ Nvidia A100 GPUs
251
+
252
+ #### Software
253
+
254
+ PyTorch 2.0,
255
+ xFormers 0.0.18
256
+
257
+ **BibTeX**
258
+
259
+ ```
260
+ @misc{oquab2023dinov2,
261
+ title={DINOv2: Learning Robust Visual Features without Supervision},
262
+ author={Oquab, Maxime and Darcet, Timothée and Moutakanni, Theo and Vo, Huy and Szafraniec, Marc and Khalidov, Vasil and Fernandez, Pierre and Haziza, Daniel and Massa, Francisco and El-Nouby, Alaaeldin and Howes, Russell and Huang, Po-Yao and Xu, Hu and Sharma, Vasu and Li, Shang-Wen and Galuba, Wojciech and Rabbat, Mike and Assran, Mido and Ballas, Nicolas and Synnaeve, Gabriel and Misra, Ishan and Jegou, Herve and Mairal, Julien and Labatut, Patrick and Joulin, Armand and Bojanowski, Piotr},
263
+ journal={arXiv:2304.07193},
264
+ year={2023}
265
+ }
266
+ @misc{darcet2023vitneedreg,
267
+ title={Vision Transformers Need Registers},
268
+ author={Darcet, Timothée and Oquab, Maxime and Mairal, Julien and Bojanowski, Piotr},
269
+ journal={arXiv:2309.16588},
270
+ year={2023}
271
+ }
272
+ ```