About - Authors - Project structure - Getting started - How To Run Experiments - Input and Output - Credits - License
This repository contains a deep learning project developed in collaboration with Gustave Roussy Hospital, within Machine Learning course at EPFL.
Correctly identifying tumor lesions on Computed Tomography (CT) scans is a crucial task in cancer diagnosis and treatment. Developing and improving deep learning models to automate tumor segmentation, thereby supporting radiologists’ work, could significantly reduce diagnostic errors and the time required to obtain a diagnosis. In this work, we propose a comprehensive pipeline for processing language–vision medical datasets and a 3D vision–language segmentation model comprising of a Language-Guided vision encoder with a Scale-aware Vision–Language Attention module, a Full-scale decoder, and a loss combining segmentation errors and contrastive errors. We compare and validate our approach on a model previously built at Gustave Roussy on abdominal CT scans with liver cancer lesions. Please cite the repo if you use our code :)
We provide Hydra-based execution scripts (with corresponding configs) to reproduce the full pipeline described in the report: preprocessing a dataset of CT volumes (NIfTI), segmentation masks (NIfTI), and text prompts (JSON), training the model, and running inference on new samples. The implementation is available in src and is documented throughout the codebase.
src/configscontains hydra configurations.src/modelcontains the blocks of our network and the main blockLSMS_model.pysrc/datasetscontains functions and main classes to proprocess the dataset and the main dataloader classessrc/losscontains our losses classessrc/infercontains helper functions to segment lesions on new CT scanspreprocess.pyis the main file to preprocess the dataset.train_1.pyis the main file to train on the dataset with our proposed model.infer_1.pyis the main file to infer on a new CT scan.train_old_model.pyis the main file to train on the dataset with the baseline model.
Python version: Python >= 3.9, <= 3.10 (tested on 3.10)
0. (Optional) Create and activate new environment using conda or venv (+pyenv).
a. conda version:
# create env
conda create -n project_env python=PYTHON_VERSION
# activate env
conda activate project_envb. venv version:
# create env
python -m venv project_env
# activate env
source project_env/bin/activate-
Install all required packages to run
pip install -r requirements.txt
-
(Optional) Install
pre-commit:pre-commit install
-
Follow the instructions to extract the dataset as
.tararchive detailed in Input and Output. Back to top
Run the experiments after checking Input and Output.
- To preprocess dataset with the report configuration
python preprocess.py - To train experiment 1 with our proposed model
python train_1.py dataset._target_=src.datasets.MedVLSet #(To modify configs of new model in general go to `baseline.yaml`) - To train experiment 1 with the baseline model
python train_old_model.py dataset._target_=src.datasets.MedVLSet #(To modify configs of old model in general go to `baseline_old.yaml`) - To train experiment 2 with our proposed model
python train_1.py dataset._target_=src.datasets.MedVLSet2- To train experiment 2 with the baseline model
python train_old_model.py dataset._target_=src.datasets.MedVLSet2- To infer on a new CT scan:
-
Inference config (
infer.yaml): setct(preprocessed CT path),features(training features path),model(weights path), andout(output file path). Provide the patient text inpromptand choosemodel_type(LSMS= proposed,LSMSLite= baseline). -
Training config (
baseline.yaml): setpatches_per_patientto1(single patch per patient) or8(multiple patches per patient).python infer_1.py
Dataset
We preprocessed and trained on a subsample of liver cancer patients extracted from the public dataset AbdomenAtlas 3.0.
You can extract the already preprocessed sample from this drive, together with lsms_liver_prompts.json.
After downloading locally lsms_liver_subset.tar and lsms_liver_prompts.json, follow the instructions below.
Windows 10/11
-
Open PowerShell or Command Prompt
-
Go to the directory containing the archive:
cd D:\path\to\archive
-
Extract:
tar -xf dataset.tar -
Write in
src/configs/dataloader/preprocessing.yamlandsrc/configs/datasets/preprocessing.yaml, inrootand inpromptsthe directory where you extractedlsms_liver_subset.tarand downloadedlsms_liver_prompts.json.
WSL
-
Extract:
cd /mnt/d/path/to/archive tar -xf dataset.tar -
Write in
src/configs/dataloader/preprocessing.yamlandsrc/configs/datasets/preprocessing.yaml, inrootand inpromptsthe directory where you extractedlsms_liver_subset.tarand downloadedlsms_liver_prompts.json.
macOS
-
Open Terminal
-
macOS ships with BSD tar:
cd /Volumes/DriveName/path/to/archive tar -xf dataset.tar -
Write in
src/configs/dataloader/preprocessing.yamlandsrc/configs/datasets/preprocessing.yaml, inrootand inpromptsthe directory where you extractedlsms_liver_subset.tarand downloadedlsms_liver_prompts.json.
Experiments output
The outputs of the experiments described in the report can be found in drive as well.
best_modelfolder contains the output of experiment 2 with our proposed model.old_model_with_patchesfolder contains the output of experiment 2 with the Gustave Roussy model.new_model_without_patchesfolder contains the output of experiment 1 with our proposed model.old_model_without_patchesfolder contains the output of experiment 1 with the Gustave Roussy model.
This repository is based on a heavily modified fork of pytorch-template and asr_project_template repositories.
Back to top