Configuration File¶
All parameters used for loading data, training and predicting are contained within a single JSON configuration file. This section describes how to set up this configuration file.
For convenience, here is an generic configuration file: config_config.json.
Below are other, more specific configuration files:
- config_classification.json: Trains a classification model.
- config_sctTesting.json: Trains a 2D segmentation task with the U-Net architecture.
- config_spineGeHemis.json: Trains a segmentation task with the HeMIS-UNet architecture.
- config_tumorSeg.json: Trains a segmentation task with a 3D U-Net architecture.
General Parameters¶
command¶
Run the specified command. | |
type | string |
options | |
train |
train a model on a training/validation sub-datasets |
test |
evaluate a trained model on a testing sub-dataset |
segment |
segment a entire dataset using a trained model |
{
"command": "train"
}
gpu_ids¶
List of IDs of one or more GPUs to use. | |
type | list * integer |
{
"gpu_ids": [1,2,3]
}
Note
Currently only ivadomed_automate_training
supports the use of more than one GPU.
log_directory¶
Folder name that will contain the output files (e.g., trained model, predictions, results). | |
type | string |
{
"log_directory": "tmp/spineGeneric"
}
model_name¶
Folder name containing the trained model (ONNX format) and its configuration file, located within log_directory/ |
|
type | string |
"log_directory/seg_gm_t2star/seg_gm_t2star.onnx"
"log_directory/seg_gm_t2star/seg_gm_t2star.json"
When possible, the folder name will follow the following convention:
task_(animal)_region_(contrast)
with
task = {seg, label, find}
animal = {human, dog, cat, rat, mouse, ...}
region = {sc, gm, csf, brainstem, ...}
contrast = {t1, t2, t2star, dwi, ...}
{
"model_name": "seg_gm_t2star"
}
debugging¶
Extended verbosity and intermediate outputs. | |
type | boolean |
{
"debugging": true
}
Loader Parameters¶
path_data¶
Path of the BIDS folder. | |
type | string |
{
"loader_parameters": {
"path_data": "path/to/data_example_spinegeneric"
}
}
bids_config¶
(Optional). Path of the custom BIDS configuration file for BIDS non-compliant modalities | |
type | string |
{
"loader_parameters": {
"bids_config": "ivadomed/config/config_bids.json"
}
}
subject_selection¶
Used to specify a custom subject selection from a dataset. | ||
type | dict | |
options | ||
n |
List containing the number subjects of each metadata. | |
type | list | |
metadata |
List of metadata used to select the subjects. Each metadata should be the name of a column from the participants.tsv file. |
|
type | list | |
value |
List of metadata values of the subject to be selected. | |
type | list |
{
"loader_parameters": {
"subject_selection": {
"n": [5, 10],
"metadata": ["disease", "disease"],
"value": ["healthy", "ms"]
}
}
}
In this example, a subdataset composed of 5 healthy subjects and 10 ms subjects will be selected for training/testing.
target_suffix¶
Suffix list of the derivative file containing the ground-truth of interest. | |
type | list * string |
{
"loader_parameters": {
"target_suffix": ["_seg-manual", "_lesion-manual"]
}
}
The length of this list controls the number of output channels of the model (i.e.
out_channel
). If the list has a length greater than 1, then a
multi-class model will be trained. If a list of list(s) is input for a
training, (e.g. [["_seg-manual-rater1"
, "_seg-manual-rater2"
],
["_lesion-manual-rater1"
, "_lesion-manual-rater2"
]), then each
sublist is associated with one class but contains the annotations from
different experts: at each training iteration, one of these annotations
will be randomly chosen.
extensions¶
Used to specify a list of file extensions to be selected for training/testing. | |
type | list, string |
{
"loader_parameters": {
"extensions": [".nii.gz", ".png"]
}
}
contrast_params¶
type | dict | |
options | ||
train_validation |
List of image contrasts (e.g. validation. If channels of the input tensors (i.e. its length equals model’s Otherwise, the contrasts are mixed and the model has only one input channel (i.e. model’s |
|
type | list, string | |
test |
List of image contrasts (e.g. Same comment as for |
|
type | list, string | |
balance |
Enables to weight the importance of specific channels (or contrasts) in the dataset: e.g. images will be included into the training/validation/test set. Please set
|
|
type | dict |
{
"loader_parameters": {
"contrast_params": {
"training_validation": ["T1w", "T2w", "T2star"],
"testing": ["T1w", "T2w", "T2star"],
"balance": {}
}
}
}
multichannel¶
Indicated if more than a contrast (e.g. T1w and T2w ) is used by the model. |
|
type | boolean |
See details in both train_validation
and test
for the contrasts that are input.
{
"loader_parameters": {
"multichannel": false
}
}
slice_axis¶
Sets the slice orientation for on which the model will be used. | |
type | string |
options | |
sagittal |
plane dividing body into left/right |
coronal |
plane dividing body into front/back |
axial |
plane dividing body into top/bottom |
{
"loader_parameters": {
"slice_axis": "sagittal"
}
}
slice_filter_params¶
Discard a slice from the dataset if it meets a condition, see below. | ||
type | dict | |
options | ||
filter_empty_input |
Discard slices where all voxel intensities are zeros. | |
type | boolean | |
filter_empty_mask |
Discard slices where all voxel labels are zeros. | |
type | boolean | |
filter_absent_class |
Discard slices where all voxel labels are zero for one or more classes (this is most relevant for multi-class models that need GT for all classes at train time). |
|
type | boolean | |
filter_classification |
Discard slices where all images fail a custom classifier filter. If used,
|
|
type | boolean |
{
"loader_parameters": {
"slice_filter_params": {
"filter_empty_mask": false,
"filter_empty_input": true
}
}
}
roi_params¶
Parameters for the region of interest | ||
type | dict | |
options | ||
suffix |
Suffix of the derivative file containing the ROI used to crop (e.g. |
|
type | string | |
slice_filter_roi |
If the ROI mask contains less than the slice will be discarded from the dataset. This feature helps with noisy labels, e.g., if a slice contains only 2-3 labeled voxels, we do not want to use these labels to crop the image. This parameter is only considered when using |
|
type | int |
{
"loader_parameters": {
"roi_params": {
"suffix": null,
"slice_filter_roi": null
}
}
}
soft_gt¶
Indicates if a soft mask will be used as ground-truth to train and / or evaluate a model. In particular, the masks are not binarized after interpolations implied by preprocessing or data-augmentation operations. |
|
type | boolean |
{
"loader_parameters": {
"soft_gt": true
}
}
Split Dataset¶
fname_split¶
File name of the log (joblib) that contains the list of training/validation/testing subjects. This file can later be used to re-train a model using the same data splitting scheme. If a new splitting scheme is performed. |
|
type | string |
{
"split_dataset": {
"fname_split": null
}
}
random_seed¶
Seed used by the random number generator to split the dataset between training/validation/testing. The use of the same seed ensures the same split between the sub-datasets, which is useful for reproducibility. |
|
type | int |
{
"split_dataset": {
"random_seed": 6
}
}
method¶
Seed used by the random number generator to split the dataset between training/validation/testing. The use of the same seed ensures the same split between the sub-datasets, which is useful for reproducibility. |
|
type | string |
options | |
per_patient |
all subjects are shuffled, then split between train/validation/test according to |
per_center |
all subjects are split so as not to mix institutions between the train/validation/test sets according to The latter option enables the user to ensure the model is working across domains (institutions). |
{
"split_dataset": {
"method": "per_center"
}
}
Note
The institution information is contained within the institution_id
column in the
participants.tsv
file.
balance¶
Metadata contained in will be evenly distributed in the training, validation and testing datasets. |
|
type | string |
required | false |
{
"split_dataset": {
"balance": null
}
}
train_fraction¶
Fraction of the dataset used as training set. | |
type | float |
range | [0, 1] |
{
"split_dataset": {
"train_fraction": 0.6
}
}
test_fraction¶
Fraction of the dataset used as testing set. This parameter is only used if the
|
|
type | float |
range | [0, 1] |
{
"split_dataset": {
"test_fraction": 0.2
}
}
center_test¶
Each string corresponds to an institution/center to only include in the testing dataset (not validation). This parameter is only used if the If used, the file
|
|
type | list, string |
{
"split_dataset": {
"center_test": []
}
}
Training Parameters¶
batch_size¶
type | int |
range | (0, inf) |
{
"training_parameters": {
"batch_size": 24
}
}
loss¶
Metadata for the loss function. Other parameters that could be needed in the Loss function definition: see attributes of the Loss function of interest (e.g. |
||
type | dict | |
options | ||
name |
Name of the loss function class. See ivadomed.losses |
|
type | string |
{
"training_parameters": {
"loss": {
"name": "DiceLoss"
}
}
}
training_time¶
Metadata for the loss function. Other parameters that could be needed in the Loss function definition: see attributes of the Loss function of interest (e.g. |
||
type | dict | |
options | ||
num_epochs |
type | int |
range | (0, inf) | |
early_stopping_epsilon |
If the validation loss difference during one epoch (i.e. is inferior to this epsilon for then training stops. |
|
type | float | |
early_stopping_patience |
Number of epochs after which the training is stopped if the validation loss improvement is smaller than |
|
type | int | |
range | (0, inf) |
{
"training_parameters": {
"training_time": {
"num_epochs": 100,
"early_stopping_patience": 50,
"early_stopping_epsilon": 0.001
}
}
}
scheduler¶
type | dict | ||
options | |||
initial_lr |
Initial learning rate. | ||
type | float | ||
scheduler_lr |
Other parameters depend on the scheduler of interest | ||
type | dict | ||
options | |||
name |
One of and |
||
type | string |
{
"training_parameters": {
"scheduler": {
"initial_lr": 0.001,
"scheduler_lr": {
"name": "CosineAnnealingLR",
"max_lr": 1e-2,
"base_lr": 1e-5
}
}
}
}
balance_samples¶
Balance labels in both the training and the validation datasets. | ||
type | dict | |
options | ||
applied |
Indicates whether to use a balanced sampler or not. | |
type | boolean | |
type |
Indicates which metadata to use to balance the sampler. Choices: (i.e. subject-based metadata) |
|
type | string |
{
"training_parameters": {
"balance_samples": {
"applied": false,
"type": "gt"
}
}
}
mixup_alpha¶
Alpha parameter of the Beta distribution, see original paper on the Mixup technique. | |
type | float |
{
"training_parameters": {
"mixup_alpha": null
}
}
transfer_learning¶
type | dict | |
options | ||
retrain_model |
Filename of the pretrained model ( no transfer learning is performed and the network is trained from scratch. |
|
type | string | |
retrain_fraction |
Controls the fraction of the pre-trained model that will be fine-tuned. For instance, if set to 0.5, the second half of the model will be fine-tuned while the first layers will be frozen. |
|
type | float | |
range | [0, 1] | |
reset |
If true, the weights of the layers that are not frozen are reset. If false, they are kept as loaded. | |
type | boolean |
{
"training_parameters": {
"transfer_learning": {
"retrain_model": null,
"retrain_fraction": 1.0,
"reset": true
}
}
}
Architecture¶
Architectures for both segmentation and classification are available and
described in the Architectures section. If the selected architecture is listed in the
loader file, a
classification (not segmentation) task is run. In the case of a
classification task, the ground truth will correspond to a single label
value extracted from target
, instead being an array (the latter
being used for the segmentation task).
default_model¶
Define the default model ( available Architectures. For custom architectures (see below), the default parameters are merged with the parameters that are specific to the tailored architecture. |
||
type | dict | |
required | true | |
options | ||
name |
Default: Unet |
|
type | string | |
dropout_rate |
type | float |
batch_norm_momentum |
type | float |
depth |
Number of down-sampling operations. | |
type | int | |
range | (0, inf) | |
relu |
Sets final activation to normalized ReLU (relu between 0 and 1), instead of sigmoid. Only available when is_2D=True. |
|
type | boolean | |
required | false | |
is_dim |
Indicates dimensionality of model (2D or 3D). If
|
|
type | boolean |
{
"default_model": {
"name": "Unet",
"dropout_rate": 0.4,
"batch_norm_momentum": 0.1
}
}
FiLMedUnet¶
type | dict | |
required | false | |
options | ||
applied |
Set to true to use this model. |
|
type | boolean | |
metadata |
Choice between name of a column from the participants.tsv file (i.e. subject-based metadata). |
|
type | string | |
options | ||
mri_params |
Vectors of (defined in the json of each image) are input to the FiLM generator. |
|
contrast |
Image contrasts (according to config/contrast_dct.json ) are input to the FiLM generator. |
{
"FiLMedUnet": {
"applied": false,
"metadata": "contrasts",
"film_layers": [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
}
}
HeMISUnet¶
type | dict | |
required | false | |
options | ||
applied |
Set to true to use this model. |
|
type | boolean | |
missing_probability |
Initial probability of missing image contrasts as model’s input (e.g. 0.25 results in a quarter of the image contrasts, i.e. channels, that will not be sent to the model for training). |
|
type | float | |
range | [0, 1] | |
missing_probability_growth |
Controls missing probability growth at each epoch: at each epoch, the
|
|
type | float |
{
"HeMISUnet": {
"applied": true,
"missing_probability": 0.00001,
"missing_probability_growth": 0.9,
"contrasts": ["T1w", "T2w"],
"ram": true,
"hdf5_path": "/path/to/HeMIS.hdf5",
"csv_path": "/path/to/HeMIS.csv",
"target_lst": ["T2w"],
"roi_lst": null
}
}
Modified3DUNet¶
type | dict | |
required | false | |
options | ||
length_3D |
Size of the 3D patches used as model’s input tensors. | |
type | (int, int, int) | |
stride_3D |
Voxels’ shift over the input matrix to create patches. Ex: Stride of [1, 2, 3] will cause a patch translation of 1 voxel in the 1st dimension, 2 voxels in the 2nd dimension and 3 voxels in the 3rd dimension at every iteration until the whole input matrix is covered. |
|
type | [int, int, int] | |
attention_unet |
Use attention gates in the Unet’s decoder. | |
type | boolean | |
required | false | |
n_filters |
Number of filters in the first convolution of the UNet. This number of filters will be doubled at each convolution. |
|
type | int | |
required | false |
{
"Modified3DUNet": {
"applied": false,
"length_3D": [128, 128, 16],
"stride_3D": [128, 128, 16],
"attention": false,
"n_filters": 8
}
}
Cascaded Architecture Features¶
object_detection_params¶
type | dict | |
required | false | |
options | ||
object_detection_path |
Path to object detection model and the configuration file. The folder, configuration file, and model need to have the same name (e.g.
will be used to generate bounding boxes. |
|
type | string | |
safety_factor |
List of length 3 containing the factors to multiply each dimension of the bounding box. Ex: If the original bounding box has a size of 10x20x30 with a safety factor of [1.5, 1.5, 1.5], the final dimensions of the bounding box will be 15x30x45 with an unchanged center. |
|
type | [int, int, int] |
{
"object_detection_params": {
"object_detection_path": null,
"safety_factor": [1.0, 1.0, 1.0]
}
}
Transformations¶
Transformations applied during data augmentation. Transformations are
sorted in the order they are applied to the image samples. For each
transformation, the following parameters are customizable: -
applied_to
: list betweem "im", "gt", "roi"
. If not specified,
then the transformation is applied to all loaded samples. Otherwise,
only applied to the specified types: eg ["gt"]
implies that this
transformation is only applied to the ground-truth data. -
dataset_type
: list between "training", "validation", "testing"
.
If not specified, then the transformation is applied to the three
sub-datasets. Otherwise, only applied to the specified subdatasets: eg
["testing"]
implies that this transformation is only applied to the
testing sub-dataset.
Available Transformations:¶
NumpyToTensor¶
Converts nd array to tensor object. | |
type | dict |
{
"transformation": {
"NumpyToTensor": {
"applied_to": ["im", "gt"]
}
}
}
CenterCrop¶
type | dict | |
options | ||
size |
type | list, int |
applied_to |
type | list, string |
{
"transformation": {
"CenterCrop": {
"applied_to": ["im", "gt"],
"size": [512, 256, 16]
}
}
}
ROICrop¶
type | dict | |
options | ||
size |
type | list, int |
applied_to |
type | list, string |
{
"transformation": {
"ROICrop": {
"size": [48, 48]
}
}
}
NormalizeInstance¶
Normalize a tensor or an array image with mean and standard deviation estimated from the sample itself. |
|
type | dict |
{
"transformation": {
"NormalizeInstance": {}
}
}
RandomAffine¶
type | dict | |
options | ||
degrees |
Positive float or list (or tuple) of length two. Angles in degrees. If only a float is provided, then rotation angle is selected within the range [-degrees, degrees]. Otherwise, the tuple defines this range. |
|
type | float or tuple of float | |
range | (0, inf) | |
translate |
Length 2 or 3 depending on the sample shape (2D or 3D). Defines the maximum range of translation along each axis. |
|
type | list, float | |
range | [0, 1] | |
scale |
Length 2 or 3 depending on the sample shape (2D or 3D). Defines the maximum range of scaling along each axis. |
|
type | list, float | |
range | [0, 1] |
{
"transformation": {
"RandomAffine": {
"translate": [0.03, 0.03],
"applied_to": ["im"],
"dataset_type": ["training"],
"scale": [0.1, 0.5],
"degrees": 180
}
}
}
RandomShiftIntensity¶
type | dict | |
options | ||
shift_range |
Range from which the offset applied is randomly selected. | |
type | [float, float] |
{
"transformation": {
"RandomShiftIntensity": {
"shift_range": [28.0, 30.0]
}
}
}
ElasticTransform¶
Applies elastic transformation. See also: Best practices for convolutional neural networks applied to visual document analysis. |
||
type | dict | |
options | ||
alpha_range |
Deformation coefficient. | |
type | (float, float) | |
sigma_range |
Standard deviation. | |
type | (float, float) | |
p |
type | float |
{
"transformation": {
"ElasticTransform": {
"alpha_range": [28.0, 30.0],
"sigma_range": [3.5, 4.5],
"p": 0.1,
"applied_to": ["im", "gt"],
"dataset_type": ["training"]
}
}
}
Resample¶
type | dict | |
options | ||
wspace |
Resolution along the first axis, in mm. | |
type | float | |
range | [0, 1] | |
hspace |
Resolution along the second axis, in mm. | |
type | float | |
range | [0, 1] | |
dspace |
Resolution along the third axis, in mm. | |
type | float | |
range | [0, 1] |
{
"transformation": {
"Resample": {
"wspace": 0.75,
"hspace": 0.75,
"dspace": 1
}
}
}
AdditiveGaussianNoise¶
type | dict | |
options | ||
mean |
Mean of Gaussian noise. | |
type | float | |
std |
Standard deviation of Gaussian noise. | |
type | float |
{
"transformation": {
"AdditiveGaussianNoise": {
"mean": 0.0,
"std": 0.02
}
}
}
DilateGT¶
type | dict | |
options | ||
dilation_factor |
Controls the number of iterations of ground-truth dilation depending on the size of each individual lesion, data augmentation of the training set. Use |
|
type | float |
{
"transformation": {
"DilateGT": {
"dilation_factor": 0
}
}
}
HistogramClipping¶
Perform intensity clipping based on percentiles. | ||
type | dict | |
options | ||
min_percentile |
type | float |
range | [0, 100] | |
max_percentile |
type | float |
range | [0, 100] |
{
"transformation": {
"HistogramClipping": {
"min_percentile": 50,
"max_percentile": 75
}
}
}
Clahe¶
type | dict | |
options | ||
clip_limit |
type | float |
kernel_size |
Defines the shape of contextual regions used in the algorithm. List length = dimension, i.e. 2D or 3D |
|
type | list, int |
{
"transformation": {
"Clahe": {
"clip_limit": 0.5,
"kernel_size": [8, 8]
}
}
}
RandomReverse¶
Make a randomized symmetric inversion of the different values of each dimensions. | |
type | dict |
{
"transformation": {
"RandomReverse": {
"applied_to": ["im"]
}
}
}
Uncertainty¶
Uncertainty computation is performed if n_it>0
and at least
epistemic
or aleatoric
is true
. Note: both epistemic
and
aleatoric
can be true
.
epistemic¶
Model-based uncertainty with Monte Carlo Dropout. | |
type | boolean |
{
"uncertainty": {
"epistemic": true
}
}
aleatoric¶
Image-based uncertainty with test-time augmentation. | |
type | boolean |
{
"uncertainty": {
"aleatoric": true
}
}
n_it¶
Number of Monte Carlo iterations. Set to 0 for no uncertainty computation. | |
type | int |
{
"uncertainty": {
"n_it": 2
}
}
Postprocessing¶
binarize_prediction¶
Binarizes predictions according to the given threshold threshold become 0, and predictions above or equal to threshold become 1. |
||
type | dict | |
options | ||
thr |
Threshold. To use soft predictions (i.e. no binarisation, float between 0 and 1) for metric computation, indicate -1. |
|
type | float | |
range | [0, 1] |
{
"postprocessing": {
"binarize_prediction": {
"thr": 0.1
}
}
}
binarize_maxpooling¶
Binarize by setting to 1 the voxel having the maximum prediction across all classes. Useful for multiclass models. No parameters required (i.e., {}). |
|
type | dict |
{
"postprocessing": {
"binarize_maxpooling": {}
}
}
fill_holes¶
Fill holes in the predictions. No parameters required (i.e., {}). | |
type | dict |
{
"postprocessing": {
"fill_holes": {}
}
}
keep_largest¶
Keeps only the largest connected object in prediction. Only nearest neighbors are connected to the center, diagonally-connected elements are not considered neighbors. No parameters required (i.e., {}) |
|
type | dict |
{
"postprocessing": {
"keep_largest": {}
}
}
remove_noise¶
Sets to zero prediction values strictly below the given threshold thr . |
||
type | dict | |
options | ||
thr |
Threshold. Threshold set to -1 will not apply this postprocessing step. |
|
type | float | |
range | [0, 1] |
{
"postprocessing": {
"remove_noise": {
"thr": 0.1
}
}
}
remove_small¶
Remove small objects from the prediction. An object is defined as a group of connected voxels. Only nearest neighbors are connected to the center, diagonally-connected elements are not considered neighbors. |
||
type | dict | |
options | ||
thr |
Minimal object size. If a list of thresholds is chosen, the length should match the number of predicted classes. |
|
type | int or list | |
unit |
Either vox for voxels or mm3. Indicates the unit used to define the minimal object size. |
|
type | string |
{
"postprocessing": {
"remove_small": {
"unit": "vox",
"thr": 3
}
}
}
threshold_uncertainty¶
Removes the most uncertain predictions (set to 0) according to a threshold using the uncertainty file with the suffix uncertainty needs to be evaluated on the predictions with the uncertainty parameter. |
||
type | dict | |
options | ||
thr |
Threshold. Threshold set to -1 will not apply this postprocessing step. |
|
type | float | |
range | [0, 1] | |
suffix |
Indicates the suffix of an uncertainty file. Choices: voxel-wise uncertainty, derived from mean value of
variation, derived from the Intersection-over-Union of the predictions, or to threshold on the average of Monte Carlo iterations. |
|
type | string |
{
"postprocessing": {
"threshold_uncertainty": {
"thr": -1,
"suffix": "_unc-vox.nii.gz"
}
}
}
Evaluation Parameters¶
Dict. Parameters to get object detection metrics (true positive and false detection rates), and this, for defined object sizes.
target_size¶
type | dict | |
options | ||
thr |
These values will create several consecutive target size bins. For instance with a list of two values, we will have three target size bins: minimal size to first list element, first list element to second list element, and second list element to infinity. |
|
type | list, int | |
unit |
Either vox for voxels or mm3. Indicates the unit used to define the target object sizes. |
|
type | string |
{
"evaluation_parameters": {
"target_size": {
"thr": [20, 100],
"unit": "vox"
}
}
}
overlap¶
type | dict | |
options | ||
thr |
Minimal object size overlapping to be considered a TP, FP, or FN. | |
type | int | |
unit |
Either vox for voxels or mm3. Indicates the unit used to define the overlap. |
|
type | string |
{
"evaluation_parameters": {
"overlap": {
"thr": 30,
"unit": "vox"
}
}
}