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
File size: 2,902 Bytes
c734504 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | ---
tags:
- feature-extraction
- image-classification
- timm
- radiology
- chest-x-ray
- medical-imaging
library_name: timm
license: mit
pipeline_tag: feature-extraction
inference: false
widget:
- src: https://raw.githubusercontent.com/SZUHvern/MaCo/main/figure/Figure.png
example_title: MaCo masked contrastive learning
---
# Model card for vit_base_patch16_224.maco
A Vision Transformer (ViT-B/16) chest X-ray foundation model encoder. \
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).

## Model Details
- **Model Type:** Feature backbone
- **Developed by**: Weijian Huang, Cheng Li, Hong-Yu Zhou et al. (SZUHvern)
- **Model Stats:**
- Params: 85.8M (base)
- Image size: 224 x 224 x 3
- Patch size: 16 x 16 x 3
- **Pre-training:**
- Dataset: [MIMIC-CXR v2](https://physionet.org/content/mimic-cxr-jpg/2.0.0/)
- Framework: [MaCo](https://github.com/SZUHvern/MaCo), masked contrastive learning (MAE-style masked image reconstruction + image-report contrastive alignment with correlation weighting)
- **Papers:**
- [Enhancing Representation in Radiography-Reports Foundation Model: A Granular Alignment Algorithm Using Masked Contrastive Learning](https://www.nature.com/articles/s41467-024-51749-0)
- **Original:** https://github.com/SZUHvern/MaCo
- **License:** [MIT](https://github.com/SZUHvern/MaCo/blob/main/LICENSE)
## Model Usage
### Image Embeddings
```python
from urllib.request import urlopen
from PIL import Image
import timm
# get example image
img = Image.open(
urlopen(
"https://raw.githubusercontent.com/SZUHvern/MaCo/main/figure/Figure.png"
)
).convert("RGB")
# load model from the hub
model = timm.create_model(
model_name="hf-hub:1aurent/vit_base_patch16_224.maco",
pretrained=True,
).eval()
# get model specific transforms (normalization, resize)
data_config = timm.data.resolve_model_data_config(model)
transforms = timm.data.create_transform(**data_config, is_training=False)
data = transforms(img).unsqueeze(0) # input is a (batch_size, num_channels, img_size, img_size) shaped tensor
output = model(data) # output is a (batch_size, num_features) shaped tensor
```
## Citation
```bibtex
@article{huang2024enhancing,
title={Enhancing representation in radiography-reports foundation model: A granular alignment algorithm using masked contrastive learning},
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},
journal={Nature Communications},
volume={15},
number={7620},
year={2024},
doi={10.1038/s41467-024-51749-0},
url={https://doi.org/10.1038/s41467-024-51749-0}
}
```
|