Overview
- Repo: instructions to train the multimodal EviVLM (vision + text) model using the dataset in
dataset/.
What I changed
- Dataset loader:
code/Load_Dataset_val_SSL.pynow supports loading report text from an Excel file and attaches atextfield to each sample. - New training script:
code/train_evivlm.py— trainsEviVLMcombining segmentation and cross-modal similarity loss. This script does not start training automatically; run it manually. - New inference script:
code/infer_evivlm.py— runs EviVLM inference and saves a panel with Image, GT, UNet, UNet+Text, and a saliency overlay for text interpretability. - Requirements: added
openpyxltorequirements.txtso pandas can read.xlsxfiles.
Files to check
- Dataset loader: code/Load_Dataset_val_SSL.py
- Multimodal model: code/nets/EviVLM.py
- Text encoder: code/backbones/bert_model/TextEncoder.py
- New trainer: code/train_evivlm.py
- Inference script: code/infer_evivlm.py
Dataset (expected)
- Place images and masks under:
dataset/Train_Folder/img/anddataset/Train_Folder/labelcol/dataset/Val_Folder/img/anddataset/Val_Folder/labelcol/
- Provide a single Excel file mapping image filenames to text descriptions (one row per image). Example columns:
image(filename, e.g.case001.png)report(text description)
- By default the trainer looks for
dataset/reports.xlsx(absolute pathd:/VLM_Medical_Imaging/dataset/reports.xlsx). You can pass a different path by editingcode/train_evivlm.pyor running it as a module with modifications.
Text encoder assets
- The text encoder now resolves paths relative to
code/backbones/bert_model/instead of a hard-coded Linux path. - For paper-style training, place the Bio-ClinicalBERT checkpoint files under
code/backbones/bert_model/Bio_ClinicalBERT/, or set:BIO_CLINICAL_BERT_PATHBIO_CLINICAL_BERT_NAME
- If pretrained weights are not available, the code will fall back to a randomly initialized BERT-compatible model so the script can still run, but that is not equivalent to the paper setup.
How to run (example)
- Install dependencies (recommended inside your virtualenv
vlm_env):
pip install -r requirements.txt-
Vision backbone selection lives in
code/Config_SSL.py:vision_backbone = "segformer-b0"usesnvidia/segformer-b0-finetuned-ade-512-512as a frozen SegFormer bottleneck projected into EviVLM.vision_backbone = "unet"restores the original convolutional bottleneck.
-
Run training (example):
python code/train_evivlm.py- Run inference with saliency visualization (example):
python code/infer_evivlm.py --checkpoint ImageEncoder_Pretrain/EviVLM/Pretrain_EviVLM_05.25_14h42/models/best_model-EviVLM.pth.tar --dataset-path D:/VLM_Medical_Imaging/dataset/Test_Folder --report-excel D:/VLM_Medical_Imaging/dataset/reports.xlsx --output-dir D:/VLM_Medical_Imaging/inference_outputsIf the checkpoint was trained with the old visual path, add --vision-backbone unet.
Notes:
code/train_evivlm.pywill automatically used:/VLM_Medical_Imaging/dataset/reports.xlsxif present. Otherwise it will run with empty texts (still trains segmentation only).code/infer_evivlm.pywill use the text reports if the Excel file is available; otherwise it will still produce image-only saliency and prediction outputs.- Tune
lambda_simintrain_evivlm.py(default0.1) to balance segmentation and similarity loss. - If you have a different Excel layout, open
code/Load_Dataset_val_SSL.pyand adjust thereport_sheet,report_col_image, orreport_col_textarguments when constructing the dataset.
Next steps I can do for you
- Wire command-line arguments to
train_evivlm.pyfor flexible paths and hyperparameters. - Add simple unit tests for dataset mapping and a small smoke test that runs one forward pass on CPU.
If you want me to proceed with any of those, tell me which one.