This is a project to classify five levels of clinical dementia rating using MRI, age, and sex of the subject. The project uses CNN based model, developed using Tensorflow, to predict CDR. The trained model can also be used in transfer learning.
- Create a new conda or docker environment with python 3.7.
- Activate the environment.
- Run the commands listed in
requirements.txt
. - Install niftyreg.
- Download the standard ICBM 2009c Nonlinear Symmetric MNI space available here.
Run the command
conda create --name myenv --file spec-file.txt
Download the required data from the folder /project/RDS-SMS-FFgenomics-RW/raquib/cdr/
of Uni Artemis to the local data
folder.
To start the training, run the command
python train.py LOGDIR
Be sure to replace LOGDIR
with the path of your log directory where tensorboard history and model will be saved.
- Register your mri image into standard MNI space ICBM 2009c Nonlinear Symmetric MNI space.
Be sure to replace
reg_aladin -flo PATH_TO_YOUR_MRI -ref PATH_TO_MNI_FILE -res OUTPUT_MRI_PATH
PATH_TO_YOUR_MRI
with the path to your MRI file,PATH_TO_MNI_FILE
path to the MNI file you downloaded, andOUTPUT_MRI_PATH
location where the registered MRI should be saved. - Download the model from 10.6084/m9.figshare.12954521.
- To classify the MRI, follow one of the following two options.
To predict CDR from MRI, age, and sex, run the command:
python predict.py MODEL_PATH IMAGE_PATH AGE SEX
Be sure to replace, MODEL_PATH
with the path of the model (.h5
file) you just downloaded, IMAGE_PATH
with the registered .nii
or .nii.gz
(MRI) file, AGE
with subject's age in years and SEX
with 0
or 1
. Here, 0
indicates male while 1
indicates female. The output will be subject's CDR in the form of one of five numbers: 0, 0.5, 1, 2, or 3.
Note that loading a model requires a few seconds. However the actual time to predict is usually less than a second when a GPU is used.
- Copy the
encoder.py
file in your project which can transform between one hot encoded CDR to normal CDR scale. - Copy the code in
predict.py
and paste it in your code. - Make sure to use registered MRI file for executing the copied code.
The following command does two things. (a) Predict CDR from MRI, age, and sex. (b) Generates and saves the gradcam heatmap.
python gradcam.py MODEL_PATH IMAGE_PATH AGE SEX CDR OUTPUT_PATH
Be sure to replace, MODEL_PATH
with the path of the model (.h5
file) you just downloaded, IMAGE_PATH
with the .nii
or .nii.gz
(MRI) file, AGE
with subject's age in years, SEX
with 0
(male) or 1
(female), CDR
with class label to generate Grad-CAM for, OUTPUT_PATH
with the directory where the generated three dimensional heatmap should be saved. The command will also output the subject's CDR in the form of one of five numbers: 0, 0.5, 1, 2, or 3. For CDR
argument, you can use -1
to produce Grad-CAM for the predicted class.