Git Product home page Git Product logo

4dflownet's Introduction

4DFlowNet

Super Resolution 4D Flow MRI using Residual Neural Network

This is an implementation of the paper 4DFlowNet: Super-Resolution 4D Flow MRI Using Deep Learning and Computational Fluid Dynamics using Tensorflow 2.0 with Keras. Previous implementation on Tensorflow 1.8 can be found in the tf1.8 branch.

Please find the pre-trained networks weights (for both Tensorflow versions) here:

4DFlowNet pre-trained weights

If you are using later Tensorflow 1.x version that is not compatible with this 1.8 version, please refer to Tensorflow backwards compatibility (tf.compat module).

Example results

Below are the example prediction results from an actual 4D Flow MRI of a bifurcation phantom dataset.

LowRes input (voxel size 4mm)

High Res Ground Truth vs noise-free Super Resolution (2mm)

High Res Ground Truth vs noise-free Super Resolution (1mm)

Training setup from CFD data

Prepare dataset

To prepare training or validation dataset, we assume a High resolution CFD dataset is available. As an example we have provided this under /data/example_data_HR.h5

How to prepare training/validation dataset.

1. Generate lowres dataset
    >> Configure the datapath and filenames in prepare_lowres_dataset.py
    >> Run prepare_lowres_dataset.py
    >> This will generate a separate HDF5 file for the low resolution velocity data.
2. Generate random patches from the LR-HR dataset pairs.
    >> Configure the datapath and filenames in prepare_patches.py
    >> Configure patch_size, rotation option, and number of patches per frame
    >> Run prepare_patches.py
    >> This will generate a csv file that contains the patch information.

Training

The training accepts csv files for training and validation set. A benchmark set is used to keep prediction progress everytime a model is being saved as checkpoint. Example csv files are provided in the /data folder.

To run a training for 4DFlowNet:

1. Put all data files (HDF5) and CSV patch index files in the same directory (e.g. /data)
2. Open trainer.py and configure the data_dir and the csv filenames
3. Adjust hyperparameters. The default values from the paper are already provided in the code.
4. Run trainer.py

Adjustable parameters:

Param Description Default
patch_size The image will be split into isotropic patches. Adjust according to computation power and image size. 24
res_increase Upsample ratio. Adjustable to any integer. More upsample ratio requires more computation power. Note: res_increase=1 will denoise the image at the current resolution 2
batch_size Batch size per prediction. Keep it low. 8
initial_learning_rate Initial learning rate 1e-4
epochs maximum number of epochs 1000
mask_threshold Mask threshold for non-binary mask. This is used to measure relative error (accuracy) 0.6
network_name The network name. The model will be saved in this name_timestamp format 4DFlowNet
QUICKSAVE Option to run a "bechmark" dataset everytime a model is saved True
benchmark_file A patch index file (CSV) contains a list of patches. Only the first batch will be read and run into prediction. None
low_resblock Number of residual blocks in low resolution space within 4DFlowNet. 8
hi_resblock Number of residual blocks in high resolution space within 4DFlowNet. 4

Running prediction on MRI data

Prepare data from MRI (for prediction purpose)

To prepare 4D Flow MRI data to HDF5, go to the prepare_data/ directory and run the following script:

>> python prepare_data.py --input-dir [4DFlowMRI_CASE_DIRECTORY]

>> usage: prepare_mri_data.py [-h] --input-dir INPUT_DIR
                       [--output-dir OUTPUT_DIR]
                       [--output-filename OUTPUT_FILENAME]
                       [--phase-pattern PHASE_PATTERN]
                       [--mag-pattern MAG_PATTERN] [--fh-mul FH_MUL]
                       [--rl-mul RL_MUL] [--in-mul IN_MUL]

Notes:

  • The directory must contains the following structure: [CASE_NAME]/[Magnitude_or_Phase]/[TriggerTime]
  • There must be exactly 3 Phase and 3 Magnitude directories
  • To get the required directory structure, DicomSort is recommended. Sort by SeriesDescription -> TriggerTime.
  • In our case, VENC and velocity direction is read from the SequenceName DICOM HEADER. Code might need to be adjusted if the criteria is different.

Prediction

To run the prediction, download first the pre-trained weights. We have provided an example dataset under the data/ folder.

1. Create a directory named models/
2. Put the downloaded 4DFlowNet folder under models/ 
3. Put your dataset under the data/ folder
4. Go to src/ and open predictor.py and configure the input_filename and output_filename if necessary
5. Run predictor.py

Adjustable parameters:

Param Description Default
patch_size The image will be split into isotropic patches. Adjust according to computation power and image size. 24
res_increase Upsample ratio. Adjustable to any integer. More upsample ratio requires more computation power. Note: res_increase=1 will denoise the image at the current resolution 2
batch_size Batch size per prediction. Keep it low. 8
round_small_values Small values are rounded down to zero. Small value is calculated based on venc, according to Velocity per 1 pixel value = venc/2048 True
low_resblock Number of residual blocks in low resolution space within 4DFlowNet. 8
hi_resblock Number of residual blocks in high resolution space within 4DFlowNet. 4

Contact Information

If you encounter any problems in using the code, please open an issue in this repository or feel free to contact me by email.

Author: Edward Ferdian ([email protected]).

4dflownet's People

Contributors

edwardferdian avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.