Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
{}
|
3 |
+
---
|
4 |
+
# AM-RADIO: Reduce All Domains Into One
|
5 |
+
|
6 |
+
Mike Ranzinger, Greg Heinrich, Jan Kautz, Pavlo Molchanov
|
7 |
+
|
8 |
+
[NVIDIA Research](https://www.nvidia.com/en-us/research/)
|
9 |
+
|
10 |
+
\[[Paper](https://arxiv.org/abs/2312.06709)\]\[[BibTex](#citing-radio)\]
|
11 |
+
|
12 |
+
### HuggingFace Hub
|
13 |
+
|
14 |
+
You can pull the model from a Python script:
|
15 |
+
|
16 |
+
```Python
|
17 |
+
import torch
|
18 |
+
from PIL import Image
|
19 |
+
from transformers import AutoModel, CLIPImageProcessor
|
20 |
+
|
21 |
+
hf_repo = "nvidia/RADIO-B"
|
22 |
+
|
23 |
+
image_processor = CLIPImageProcessor.from_pretrained(hf_repo)
|
24 |
+
model = AutoModel.from_pretrained(hf_repo, trust_remote_code=True)
|
25 |
+
model.eval().cuda()
|
26 |
+
|
27 |
+
image = Image.open('./assets/radio.png').convert('RGB')
|
28 |
+
pixel_values = image_processor(images=image, return_tensors='pt', do_resize=True).pixel_values
|
29 |
+
pixel_values = pixel_values.cuda()
|
30 |
+
|
31 |
+
summary, features = model(pixel_values)
|
32 |
+
```
|
33 |
+
|
34 |
+
### Usage
|
35 |
+
|
36 |
+
RADIO will return a tuple with two tensors. The `summary` is similar to the `cls_token` in ViT and is meant to represent the general concept of the entire image. It has shape $(B,C)$ with $B$ being the batch dimension, and $C$ being some number of channels. The `spatial_features` represent more localized content which should be suitable for dense tasks such as semantic segmentation, or for integration into an LLM. It has shape $(B,T,D)$ with $T$ being the flattened spatial tokens, and $D$ being the channels for spatial features. Note that $C \neq D$ in general.
|
37 |
+
|
38 |
+
Converting to a spatial tensor format can be done using the downsampling size of the model, combined with the input tensor shape. For 'radio_v1', the patch size is 14.
|
39 |
+
```Python
|
40 |
+
from einops import rearrange
|
41 |
+
spatial_features = rearrange(spatial_features, 'b (h w) d -> b d h w', h=x.shape[-2] // patch_size, w=x.shape[-1] // patch_size)
|
42 |
+
```
|
43 |
+
|
44 |
+
The resulting tensor will have shape $(B,D,H,W)$, as is typically seen with computer vision models.
|
45 |
+
|
46 |
+
### RADIOv2.5 Notes
|
47 |
+
|
48 |
+
See the [RADIOv2.5 technical report](https://github.com/NVlabs/RADIO/blob/main/RADIOv2.5_tech_report.md).
|
49 |
+
|
50 |
+
## License
|
51 |
+
|
52 |
+
RADIO code and weights are released under the [NSCLv1 License](LICENSE).
|
53 |
+
|
54 |
+
## Citing RADIO
|
55 |
+
|
56 |
+
If you find this repository useful, please consider giving a star and citation:
|
57 |
+
```
|
58 |
+
@misc{ranzinger2023amradio,
|
59 |
+
title={AM-RADIO: Agglomerative Model -- Reduce All Domains Into One},
|
60 |
+
author={Mike Ranzinger and Greg Heinrich and Jan Kautz and Pavlo Molchanov},
|
61 |
+
year={2023},
|
62 |
+
eprint={2312.06709},
|
63 |
+
archivePrefix={arXiv},
|
64 |
+
primaryClass={cs.CV}
|
65 |
+
}
|
66 |
+
```
|