Skip to content
abhivanth edited this page Aug 16, 2020 · 7 revisions

White Matter Hyperintensities Segmentation using U-Net

Steps to be followed for execution of the 'unet_wmh.zip'

Preprocessing the input and ground truth images

Make the below changes in the 'preprocessing.py' file

  1. Update the path and the directory in the below mentioned variables
    • GE3T_DIR = ‘P:\Clean_Datasets_Backup\WMH\Amsterdam_GE3T\GE3T’ # Example path
    • SINGAPORE_DIR = 'P:\Clean_Datasets_Backup\WMH\Singapore\Singapore' # Example path
    • UTRECHT_DIR = 'P:\Clean_Datasets_Backup\WMH\Utrecht\Utrecht' # Example path
  2. Execute the code - Only the 'preprocessing.py'

The output of the program returns the below results

  1. The normalised preprocessed images will be stored in the folders (dir_input, dir_output)
  2. The preprocessed images will be sliced with respect to the z-direction and stored in the folders (out_dir_groudtruth_slices, out_dir_input_slices)
  3. The data dump will be stored locally as 'data_tensor.sav' file

Training the model

  1. Execute the code - Only the 'train_network.py' (no changes required) Note: For each hospital, only 17 out of 20 images were used for training the network, the other 3 were used for testing or validation

The output of the program returns the below results

  1. The model will be trained(200 epochs) and for each epoch, the model will save a 'checkpoint.pth.tar' file in checkpoints folder
  2. The losses for corresponding epoch will be saved locally in a text file as 'plot_loss.txt'

Epoch losses graph plot

  1. Convert the 'plot_loss.txt' file to 'epoch_losses.csv' manually by removing the square brackets from the text file (Reference files are provided)
  2. Execute the code - Only the 'plot_result.py' (verify the input filename and no changes are required)

The output of the program returns the below results

  1. The graph will be plotted and it will be saved locally as a .png file 'epoch_losses.png'

Testing the model

Make the below changes in the 'test.py' file

  1. Update the test_subject = ‘P:\Clean_Datasets_Backup\WMH\Utrecht\Utrecht\49' # Example path
  2. Choose the best 'checkpoint.pth.tar' file and update the path = 'checkpoints\checkpoint_75.pth.tar' # Example

The output of the program returns the below results

  1. Two files will be saved locally as 'prefix_predicted.nii' and 'prefix_actual.nii' (prefix denotes test subject folder name, in this case it is '49_predicted.nii' and '49_actual.nii')