Repository containing code, models and tutorials for the paper Deep neural networks learn general and clinically relevant representations of the ageing brain

Installation (via terminal and Anaconda)

  1. Clone the github repo
    git clone git@github.com:estenhl/pyment-public.git
  2. Enter the folder
    cd pyment-public
  3. Create a conda environment
    conda create --name pyment python=3.9
  4. Activate environment
    conda activate pyment
  5. Install required packages
    pip install -r requirements.txt
  6. Install Tensorflow
    a. Tensorflow for GPU
    pip install tensorflow-gpu
    b. Tensorflow for CPU
    pip install tensorflow
  7. Source the package
    conda develop .

Preparing data

While the models adhere to the Keras Model interface and can thus be used however one wants, we have provided Dataset/Generator-classes for nifti-files which are used in the tutorials. For these classes to work off-the-shelf the Nifti-data has to be organized in the following folder structure:

.
├── labels.csv
└── images
      ├── image1.nii.gz
      ├── image2.nii.gz
     ...
      └── imageN.nii.gz

where labels.csv is a csv-file with column id (corresponding to image1, image2, etc) and column age.

Preprocessing

Before training the models all images were ran through the following preprocessing pipeline:

  1. Extract brainmask with recon-all -autorecon1 (FreeSurfer)
  2. Transform to *.nii.gz with mri_convert (FreeSurfer)
  3. Translate to FSL space with fslreorient2std (FSL)
  4. Register to MNI space with flirt -dof 6 (FSL, linear registration), and the standard FSL template MNI152_T1_1mm_brain.nii.gz
  5. Crop away borders of [6:173,2:214,0:160]

A full example which downloads the IXI dataset and preprocesses it can be found in the Preprocessing tutorial

Estimating brain age in Python

Estimating brain age using the trained brain age model from the paper consists of downloading the weights, instantiating the model with said weights, and calling Model.fit() with an appropriate generator. A full tutorial (which relies on having a prepared dataset) can be found in the Python prediction tutorial

Instructions for downloading, building and using our docker containers for brain age predictions can be found in the docker-folder