CARZero models
Collection
CARZero: Cross-Attention Alignment for Radiology Zero-Shot Classification (CVPR 2024, arXiv:2402.17417), https://github.com/laihaoran/CARZero • 2 items • Updated
How to use 1aurent/vit_base_patch16_224.carzero with timm:
import timm
model = timm.create_model("hf-hub:1aurent/vit_base_patch16_224.carzero", pretrained=True)Vision encoder (ViT-B/16) of CARZero (CVPR 2024), a cross-attention alignment framework for radiology zero-shot classification. The encoder is a ViT-B/16 initialized with MAE/M3AE masked image modeling and fine-tuned on MIMIC-CXR chest X-rays with CARZero cross-attention alignment against radiology reports. Only the vision tower of the released CARZero_best_model.ckpt is ported here (encoder-only, num_classes=0); the text encoder (BioClinicalMPBERT) and cross-attention fusion module are not included.
CARZero_best_model.ckpt (Google Drive id 1kYF-k5otW5DHwz1En5d_ScV3zu2E27Ch), vision tower keys CARZero.img_encoder.model.* remapped 1:1 to timm layoutcv2.INTER_AREA (~ box), zero-pad to 256x256, center crop 224, normalize with CXR stats mean=0.4978, std=0.2449 (the pretrained_cfg records the closest standard timm transform: box interpolation, crop_pct 0.875, center crop)from urllib.request import urlopen
from PIL import Image
import timm
# get example chest X-ray image (NIH ChestX-ray14 sample, via torchxrayvision)
img = Image.open(
urlopen(
"https://raw.githubusercontent.com/mlmed/torchxrayvision/master/tests/00000001_000.png"
)
).convert("RGB")
# load model from the hub
model = timm.create_model(
model_name="hf-hub:1aurent/vit_base_patch16_224.carzero",
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
@inproceedings{lai2024carzero,
title={CARZero: Cross-Attention Alignment for Radiology Zero-Shot Classification},
author={Lai, Haoran and Yao, Qingsong and Jiang, Zihang and Wang, Rongsheng and He, Zhiyang and Tao, Xiaodong and Zhou, S. Kevin},
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
pages={11137--11146},
year={2024},
doi={10.1109/CVPR52733.2024.01059}
}