junn.common package¶
Subpackages¶
Submodules¶
junn.common.callbacks module¶
junn.common.distributed module¶
Helper functions for distributed training.
- junn.common.distributed.barrier(name)¶
Create a barrier which will synchronize all processes.
Can be used if the worker processes need to wait for the main process.
- Parameters
name –
- Returns
- junn.common.distributed.get_callbacks()¶
Get Keras callbacks.
If Horovod is present, this will be the BroadCastGlobalVariables callback.
- Returns
- junn.common.distributed.init(device_pinning=True)¶
Initialize Horovod if present.
- Parameters
device_pinning – Whether GPUs should be pinned.
- Returns
- junn.common.distributed.is_rank_zero()¶
Return whether the current process is rank zero, i.e. the main process.
- Returns
- junn.common.distributed.is_running_distributed()¶
Return True if JUNN is running distributed and Horovod is initialized.
- Returns
- junn.common.distributed.local_rank()¶
Return the local rank (on the physical machine).
- Returns
- junn.common.distributed.pin_devices()¶
Pin each GPU to a worker.
- Returns
- junn.common.distributed.rank()¶
Return the global rank.
This is the rank within all running instances on possibly multiple machines.
- Returns
- junn.common.distributed.size()¶
Return the count of running instances.
- Returns
- junn.common.distributed.wrap_optimizer(optimizer)¶
Wrap the Keras optimizer.
If Horovod is present, with DistributedOptimizer.
- Parameters
optimizer –
- Returns
junn.common.losses module¶
Additional losses suitable for segmentation tasks.
- junn.common.losses.accuracy(y_true, y_pred)¶
Calculate the accuracy.
- Parameters
y_true – ground truth
y_pred – prediction
- Returns
accuracy
- junn.common.losses.dice_index(y_true, y_pred)¶
Calculate the Dice index.
- Parameters
y_true – ground truth
y_pred – prediction
- Returns
the Dice index
- junn.common.losses.dice_index_direct(y_true, y_pred)¶
Directly calculate the Dice index.
- Parameters
y_true – ground truth
y_pred – prediction
- Returns
Dice index
- junn.common.losses.dice_index_weighted(y_true, y_pred, y_weight)¶
Calculate the Dice index with weighting applied.
- Parameters
y_true – ground truth
y_pred – prediction
y_weight – weights
- Returns
weighted Dice index
- junn.common.losses.dice_loss(y_true, y_pred)¶
Calculate the Dice loss, i.e. the negative Dice index.
- Parameters
y_true – ground truth
y_pred – prediction
- Returns
Dice loss
- junn.common.losses.dice_loss_unclipped(y_true, y_pred)¶
Calculate the Dice loss, i.e. the negative Dice index without clipping.
- Parameters
y_true – ground truth
y_pred – prediction
- Returns
Dice loss
- junn.common.losses.dice_loss_weighted(y_true, y_pred, y_weight)¶
Calculate the weighted Dice loss, i.e. negative Dice index.
- Parameters
y_true – ground truth
y_pred – prediction
y_weight – weights
- Returns
weighted Dice loss
- junn.common.losses.epsilon()¶
Epsilon of the current compute hardware.
- Returns
epsilon as a floating point type
- junn.common.losses.f_score(y_true, y_pred)¶
Calculate the F score.
- Parameters
y_true – ground truth
y_pred – prediction
- Returns
F-score
- junn.common.losses.false_negative(y_true, y_pred)¶
- junn.common.losses.false_positive(y_true, y_pred)¶
- junn.common.losses.flatten_and_clip(values)¶
Flatten and clip a tensor.
- Parameters
values – values
- Returns
flattened and clipped to 0-1 values
- junn.common.losses.generate_tversky_loss(alpha=0.5, beta=0.5)¶
Generate a Tversky loss function.
- Parameters
alpha – alpha
beta – beta
- Returns
a Tversky loss function with fixed parameters
- junn.common.losses.jaccard_index(y_true, y_pred)¶
Calculate the Jaccard index.
- Parameters
y_true – ground truth
y_pred – prediction
- Returns
the Jaccard index
- junn.common.losses.mixin_flatten_and_clip(what)¶
Mixin to assure a function gets a flattened and clipped tensor.
- Parameters
what – function to be modified
- Returns
modified function
- junn.common.losses.nan_loss(y_true, y_pred)¶
Return always NaN for debugging and testing purposes.
- Parameters
y_true – ground truth
y_pred – prediction
- Returns
all NaN
- junn.common.losses.precision(y_true, y_pred)¶
Calculate the precision.
- Parameters
y_true – ground truth
y_pred – prediction
- Returns
precision
- junn.common.losses.recall(y_true, y_pred)¶
Calculate the recall.
- Parameters
y_true – ground truth
y_pred – prediction
- Returns
recall
- junn.common.losses.tp_tn_fp_fn_precision_recall(y_true, y_pred)¶
Calculate a set of simple metrics in one go.
True positives, true negatives, false positives, false negatives, precision as well as recall.
- Parameters
y_true – ground truth
y_pred – prediction
- Returns
tuple of metrics (tp, tn, fp, fn, precision, recall)
- junn.common.losses.true_negative(y_true, y_pred)¶
- junn.common.losses.true_positive(y_true, y_pred)¶
- junn.common.losses.tversky_index(y_true, y_pred, alpha=0.5, beta=0.5)¶
Calculate the Tversky index.
- Parameters
y_true – ground truth
y_pred – prediction
alpha – alpha
beta – beta
- Returns
the Tversky index
- junn.common.losses.weighted_loss(y_true, y_pred, y_weight)¶
Weighted loss function.
- Parameters
y_true – ground truth
y_pred – prediction
y_weight – weights
- Returns
weighted loss