--- tags: - feature-extraction - image-classification - timm - license:apache-2.0 - radiology - chest-x-ray library_name: timm pipeline_tag: feature-extraction license: apache-2.0 inference: false --- # Model card for vit_base_patch16_224.carzero Vision encoder (ViT-B/16) of [CARZero](https://github.com/laihaoran/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. ![](https://github.com/laihaoran/CARZero/raw/main/CARZero.png) ## Model Details - **Model Type:** Feature backbone (vision tower of a multimodal vision-language model) - **Developed by:** Haoran Lai, Qingsong Yao, Zihang Jiang, Rongsheng Wang, Zhiyang He, Xiaodong Tao, S. Kevin Zhou (University of Science and Technology of China) - **Model Stats:** - Params: 85.8M (ViT-B/16: embed dim 768, depth 12, heads 12, MLP ratio 4) - Image size: 224 x 224 x 3 - Patch size: 16 x 16 x 3 - **Pre-training:** - Dataset: [MIMIC-CXR](https://physionet.org/content/mimic-cxr/1.0.0/) (377,110 chest X-rays) - Framework: MAE/M3AE masked image modeling initialization, then CARZero cross-attention alignment fine-tuning - Source checkpoint: `CARZero_best_model.ckpt` (Google Drive id `1kYF-k5otW5DHwz1En5d_ScV3zu2E27Ch`), vision tower keys `CARZero.img_encoder.model.*` remapped 1:1 to timm layout - **Preprocessing (upstream eval pipeline):** grayscale read, resize longest side to 256 with `cv2.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) - **Papers:** - [CARZero: Cross-Attention Alignment for Radiology Zero-Shot Classification](https://arxiv.org/abs/2402.17417) (CVPR 2024, pp. 11137-11146, DOI 10.1109/CVPR52733.2024.01059) - **Original:** https://github.com/laihaoran/CARZero - **License:** [Apache-2.0](https://github.com/laihaoran/CARZero/blob/main/LICENSE) ## Model Usage ### Image Embeddings ```python 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 ``` ## Citation ```bibtex @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} } ```