A project for medical image-text retrieval using LLM2CLIP for chest X-ray (CXR) images.
git clone https://github.com/lukeingawesome/llm2clip4cxr.git
cd llm2clip4cxr
pip install -e .
This will install all required dependencies from requirements.txt.
Create CSV files with the following structure:
Anchor CSV (e.g., anchors.csv):
img_path,caption_if
/path/to/image1.jpg,"Chest X-ray shows clear lungs"
/path/to/image2.jpg,"Normal cardiac silhouette"
Candidate Text CSV (e.g., candidates.csv):
caption_if
"Chest X-ray shows clear lungs"
"Normal cardiac silhouette"
"Pneumonia in right lower lobe"
Important Notes:
img_path column should contain the full path to your images (however the column name does not have to be 'img_path')caption column should contain the text descriptions/reports (however the column name does not have to be 'caption')--csv-img-key and --csv-caption-key) are not found in your CSV, the system will show a warning and automatically add fake placeholder columns to prevent errorsDownload the pre-trained model weights from Google Drive and place them in your desired location.
Edit the retrieve.sh script with your specific paths:
#!/usr/bin/env bash
set -e
CUDA_VISIBLE_DEVICES=0 python -u retrieval.py \
--anchors /path/to/your/anchors.csv \
--candidates /path/to/your/candidates.csv \
--clip-ckpt /path/to/your/model/llm2clip4cxr.bin \
--text-base lukeingawesome/llm2vec4cxr \
--csv-img-key img_path \
--csv-caption-key caption_if \
--precision bf16 \
--pooling-mode latent_attention \
--text-max-len 512 \
--batch 16 \
--similarity clip \
--lora-r 16 \
--lora-alpha 32 \
--lora-dropout 0.1 \
--lora-target-modules q_proj,k_proj,v_proj,o_proj \
--save /path/to/output/retrieval_results.csv \
--exit-no-segfault \
--adapter-name llm2clip
Key Parameters to Update:
--anchors: Path to your anchor CSV file--candidates: Path to your candidate text CSV file--clip-ckpt: Path to your downloaded model weights--csv-img-key: Column name for image paths in your CSV (default: img_path)--csv-caption-key: Column name for captions in your CSV (default: caption)--save: Output path for retrieval resultschmod +x retrieve.sh
./retrieve.sh
The model uses the following key components:
lukeingawesome/llm2vec4cxrThe script will generate a CSV file with retrieval results, showing the similarity scores between anchor images and candidate texts.
Training code is currently under development and will be released after thorough sanity checks. Stay tuned for updates!
This project is built on top of LLM2CLIP, which provides the foundational architecture for combining Large Language Models with CLIP for vision-language tasks. We extend their work specifically for chest X-ray (CXR) medical image-text retrieval.
This project is licensed under the MIT License - see the LICENSE file for details.
If you use this code in your research, please cite our paper (citation details to be added) and the original LLM2CLIP work:
@article{ko2025exploring,
title={Exploring the Capabilities of LLM Encoders for Image--Text Retrieval in Chest X-rays},
author={Ko, Hanbin and Cho, Gihun and Baek, Inhyeok and Kim, Donguk and Koo, Joonbeom and Kim, Changi and Lee, Dongheon and Park, Chang Min},
journal={arXiv preprint arXiv:2509.15234},
year={2025}
}
3 commits
Python
99.9%
A project for medical image-text retrieval using LLM2CLIP for chest X-ray (CXR) images.
git clone https://github.com/lukeingawesome/llm2clip4cxr.git
cd llm2clip4cxr
pip install -e .
This will install all required dependencies from requirements.txt.
Create CSV files with the following structure:
Anchor CSV (e.g., anchors.csv):
img_path,caption_if
/path/to/image1.jpg,"Chest X-ray shows clear lungs"
/path/to/image2.jpg,"Normal cardiac silhouette"
Candidate Text CSV (e.g., candidates.csv):
caption_if
"Chest X-ray shows clear lungs"
"Normal cardiac silhouette"
"Pneumonia in right lower lobe"
Important Notes:
img_path column should contain the full path to your images (however the column name does not have to be 'img_path')caption column should contain the text descriptions/reports (however the column name does not have to be 'caption')--csv-img-key and --csv-caption-key) are not found in your CSV, the system will show a warning and automatically add fake placeholder columns to prevent errorsDownload the pre-trained model weights from Google Drive and place them in your desired location.
Edit the retrieve.sh script with your specific paths:
#!/usr/bin/env bash
set -e
CUDA_VISIBLE_DEVICES=0 python -u retrieval.py \
--anchors /path/to/your/anchors.csv \
--candidates /path/to/your/candidates.csv \
--clip-ckpt /path/to/your/model/llm2clip4cxr.bin \
--text-base lukeingawesome/llm2vec4cxr \
--csv-img-key img_path \
--csv-caption-key caption_if \
--precision bf16 \
--pooling-mode latent_attention \
--text-max-len 512 \
--batch 16 \
--similarity clip \
--lora-r 16 \
--lora-alpha 32 \
--lora-dropout 0.1 \
--lora-target-modules q_proj,k_proj,v_proj,o_proj \
--save /path/to/output/retrieval_results.csv \
--exit-no-segfault \
--adapter-name llm2clip
Key Parameters to Update:
--anchors: Path to your anchor CSV file--candidates: Path to your candidate text CSV file--clip-ckpt: Path to your downloaded model weights--csv-img-key: Column name for image paths in your CSV (default: img_path)--csv-caption-key: Column name for captions in your CSV (default: caption)--save: Output path for retrieval resultschmod +x retrieve.sh
./retrieve.sh
The model uses the following key components:
lukeingawesome/llm2vec4cxrThe script will generate a CSV file with retrieval results, showing the similarity scores between anchor images and candidate texts.
Training code is currently under development and will be released after thorough sanity checks. Stay tuned for updates!
This project is built on top of LLM2CLIP, which provides the foundational architecture for combining Large Language Models with CLIP for vision-language tasks. We extend their work specifically for chest X-ray (CXR) medical image-text retrieval.
This project is licensed under the MIT License - see the LICENSE file for details.
If you use this code in your research, please cite our paper (citation details to be added) and the original LLM2CLIP work:
@article{ko2025exploring,
title={Exploring the Capabilities of LLM Encoders for Image--Text Retrieval in Chest X-rays},
author={Ko, Hanbin and Cho, Gihun and Baek, Inhyeok and Kim, Donguk and Koo, Joonbeom and Kim, Changi and Lee, Dongheon and Park, Chang Min},
journal={arXiv preprint arXiv:2509.15234},
year={2025}
}
3 commits
Python
99.9%