Instructions to use 1aurent/vit_base_patch16_224.maco with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- timm
How to use 1aurent/vit_base_patch16_224.maco with timm:
import timm model = timm.create_model("hf-hub:1aurent/vit_base_patch16_224.maco", pretrained=True) - Notebooks
- Google Colab
- Kaggle
Add vit_base_patch16_224.maco (timm re-upload of official MaCo encoder; bit-identical 150/150, parity 0.0)
Browse files- README.md +82 -0
- config.json +47 -0
- model.safetensors +3 -0
README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
tags:
|
| 3 |
+
- feature-extraction
|
| 4 |
+
- image-classification
|
| 5 |
+
- timm
|
| 6 |
+
- radiology
|
| 7 |
+
- chest-x-ray
|
| 8 |
+
- medical-imaging
|
| 9 |
+
library_name: timm
|
| 10 |
+
license: mit
|
| 11 |
+
pipeline_tag: feature-extraction
|
| 12 |
+
inference: false
|
| 13 |
+
widget:
|
| 14 |
+
- src: https://raw.githubusercontent.com/SZUHvern/MaCo/main/figure/Figure.png
|
| 15 |
+
example_title: MaCo masked contrastive learning
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# Model card for vit_base_patch16_224.maco
|
| 19 |
+
|
| 20 |
+
A Vision Transformer (ViT-B/16) chest X-ray foundation model encoder. \
|
| 21 |
+
MaCo pre-trains a ViT-B/16 image encoder jointly with a BERT report encoder on MIMIC-CXR using masked contrastive learning with granular radiography-report alignment (Huang et al., Nature Communications 2024).
|
| 22 |
+
|
| 23 |
+

|
| 24 |
+
|
| 25 |
+
## Model Details
|
| 26 |
+
|
| 27 |
+
- **Model Type:** Feature backbone
|
| 28 |
+
- **Developed by**: Weijian Huang, Cheng Li, Hong-Yu Zhou et al. (SZUHvern)
|
| 29 |
+
- **Model Stats:**
|
| 30 |
+
- Params: 85.8M (base)
|
| 31 |
+
- Image size: 224 x 224 x 3
|
| 32 |
+
- Patch size: 16 x 16 x 3
|
| 33 |
+
- **Pre-training:**
|
| 34 |
+
- Dataset: [MIMIC-CXR v2](https://physionet.org/content/mimic-cxr-jpg/2.0.0/)
|
| 35 |
+
- Framework: [MaCo](https://github.com/SZUHvern/MaCo), masked contrastive learning (MAE-style masked image reconstruction + image-report contrastive alignment with correlation weighting)
|
| 36 |
+
- **Papers:**
|
| 37 |
+
- [Enhancing Representation in Radiography-Reports Foundation Model: A Granular Alignment Algorithm Using Masked Contrastive Learning](https://www.nature.com/articles/s41467-024-51749-0)
|
| 38 |
+
- **Original:** https://github.com/SZUHvern/MaCo
|
| 39 |
+
- **License:** [MIT](https://github.com/SZUHvern/MaCo/blob/main/LICENSE)
|
| 40 |
+
|
| 41 |
+
## Model Usage
|
| 42 |
+
|
| 43 |
+
### Image Embeddings
|
| 44 |
+
```python
|
| 45 |
+
from urllib.request import urlopen
|
| 46 |
+
from PIL import Image
|
| 47 |
+
import timm
|
| 48 |
+
|
| 49 |
+
# get example image
|
| 50 |
+
img = Image.open(
|
| 51 |
+
urlopen(
|
| 52 |
+
"https://raw.githubusercontent.com/SZUHvern/MaCo/main/figure/Figure.png"
|
| 53 |
+
)
|
| 54 |
+
).convert("RGB")
|
| 55 |
+
|
| 56 |
+
# load model from the hub
|
| 57 |
+
model = timm.create_model(
|
| 58 |
+
model_name="hf-hub:1aurent/vit_base_patch16_224.maco",
|
| 59 |
+
pretrained=True,
|
| 60 |
+
).eval()
|
| 61 |
+
|
| 62 |
+
# get model specific transforms (normalization, resize)
|
| 63 |
+
data_config = timm.data.resolve_model_data_config(model)
|
| 64 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
| 65 |
+
|
| 66 |
+
data = transforms(img).unsqueeze(0) # input is a (batch_size, num_channels, img_size, img_size) shaped tensor
|
| 67 |
+
output = model(data) # output is a (batch_size, num_features) shaped tensor
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
## Citation
|
| 71 |
+
```bibtex
|
| 72 |
+
@article{huang2024enhancing,
|
| 73 |
+
title={Enhancing representation in radiography-reports foundation model: A granular alignment algorithm using masked contrastive learning},
|
| 74 |
+
author={Huang, Weijian and Li, Cheng and Zhou, Hong-Yu and Yang, Hao and Liu, Jiarun and Liang, Yong and Zheng, Hairong and Zhang, Shaoting and Wang, Shanshan},
|
| 75 |
+
journal={Nature Communications},
|
| 76 |
+
volume={15},
|
| 77 |
+
number={7620},
|
| 78 |
+
year={2024},
|
| 79 |
+
doi={10.1038/s41467-024-51749-0},
|
| 80 |
+
url={https://doi.org/10.1038/s41467-024-51749-0}
|
| 81 |
+
}
|
| 82 |
+
```
|
config.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architecture": "vit_base_patch16_224",
|
| 3 |
+
"num_classes": 0,
|
| 4 |
+
"num_features": 768,
|
| 5 |
+
"global_pool": "token",
|
| 6 |
+
"model_args": {
|
| 7 |
+
"img_size": 224,
|
| 8 |
+
"patch_size": 16,
|
| 9 |
+
"in_chans": 3,
|
| 10 |
+
"embed_dim": 768,
|
| 11 |
+
"depth": 12,
|
| 12 |
+
"num_heads": 12,
|
| 13 |
+
"mlp_ratio": 4.0,
|
| 14 |
+
"qkv_bias": true,
|
| 15 |
+
"num_classes": 0,
|
| 16 |
+
"global_pool": "token"
|
| 17 |
+
},
|
| 18 |
+
"pretrained_cfg": {
|
| 19 |
+
"tag": "maco",
|
| 20 |
+
"custom_load": false,
|
| 21 |
+
"input_size": [
|
| 22 |
+
3,
|
| 23 |
+
224,
|
| 24 |
+
224
|
| 25 |
+
],
|
| 26 |
+
"fixed_input_size": true,
|
| 27 |
+
"interpolation": "bilinear",
|
| 28 |
+
"crop_pct": 1,
|
| 29 |
+
"crop_mode": "center",
|
| 30 |
+
"mean": [
|
| 31 |
+
0.4978,
|
| 32 |
+
0.4978,
|
| 33 |
+
0.4978
|
| 34 |
+
],
|
| 35 |
+
"std": [
|
| 36 |
+
0.2449,
|
| 37 |
+
0.2449,
|
| 38 |
+
0.2449
|
| 39 |
+
],
|
| 40 |
+
"num_classes": 0,
|
| 41 |
+
"pool_size": null,
|
| 42 |
+
"first_conv": "patch_embed.proj",
|
| 43 |
+
"classifier": "head",
|
| 44 |
+
"license": "mit",
|
| 45 |
+
"hf_hub_id": "1aurent/vit_base_patch16_224.maco"
|
| 46 |
+
}
|
| 47 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a387a7e663d0431e6919198200b260bda25bc9f2bfd151bffa3bb57bb6c9099f
|
| 3 |
+
size 343208584
|