This repository contains an anonymized code artifact for radiology vision-language experiments. It includes the main components used to construct fine-grained radiology alignment data, train a radiology FG-CLIP model, and evaluate downstream retrieval, classification, and report-generation tasks.
Raw datasets, model checkpoints, and some third-party baseline packages are not provided in this repository.
arr_radiology_code_submission/
├── configs/ # DeepSpeed and classification prompt configs
├── docs/ # Data schema and code maps
├── scripts/ # Reproducible entry-point wrappers
├── src/
│ ├── dataset/ # Data construction and manifest builders
│ ├── evaluation/ # Retrieval and classification evaluators
│ ├── extract/ # Feature extraction for report generation
│ ├── fgclip_sim/ # FG-CLIP model and training code
│ ├── inference/ # Report generation and GREEN evaluation
│ ├── report_gen_decoder/ # Encoder-decoder report-generation modules
│ └── train_report_generation.py
├── pyproject.toml
├── requirements.txt
└── README.md
Create a Python environment and install the package from the repository root:
cd /path/to/arr_radiology_code_submission
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e .
python -m pip install -r requirements.txt
FG-CLIP training uses DeepSpeed, and report scoring uses GREEN. Install those optional packages in the same environment if you plan to run the corresponding stages:
python -m pip install deepspeed
For MedImageInsight-based training and feature extraction, point the code to a local MedImageInsight package and checkpoint directory:
export MEDIMAGEINSIGHT_PACKAGE_ROOT=/path/to/MedImageInsights
export MEDIMAGEINSIGHT_MODEL_DIR=/path/to/MedImageInsights/model
export MEDIMAGEINSIGHT_VISION_MODEL=vision_model.pth
export MEDIMAGEINSIGHT_LANGUAGE_MODEL=language_model.pth
The FG-CLIP trainer expects a JSON manifest described in docs/dataset_schema.md. The expected high-level structure is:
{
"caption": "study-level report text",
"f_path": "relative/path/to/image.jpg",
"observations": [
{
"obs_text": "Left basilar opacity is present.",
"hard_negatives": ["Right basilar opacity is present."],
"regions": [
{"region_name": "Left Lung", "bbox": [0, 0, 128, 128]}
]
}
]
}
A convenient local data layout is:
data/
├── raw/images/
├── intermediate/
│ ├── base_records.json
│ ├── all_disease_sentences.json
│ └── observation_sentences.json
├── processed/
│ └── region_coordinates.json
├── classification/
│ ├── train.json
│ └── test.json
└── report_generation/
├── pretrain_train.json
├── pretrain_val.json
├── train.json
├── validation.json
└── test.json
The data-construction pipeline is:
data/intermediate/base_records.json, a JSON list of image/report records.src/dataset/split_sentences.py.src/dataset/select_regions.py.src/dataset/segment_regions.py, producing data/processed/region_coordinates.json.src/dataset/generate_hard_negatives.py.src/dataset/build_training_manifest.py.split_sentences.py, select_regions.py, and generate_hard_negatives.py use google/medgemma-27b-text-it by default. If you use another medical LLM, keep the output JSON/JSONL schema compatible with the merge step.
Run anatomy segmentation separately:
python src/dataset/segment_regions.py \
--image_root data/raw/images \
--input_json data/intermediate/base_records.json \
--output_json data/processed/region_coordinates.json
Then run the wrapper for the remaining preprocessing and manifest merge:
bash scripts/prepare_dataset.sh
The resulting FG-CLIP training manifest is written to data/processed/train_fgclip_manifest.json.
The FG-CLIP implementation lives in src/fgclip_sim/. The radiology training recipe extends CLIP-style image-text contrastive learning with:
Train with:
bash scripts/train_fgclip.sh
The wrapper calls src/fgclip_sim/train/train_mem.py through DeepSpeed and writes checkpoints under outputs/fgclip_ours/. Edit the script or call the Python entry point directly if you need different batch sizes, epochs, data paths, or checkpoint locations.
Retrieval evaluation is feature-based. It assumes one aligned image embedding and one aligned text embedding per example.
Place embeddings at:
outputs/retrieval/<backbone>_image_embeddings.pt
outputs/retrieval/<backbone>_text_embeddings.pt
Then run:
BACKBONE=ours bash scripts/eval_retrieval.sh
BACKBONE=pubmedclip bash scripts/eval_retrieval.sh
The evaluator is src/evaluation/retrieval_eval.py and reports image-to-text and text-to-image recall at configurable k values.
src/evaluation/classification_eval.py supports linear probing and prompt-based zero-shot classification with FG-CLIP checkpoints. The default wrapper uses:
data/classification/train.jsondata/classification/test.jsondata/raw/imagesoutputs/fgclip_ours/checkpoint-lastconfigs/classification_prompts_chexpert.jsonRun:
bash scripts/eval_classification.sh
For zero-shot-only evaluation, call the Python entry point directly with --zero_shot --prompt_json configs/classification_prompts_chexpert.json.
The report-generation pipeline trains a lightweight decoder over precomputed image patch features. The relevant modules are:
src/extract/src/train_report_generation.pysrc/inference/run_inference.pysrc/inference/evaluate_green.pySupported feature-extraction backbones include medclip, pubmedclip, radclip, raddino, cxrclip, gloria, medimageinsight, and ours.
Extract features:
BACKBONE=medclip bash scripts/extract_report_features.sh
BACKBONE=ours bash scripts/extract_report_features.sh
Train the report decoder:
BACKBONE=ours ENCODER_TYPE=identity bash scripts/train_report_decoder.sh
Run inference:
MODEL_NAME=ours bash scripts/run_report_inference.sh
Evaluate generated reports with GREEN:
python src/inference/evaluate_green.py \
--input-json outputs/inference/ours_test.json \
--output-dir outputs/green_eval
For the ours backbone, the expected setup is to extract MedImageInsight patch features with the trained FG-CLIP visual weights loaded.
The following resources must be supplied locally to run the full pipeline:
Suggested local paths are:
external/MedImageInsights/
external/cxr-clip/
external/gloria/
checkpoints/
outputs/
outputs/; intermediate prepared data is expected under data/.Python
98.4%
Shell
1.6%
This repository contains an anonymized code artifact for radiology vision-language experiments. It includes the main components used to construct fine-grained radiology alignment data, train a radiology FG-CLIP model, and evaluate downstream retrieval, classification, and report-generation tasks.
Raw datasets, model checkpoints, and some third-party baseline packages are not provided in this repository.
arr_radiology_code_submission/
├── configs/ # DeepSpeed and classification prompt configs
├── docs/ # Data schema and code maps
├── scripts/ # Reproducible entry-point wrappers
├── src/
│ ├── dataset/ # Data construction and manifest builders
│ ├── evaluation/ # Retrieval and classification evaluators
│ ├── extract/ # Feature extraction for report generation
│ ├── fgclip_sim/ # FG-CLIP model and training code
│ ├── inference/ # Report generation and GREEN evaluation
│ ├── report_gen_decoder/ # Encoder-decoder report-generation modules
│ └── train_report_generation.py
├── pyproject.toml
├── requirements.txt
└── README.md
Create a Python environment and install the package from the repository root:
cd /path/to/arr_radiology_code_submission
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e .
python -m pip install -r requirements.txt
FG-CLIP training uses DeepSpeed, and report scoring uses GREEN. Install those optional packages in the same environment if you plan to run the corresponding stages:
python -m pip install deepspeed
For MedImageInsight-based training and feature extraction, point the code to a local MedImageInsight package and checkpoint directory:
export MEDIMAGEINSIGHT_PACKAGE_ROOT=/path/to/MedImageInsights
export MEDIMAGEINSIGHT_MODEL_DIR=/path/to/MedImageInsights/model
export MEDIMAGEINSIGHT_VISION_MODEL=vision_model.pth
export MEDIMAGEINSIGHT_LANGUAGE_MODEL=language_model.pth
The FG-CLIP trainer expects a JSON manifest described in docs/dataset_schema.md. The expected high-level structure is:
{
"caption": "study-level report text",
"f_path": "relative/path/to/image.jpg",
"observations": [
{
"obs_text": "Left basilar opacity is present.",
"hard_negatives": ["Right basilar opacity is present."],
"regions": [
{"region_name": "Left Lung", "bbox": [0, 0, 128, 128]}
]
}
]
}
A convenient local data layout is:
data/
├── raw/images/
├── intermediate/
│ ├── base_records.json
│ ├── all_disease_sentences.json
│ └── observation_sentences.json
├── processed/
│ └── region_coordinates.json
├── classification/
│ ├── train.json
│ └── test.json
└── report_generation/
├── pretrain_train.json
├── pretrain_val.json
├── train.json
├── validation.json
└── test.json
The data-construction pipeline is:
data/intermediate/base_records.json, a JSON list of image/report records.src/dataset/split_sentences.py.src/dataset/select_regions.py.src/dataset/segment_regions.py, producing data/processed/region_coordinates.json.src/dataset/generate_hard_negatives.py.src/dataset/build_training_manifest.py.split_sentences.py, select_regions.py, and generate_hard_negatives.py use google/medgemma-27b-text-it by default. If you use another medical LLM, keep the output JSON/JSONL schema compatible with the merge step.
Run anatomy segmentation separately:
python src/dataset/segment_regions.py \
--image_root data/raw/images \
--input_json data/intermediate/base_records.json \
--output_json data/processed/region_coordinates.json
Then run the wrapper for the remaining preprocessing and manifest merge:
bash scripts/prepare_dataset.sh
The resulting FG-CLIP training manifest is written to data/processed/train_fgclip_manifest.json.
The FG-CLIP implementation lives in src/fgclip_sim/. The radiology training recipe extends CLIP-style image-text contrastive learning with:
Train with:
bash scripts/train_fgclip.sh
The wrapper calls src/fgclip_sim/train/train_mem.py through DeepSpeed and writes checkpoints under outputs/fgclip_ours/. Edit the script or call the Python entry point directly if you need different batch sizes, epochs, data paths, or checkpoint locations.
Retrieval evaluation is feature-based. It assumes one aligned image embedding and one aligned text embedding per example.
Place embeddings at:
outputs/retrieval/<backbone>_image_embeddings.pt
outputs/retrieval/<backbone>_text_embeddings.pt
Then run:
BACKBONE=ours bash scripts/eval_retrieval.sh
BACKBONE=pubmedclip bash scripts/eval_retrieval.sh
The evaluator is src/evaluation/retrieval_eval.py and reports image-to-text and text-to-image recall at configurable k values.
src/evaluation/classification_eval.py supports linear probing and prompt-based zero-shot classification with FG-CLIP checkpoints. The default wrapper uses:
data/classification/train.jsondata/classification/test.jsondata/raw/imagesoutputs/fgclip_ours/checkpoint-lastconfigs/classification_prompts_chexpert.jsonRun:
bash scripts/eval_classification.sh
For zero-shot-only evaluation, call the Python entry point directly with --zero_shot --prompt_json configs/classification_prompts_chexpert.json.
The report-generation pipeline trains a lightweight decoder over precomputed image patch features. The relevant modules are:
src/extract/src/train_report_generation.pysrc/inference/run_inference.pysrc/inference/evaluate_green.pySupported feature-extraction backbones include medclip, pubmedclip, radclip, raddino, cxrclip, gloria, medimageinsight, and ours.
Extract features:
BACKBONE=medclip bash scripts/extract_report_features.sh
BACKBONE=ours bash scripts/extract_report_features.sh
Train the report decoder:
BACKBONE=ours ENCODER_TYPE=identity bash scripts/train_report_decoder.sh
Run inference:
MODEL_NAME=ours bash scripts/run_report_inference.sh
Evaluate generated reports with GREEN:
python src/inference/evaluate_green.py \
--input-json outputs/inference/ours_test.json \
--output-dir outputs/green_eval
For the ours backbone, the expected setup is to extract MedImageInsight patch features with the trained FG-CLIP visual weights loaded.
The following resources must be supplied locally to run the full pipeline:
Suggested local paths are:
external/MedImageInsights/
external/cxr-clip/
external/gloria/
checkpoints/
outputs/
outputs/; intermediate prepared data is expected under data/.Python
98.4%
Shell
1.6%