Channel manipulation

For processing multiple 3D volumes, the volumes can be stacked to the color dimension. This need to be implemented as callback before the batch is presented to the model.

class StackVolumes[source]

StackVolumes(after_create=None, before_fit=None, before_epoch=None, before_train=None, before_batch=None, after_pred=None, after_loss=None, before_backward=None, before_step=None, after_cancel_step=None, after_step=None, after_cancel_batch=None, after_batch=None, after_cancel_train=None, after_train=None, before_validate=None, after_cancel_validate=None, after_validate=None, after_cancel_epoch=None, after_epoch=None, after_cancel_fit=None, after_fit=None) :: Callback

Takes multiple 3D volumes and stacks them in the channel dim.
This is useful when using multi-sequence medical data.

Example:
    Having the Tensors of size (10, 1, 5, 25, 25) would lead to a single Tensor of
    size (10, 3, 5, 25, 25).

Callbacks for volume manipulation

In medical imaging, small regions in the image are often decisive for the diagnosis. This means, given a smaller subregion of the image, the model could still correctly detect the pathology. Through splitting the volumes the data might thus be augmented.

class SplitVolumes[source]

SplitVolumes(n_subvol=8, split_along_depth=True) :: Callback

Separates a 3D tensor into smaller equal-sized sub-volumes.

 o---o---o       o---o---o
 | A | A |       | B | B |        o---o  o---o  o---o  o---o  o---o  o---o  o---o  o---o
 o---o---o   +   o---o---o  ==>   | A | +| A | +| B | +| B | +| A | +| A | +| B | +| B |
 | A | A |       | B | B |        o---o  o---o  o---o  o---o  o---o  o---o  o---o  o---o
 o---o---o       o---o---o


Args:
    n_subvol = number of subvolumes
    split_along_depth = whether volumes should also be split along the D dimension fpr a [B, C, D, H, W] tensor

Subsampling the subvolumes allows for more variability in the image and also training with a batch size < 1.

class SubsampleShuffle[source]

SubsampleShuffle(p=0.5, n_subvol=8, split_along_depth=True) :: SplitVolumes

After splitting the volume into multiple subvolumes, draws a randon amount of subvolumes for training.
Would allow to train on an effective batch size < 1.

o---o---o        o---o---o
| A | A |        | B | B |        o---o  o---o  o---o  o---o  o---o  o---o
o---o---o    +   o---o---o  ==>   | B | +| A | +| A | +| A | +| B | +| A |
| A | A |        | B | B |        o---o  o---o  o---o  o---o  o---o  o---o
o---o---o        o---o---o

Args:
    p: percentage of subvolumes to train on

Assuming, a small finding is predominantly located in the, e.g. upper left image region, the model might wrongly learn the location as an important factor for the finding. Mixing subvolumes might help.

class MixSubvol[source]

MixSubvol(p=0.25, n_subvol=8, split_along_depth=True) :: SplitVolumes

After splitting the volume into multiple subvolumes, shuffels the subvolumes and sticks the images back together.

o---o---o        o---o---o        o---o---o        o---o---o
| A | A |        | B | B |        | B | B |        | A | B |
o---o---o    +   o---o---o  ==>   o---o---o    +   o---o---o
| A | A |        | B | B |        | A | A |        | B | A |
o---o---o        o---o---o        o---o---o        o---o---o


Args:
    p: probability that the callback will be applied
    n_subvol: number of subvolumina to create
    split_along_depth: whether the depth dimension should be included

Implementation for MixUp on 3D data

Tracker callbacks

class ReloadBestFit[source]

ReloadBestFit(fname, monitor='valid_loss', comp=None, min_delta=0.0, patience=1) :: TrackerCallback

A `TrackerCallback` that reloads the previous best model if not improvement happend for n epochs