Title : Denoising diffusion weighted imaging data using CNN¶
Obtaining tissue microstructure measurements from diffusion weighted imaging
(DWI) with multiple, high b-values is crucial. However, the high noise levels
present in these images can adversely affect the accuracy of the
microstructural measurements. In this context, we suggest a straightforward
denoising technique [1] that can be applied to any DWI
dataset as long as a low-noise, single-subject dataset is obtained using the
same DWI sequence.
We created a simple 1D-CNN model with five layers, based on the 1D CNN for
denoising speech. The model consists of two convolutional layers followed by
max-pooling layers, and a dense layer. The first convolutional layer has
16 one-dimensional filters of size 16, and the second layer has 32 filters of
size 8. ReLu activation function is applied to both convolutional layers.
The max-pooling layer has a kernel size of 2 and a stride of 2.
The dense layer maps the features extracted from the noisy image to the
low-noise reference image.
Name of objective function or objective function itself.
If ‘None’, the model will be compiled without any loss function
and can only be used to predict output.
metricslist of metrics, optional
List of metrics to be evaluated by the model during training
and testing.
loss_weightslist or dict, optional
Optional list or dictionary specifying scalar coefficients(floats)
to weight the loss contributions of different model outputs.
The loss value that will be minimized by the model will then be
the weighted sum of all individual losses. If a list, it is
expected to have a 1:1 mapping to the model’s outputs. If a dict,
it is expected to map output names (strings) to scalar
coefficients.
evaluate(x, y, *, batch_size=None, verbose=1, steps=None, callbacks=None, return_dict=False)[source]¶
Evaluate the model on a test dataset.
Parameters:
xndarray
Test dataset (high-noise data). If 4D, it will be converted to 1D.
yndarray
Labels of the test dataset (low-noise data). If 4D, it will be
converted to 1D.
batch_sizeint, optional
Number of samples per gradient update.
verboseint, optional
Verbosity mode. 0 = silent, 1 = progress bar, 2 = one line
per epoch.
stepsint, optional
Total number of steps (batches of samples) before declaring the
evaluation round finished.
callbackslist, optional
List of callbacks to apply during evaluation.
max_queue_sizeint, optional
Maximum size for the generator queue.
workersint, optional
Maximum number of processes to spin up when using process-based
threading.
use_multiprocessingbool, optional
If True, use process-based threading.
return_dictbool, optional
If True, loss and metric results are returned as a dictionary.
Returns:
List or dict
If return_dict is False, returns a list of [loss, metrics]
values on the test dataset. If return_dict is True, returns
a dictionary of metric names and their corresponding values.
The fit method will train the model for a fixed number of epochs
(iterations) on a dataset. If given data is 4D it will convert
it into 1D.
Parameters:
xndarray
The input data, as an ndarray.
yndarray
The target data, as an ndarray.
batch_sizeint or None, optional
Number of samples per batch of computation.
epochsint, optional
The number of epochs.
verbose‘auto’, 0, 1, or 2, optional
Verbosity mode. 0 = silent, 1 = progress bar, 2 = one line
per epoch.
callbackslist of keras.callbacks.Callback instances, optional
List of callbacks to apply during training.
validation_splitfloat between 0 and 1, optional
Fraction of the training data to be used as validation data.
validation_datatuple (x_val, y_val) or None, optional
Data on which to evaluate the loss and any model metrics at
the end of each epoch.
shuffleboolean, optional
This argument is ignored when x is a generator or an object of
tf.data.Dataset.
initial_epochint, optional
Epoch at which to start training.
steps_per_epochint or None, optional
Total number of steps (batches of samples) before declaring one
epoch finished and starting the next epoch.
validation_batch_sizeint or None, optional
Number of samples per validation batch.
validation_stepsint or None, optional
Only relevant if validation_data is provided and is a
tf.data dataset.
validation_freqint or list/tuple/set, optional
Only relevant if validation data is provided. If an integer,
specifies how many training epochs to run before a new validation
run is performed. If a list, tuple, or set, specifies the epochs
on which to run validation.
max_queue_sizeint, optional
Used for generator or keras.utils.Sequence input only.
workersinteger, optional
Used for generator or keras.utils.Sequence input only.
use_multiprocessingboolean, optional
Used for generator or keras.utils.Sequence input only.
Returns:
histobject
A History object. Its History.history attribute is a record of
training loss values and metrics values at successive epochs.
The summary is textual and includes information about:
The layers and their order in the model.
The output shape of each layer.
Returns:
summaryNoneType
the summary of the model
train_test_split(x, y, *, test_size=None, train_size=None, random_state=None, shuffle=True, stratify=None)[source]¶
Split the input data into random train and test subsets.
Parameters:
x: numpy array
input data.
y: numpy array
target data.
test_size: float or int, optional
If float, should be between 0.0 and 1.0 and represent the
proportion of the dataset to include in the test split.
If int, represents the absolute number of test samples.
If None, the value is set to the complement of the train size.
If train_size is also None, it will be set to 0.25.
train_size: float or int, optional
If float, should be between 0.0 and 1.0 and represent the
proportion of the dataset to include in the train split.
If int, represents the absolute number of train samples.
If None, the value is automatically set to the complement of the
test size.
random_state: int, np.random.Generator instance or None, optional
Controls the shuffling applied to the data before applying
the split. Pass an int for reproducible output across multiple
function calls. See Glossary.
shuffle: bool, optional
Whether or not to shuffle the data before splitting.
If shuffle=False then stratify must be None.
stratify: array-like, optional
If not None, data is split in a stratified fashion,
using this as the class labels. Read more in the User Guide.
Returns:
Tuple of four numpy arrays: x_train, x_test, y_train, y_test.
The EVAC+ model [3] is a deep learning neural network for
brain extraction. It uses a V-net architecture combined with
multi-resolution input data, an additional conditional random field (CRF)
recurrent layer and supplementary Dice loss term for this recurrent layer.
Load the model pre-training weights to use for the fitting.
While the user can load different weights, the function
is mainly intended for the class function ‘predict’.
Wrapper function to facilitate prediction of larger dataset.
Parameters:
T1np.ndarray or list of np.ndarray
For a single image, input should be a 3D array.
If multiple images, it should be a a list or tuple.
or list of np.ndarrays with len of batch_size
affinenp.ndarray (4, 4) or (batch, 4, 4)
Affine matrix for the T1 image. Should have
batch dimension if T1 has one.
voxsizenp.ndarray or list or tuple, optional
(3,) or (batch, 3)
voxel size of the T1 image.
batch_sizeint, optional
Number of images per prediction pass. Only available if data
is provided with a batch dimension.
Consider lowering it if you get an out of memory error.
Increase it if you want it to be faster and have a lot of data.
If None, batch_size will be set to 1 if the provided image
has a batch dimension.
return_affinebool, optional
Whether to return the affine matrix. Useful if the input was a
file path.
return_probbool, optional
Whether to return the probability map instead of a
binary mask. Useful for testing.
finalize_maskbool, optional
Whether to remove potential holes or islands.
Useful for solving minor errors.
Returns:
pred_outputnp.ndarray (…) or (batch, …)
Predicted brain mask
affinenp.ndarray (…) or (batch, …)
affine matrix of mask
only if return_affine is True
This class is intended for the ResDNN Histology Network model.
ResDNN [4] is a deep neural network that employs residual
blocks deep neural network to predict ground truth SH coefficients from SH
coefficients computed using DWI data. To this end, authors considered
histology FOD-computed SH coefficients (obtained from ex vivo non-human
primate acquisitions) as their ground truth, and the DWI-computed SH
coefficients as their target.
Wrapper function to facilitate prediction of larger dataset.
The function will mask, normalize, split, predict and ‘re-assemble’
the data as a volume.
Parameters:
datanp.ndarray
DWI signal in a 4D array
gtabGradientTable class instance
The acquisition scheme matching the data (must contain at least
one b0)
masknp.ndarray, optional
Binary mask of the brain to avoid unnecessary computation and
unreliable prediction outside the brain.
Default: Compute prediction only for nonzero voxels (with at least
one nonzero DWI value).
chunk_sizeint, optional
Batch size when running model prediction.
Returns:
pred_sh_coefnp.ndarray (x, y, z, M)
Predicted fODF (as SH). The volume has matching shape to the input
data, but with
(sh_order_max+1)*(sh_order_max+2)/2 as a last
dimension.
Load the model pre-training weights to use for the fitting.
While the user can load different weights, the function
is mainly intended for the class function ‘predict’.
Parameters:
idxint
The idx of the default weights. It can be from 0~4.
Wrapper function to facilitate prediction of larger dataset.
The function will pad the data to meet the required shape of image.
Note that the b0 and T1 image should have the same shape
Parameters:
b0np.ndarray (batch, 77, 91, 77) or (77, 91, 77)
For a single image, input should be a 3D array. If multiple images,
there should also be a batch dimension.
T1np.ndarray (batch, 77, 91, 77) or (77, 91, 77)
For a single image, input should be a 3D array. If multiple images,
there should also be a batch dimension.
batch_sizeint
Number of images per prediction pass. Only available if data
is provided with a batch dimension.
Consider lowering it if you get an out of memory error.
Increase it if you want it to be faster and have a lot of data.
If None, batch_size will be set to 1 if the provided image
has a batch dimension.
Default is None
averagebool
Whether the function follows the Synb0-Disco pipeline and
averages the prediction of 5 different models.
If False, it uses the loaded weights for prediction.
Default is True.
The EVAC+ model [3] is a deep learning neural network for
brain extraction. It uses a V-net architecture combined with
multi-resolution input data, an additional conditional random field (CRF)
recurrent layer and supplementary Dice loss term for this recurrent layer.
Load the model pre-training weights to use for the fitting.
While the user can load different weights, the function
is mainly intended for the class function ‘predict’.
Wrapper function to facilitate prediction of larger dataset.
Parameters:
T1np.ndarray or list of np.ndarray
For a single image, input should be a 3D array.
If multiple images, it should be a a list or tuple.
affinenp.ndarray (4, 4) or (batch, 4, 4)
or list of np.ndarrays with len of batch
Affine matrix for the T1 image. Should have
batch dimension if T1 has one.
voxsizenp.ndarray or list or tuple, optional
(3,) or (batch, 3)
voxel size of the T1 image.
batch_sizeint, optional
Number of images per prediction pass. Only available if data
is provided with a batch dimension.
Consider lowering it if you get an out of memory error.
Increase it if you want it to be faster and have a lot of data.
If None, batch_size will be set to 1 if the provided image
has a batch dimension.
return_affinebool, optional
Whether to return the affine matrix. Useful if the input was a
file path.
return_probbool, optional
Whether to return the probability map instead of a
binary mask. Useful for testing.
finalize_maskbool, optional
Whether to remove potential holes or islands.
Useful for solving minor errors.
Returns:
pred_outputnp.ndarray (…) or (batch, …)
Predicted brain mask
affinenp.ndarray (…) or (batch, …)
affine matrix of mask
only if return_affine is True
This class is intended for the ResDNN Histology Network model.
ResDNN [4] is a deep neural network that employs residual
blocks deep neural network to predict ground truth SH coefficients from SH
coefficients computed using DWI data. To this end, authors considered
histology FOD-computed SH coefficients (obtained from ex vivo non-human
primate acquisitions) as their ground truth, and the DWI-computed SH
coefficients as their target.
Wrapper function to facilitate prediction of larger dataset.
The function will mask, normalize, split, predict and ‘re-assemble’
the data as a volume.
Parameters:
datanp.ndarray
DWI signal in a 4D array
gtabGradientTable class instance
The acquisition scheme matching the data (must contain at least
one b0)
masknp.ndarray, optional
Binary mask of the brain to avoid unnecessary computation and
unreliable prediction outside the brain.
Default: Compute prediction only for nonzero voxels (with at least
one nonzero DWI value).
chunk_sizeint, optional
Batch size when running model prediction.
Returns:
pred_sh_coefnp.ndarray (x, y, z, M)
Predicted fODF (as SH). The volume has matching shape to the input
data, but with
(sh_order_max+1)*(sh_order_max+2)/2 as a last
dimension.