BioExp.helpers package

Submodules

BioExp.helpers.get_gram_matrix module

BioExp.helpers.losses module

BioExp.helpers.losses.dice(y_true, y_pred)[source]
BioExp.helpers.losses.dice_coef(y_true, y_pred)[source]
BioExp.helpers.losses.dice_coef_loss(y_true, y_pred)[source]
BioExp.helpers.losses.dice_core_coef(y_true, y_pred)[source]
BioExp.helpers.losses.dice_core_metric(y_true, y_pred)[source]
BioExp.helpers.losses.dice_en_coef(y_true, y_pred)[source]
BioExp.helpers.losses.dice_en_metric(y_true, y_pred)[source]
BioExp.helpers.losses.dice_label_coef(y_true, y_pred, labels, n_classes=4)[source]
BioExp.helpers.losses.dice_loss(y_true, y_pred)[source]
BioExp.helpers.losses.dice_updated(y_true, y_pred)[source]
BioExp.helpers.losses.dice_whole_coef(y_true, y_pred)[source]
BioExp.helpers.losses.dice_whole_metric(y_true, y_pred)[source]
BioExp.helpers.losses.gen_dice_loss(y_true, y_pred)[source]

computes the sum of two losses : generalised dice loss and weighted cross entropy

BioExp.helpers.losses.soft_dice_loss(y_true, y_pred)[source]

Soft dice loss calculation for arbitrary batch size, number of classes, and number of spatial dimensions. Assumes the channels_last format.

# Arguments
y_true: b x X x Y( x Z…) x c One hot encoding of ground truth y_pred: b x X x Y( x Z…) x c Network output, must sum to 1 over c channel (such as after softmax) epsilon: Used for numerical stability to avoid divide by zero errors
# References

V-Net: Fully Convolutional Neural Networks for Volumetric Medical Image Segmentation https://arxiv.org/abs/1606.04797 More details on Dice loss formulation https://mediatum.ub.tum.de/doc/1395260/1395260.pdf (page 72)

Adapted from https://github.com/Lasagne/Recipes/issues/99#issuecomment-347775022

BioExp.helpers.losses.weighted_log_loss(y_true, y_pred)[source]

BioExp.helpers.metrics module

BioExp.helpers.metrics.dice(y_true, y_pred)[source]
BioExp.helpers.metrics.dice_(y_true, y_pred)[source]
BioExp.helpers.metrics.dice_core_metric(y_true, y_pred)[source]
BioExp.helpers.metrics.dice_en_metric(y_true, y_pred)[source]
BioExp.helpers.metrics.dice_label_metric(y_true, y_pred, label)[source]
BioExp.helpers.metrics.dice_updated(y_true, y_pred)[source]
BioExp.helpers.metrics.dice_whole_metric(y_true, y_pred)[source]
BioExp.helpers.metrics.metric(y_true, y_pred)[source]

BioExp.helpers.models module

BioExp.helpers.models.CONV2D(inputs, n_filters, filter_size, strides, padding, name)[source]
BioExp.helpers.models.UNET(input_shape)[source]
BioExp.helpers.models.categorical_focal_loss(y_true, y_pred)[source]
Parameters:
  • y_true – A tensor of the same shape as y_pred
  • y_pred – A tensor resulting from a softmax
Returns:

Output tensor.

BioExp.helpers.models.conv_block(prev, num_filters, kernel=(3, 3), strides=(1, 1), act='relu', prefix=None)[source]
BioExp.helpers.models.dense_block(x, blocks, name)[source]

A dense block. # Arguments

x: input tensor. blocks: integer, the number of building blocks. name: string, block label.
# Returns
output tensor for the block.
BioExp.helpers.models.dense_conv_block(x, growth_rate, name)[source]

A building block for a dense block. # Arguments

x: input tensor. growth_rate: float, growth rate at dense layers. name: string, block label.
# Returns
Output tensor for the block.
BioExp.helpers.models.dice_coef(y_true, y_pred)[source]
BioExp.helpers.models.dice_coef_loss(y_true, y_pred)[source]
BioExp.helpers.models.dice_coef_rounded_ch0(y_true, y_pred)[source]
BioExp.helpers.models.dice_coef_rounded_ch1(y_true, y_pred)[source]
BioExp.helpers.models.dice_coef_rounded_ch2(y_true, y_pred)[source]
BioExp.helpers.models.dice_coef_rounded_ch3(y_true, y_pred)[source]
BioExp.helpers.models.schedule_steps(epoch, steps)[source]
BioExp.helpers.models.softmax_dice_focal_loss(y_true, y_pred)[source]
BioExp.helpers.models.softmax_dice_loss(y_true, y_pred)[source]
BioExp.helpers.models.transition_block(x, reduction, name)[source]

A transition block. # Arguments

x: input tensor. reduction: float, compression rate at transition layers. name: string, block label.
# Returns
output tensor for the block.
BioExp.helpers.models.unet_densenet121(input_shape, weights='imagenet')[source]
BioExp.helpers.models.unet_densenet121_imagenet(input_shape, weights='imagenet')[source]

BioExp.helpers.pb_file_generation module

BioExp.helpers.pb_file_generation.generate_pb(model_path, layer_name, pb_path, wts_path)[source]

freezes model weights and convert entire graph into .pb file

model_path: saved model path (model architecture) (str) layer_name: name of output layer (str) pb_path : path to save pb file wts_path : saved model weights

BioExp.helpers.radfeatures module

BioExp.helpers.transform module

BioExp.helpers.utils module

BioExp.helpers.utils.apply_modifications_custom(model, custom_objects=None)[source]

Applies modifications to the model layers to create a new Graph. For example, simply changing model.layers[idx].activation = new activation does not change the graph. The entire graph needs to be updated with modified inbound and outbound tensors because of change in layer building function. :param model: The keras.models.Model instance.

Returns:The modified model with changes applied. Does not mutate the original model.
BioExp.helpers.utils.load_file(rgbpath, maskpath=None)[source]

loads rgb image

rgbpath: rgb image path maskpath: segmentation path if exists

BioExp.helpers.utils.load_images(img_path, normalize=True, zscore=False, mask=True)[source]
BioExp.helpers.utils.load_numpy_slice(img_path, mask_path=None, seq='all', pad=0)[source]
BioExp.helpers.utils.load_vol(t1path, t2path, t1cepath, flairpath, segpath=None, slicen=-1, pad=None)[source]

loads volume if exists

rootpath : patient data root path slicen : sice which needs to ne loaded pad : number of pixels to be padded

in X, Y direction
BioExp.helpers.utils.load_vol_brats(rootpath, slicen=-1, pad=None)[source]

loads volume if exists

rootpath : patient data root path slicen : sice which needs to ne loaded pad : number of pixels to be padded

in X, Y direction
BioExp.helpers.utils.normalize_scheme(slicennot)[source]

-normalizes each slice, excluding gt -subtracts mean and div by std dev for each slice -clips top and bottom one percent of pixel intensities

BioExp.helpers.utils.one_hot(tensor, n_classes)[source]
BioExp.helpers.utils.predict_volume_brats(model, test_image, show=False)[source]

Predictions for brats dataset involves renaming of classes

model: keras model test_image: image (H x W x C) show: bool, to display prediction

Module contents