Skip to content

fragalassi/sc-segmentation

 
 

Repository files navigation

Code for project in Domain Adaptation to Bridge the Gap Between MRI Contrasts.

General comments

The spinalcordtoolbox directory is a copy of the Github repo, e.g., some adjustments to paths in module imports to make it work within this repo, and an additional init.py file in the parent folder so that it can be easily imported. When installing the SCT software, the same code is downloaded. One difference between the two is that the pre-trained models are not included in the Github repo whereas they are included in the SCT installation. Alternatively, these models are at https://github.com/spinalcordtoolbox/deepseg_lesion_models (or in this repo in the sct_deepseg_lesion_models/ directory).

The requirements.txt contains the required packages with notes about the installation on Niseko. For installation on a new machine in an isolated virtual environment, uncomment the single comment lines, as these represent cases where the package was already installed on Niseko.

Overview of necessary steps to reproduce the results.

1. im_processing/batch_process.sh

This calls the im_processing/process_registration script which implements the resampling to isotropic, cropping and registration of T2 onto T2*.

2. data-exploration.ipynb

This is for the data visualisation plots, but we first need to extract the relevant patches from the image. This is done with the patch_preprocessing.py script. This script/data is not used in the final modelling, as it was done before the final pipeline was implemented.

3. get_data_split.py

Generate a train/test split including stratification. Adjust the config_file.py parameters to adjust the proportion included in the training/validation set and to set a random seed.

4. preprocessing.py

This implements the pre-model pipeline, including cropping the spinal cord to 48 voxels, extracting patches and normalising. The data is split into the training/test splits generated by the previous script, and stored as Numpy .npz files so that they can be quickly loaded for training. The latest train-test split created will be used by default but a specific version can be specified in the config.py file.

5. train.py

This runs both the fine-tuning on the same contrast and on the opposite contrast. A user-supplied argument controls whether the same contrast or opposite contrast is used and depending on this, the results are saved to separate folders. To specificy the model should train on the opposite contrast, set the -adapt argument to 1.

6. evaluate.py

This is used to get the results for a particular model. Segmentations are generated for all images and all subjects and results are generated for all subjects. The test subjects are used for the calculation of summary stats, but results for all subjects are saved in a subject_scores.csv file. The -model_id argument should always be supplied (see the name of the directory in models/ where the model training logs were saved).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 53.5%
  • Jupyter Notebook 22.8%
  • C++ 16.4%
  • MATLAB 3.2%
  • Shell 2.0%
  • Cython 1.1%
  • Other 1.0%