ai4med.components.aux_ops package

class ComputeAccuracy(tag: str, use_sigmoid=False, do_summary=True, do_print=True)

Bases: ai4med.components.aux_ops.aux_op.AuxiliaryOperation

This aux-op computes accuracy by comparing similarity between model predictions and label data.

Parameters
  • tag (str) – the key name of the output tensor

  • use_sigmoid (bool) – whether to apply sigmoid to predictions (Default: False)

  • do_summary (bool) – whether to aggregate result across training steps for tensorboard reporting (Default: True)

  • do_print (bool) – whether to aggregate result across training steps for console printing (Default: True)

get_output_tensors(predictions, label, build_ctx: ai4med.common.build_ctx.BuildContext)

Implements the required method.

Parameters
  • predictions – predictions produced by model

  • label – label of the training subject

  • build_ctx – build context

Returns: dict of output tensors

class AuxiliaryOperation(do_summary=True, do_print=True)

Bases: ai4med.common.graph_component.GraphComponent

This class defines the interface for auxiliary operations (aux-ops).

An aux-op is a graph building component that adds additional operations to the computation graph. Output from an aux-op can be aggregated for tensorboard recording or printed to the console after each step of training.

Aux-ops are built after all other training graph components (i.e. placeholders, model, loss).

Note

Output values are aggregated, if so desired, by MetricAccumulator. MetricAccumulator can only process simple output types (scalar and size-1 arrays).

Parameters
  • do_summary (bool) – whether output should be summarized for tensorboard recording (Default: True)

  • do_print (bool) – whether output should be aggregated for printing to the console (Default: True)

build(build_ctx: ai4med.common.build_ctx.BuildContext)

Implements the required build method of GraphComponent.

Note

Aux-op components should never override this method. They should, instead, implement the required get_output_tensors method.

Parameters

build_ctx – the build context

Returns: dict of output tensors

get_output_tensors(predictions, label, build_ctx: ai4med.common.build_ctx.BuildContext)

This is the required method of the aux-op. It should add additional elements to the computation graph based on model predictions, label data, and/or any objects in the build context. It can also add more objects into the build context for other aux-ops to use.

Parameters
  • predictions – the predictions computed by model architecture

  • label – label data

  • build_ctx – the build context

Returns: a dict of tensors

class ComputeBinaryPreds(binary_preds_name='binary_preds', binary_labels_name='binary_labels')

Bases: ai4med.components.aux_ops.aux_op.AuxiliaryOperation

This aux-op processes binary predictions produced by a classification model.

Parameters
  • binary_preds_name (str) – name of the prediction processing result

  • binary_labels_name (str) – name of the label processing result

Returns: a ComputeBinaryPreds object

get_output_tensors(predictions, label, build_ctx: ai4med.common.build_ctx.BuildContext)

Implements the required method.

Parameters
  • predictions – predictions produced by model

  • label – label of the training subject

  • build_ctx – build context

Returns: dict of output tensors

class ComputeMulticlassAccuracy(tag, use_sigmoid_for_binary=True, use_softmax_for_multiclass=True, use_sigmoid_for_accuracy=False, do_summary=True, do_print=True)

Bases: ai4med.components.aux_ops.aux_op.AuxiliaryOperation

This aux-op computes accuracy for multi-class predictions produced by a classification model.

Parameters
  • tag (str) – the key name of the output tensor

  • use_sigmoid_for_binary (bool) – whether to apply sigmoid for binary labels (Default: True)

  • use_softmax_for_multiclass (bool) – whether to apply softmax to multi-class labels (Default: True)

  • use_sigmoid_for_accuracy (bool) – whether to apply sigmoid to accuracy (Default: False)

  • do_summary (bool) – whether to aggregate result across training steps for tensorboard reporting (Default: True)

  • do_print (bool) – whether to aggregate result across training steps for console printing (Default: True)

Returns: a ComputeMulticlassPreds object

get_output_tensors(predictions, labels, build_ctx=None)

This is the required method of the aux-op. It should add additional elements to the computation graph based on model predictions, label data, and/or any objects in the build context. It can also add more objects into the build context for other aux-ops to use.

Parameters
  • predictions – the predictions computed by model architecture

  • label – label data

  • build_ctx – the build context

Returns: a dict of tensors

class ComputeMulticlassPreds(preds_name='preds', labels_name='labels', use_sigmoid_for_binary=True, use_softmax_for_multiclass=True)

Bases: ai4med.components.aux_ops.aux_op.AuxiliaryOperation

This aux-op processes multi-class predictions produced by a classification model. The predictions could contain both binary and multi-class labels.

Parameters
  • preds_name (str) – name of the prediction processing result

  • labels_name (str) – name of the label processing result

  • use_sigmoid_for_binary (bool) – whether to apply sigmoid for binary labels (Default: True)

  • use_softmax_for_multiclass (bool) – whether to apply softmax to multi-class labels (Default: True)

Returns: a ComputeMulticlassPreds object

get_output_tensors(predictions, labels, build_ctx=None)

Implements the required method.

Parameters
  • predictions – predictions produced by model

  • labels – labels of the training subject

  • build_ctx – build context

Returns: dict of output tensors

class ComputeDice(tag: str, mask_tag: str = None, data_format='channels_first', skip_background=False, is_onehot_targets=False, is_independent_predictions=False, jaccard=False, threshold=0.5, do_summary=True, do_print=True)

Bases: ai4med.components.aux_ops.aux_op.AuxiliaryOperation

This aux-op computes dice metric from predictions and label.

Parameters
  • tag (str) – key name of the dice tensor

  • mask_tag (str) – key name of the mask tensor. Optional.

  • data_format (str) – the input format (‘channels_last’ or ‘channels_first’)

  • skip_background (bool) – skip dice computation on the first channel of the predicted output (basically skipping dice on background class) or not (Default: False)

  • is_onehot_targets (bool) – targets in One-Hot format or not (Default: False)

  • is_independent_predictions (bool) – prediction results are independent or not (Default: False)

  • jaccard (bool) – compute Jaccard Indect (a.k.a. IoU) instead of dice or not (Default: False)

  • threshold (float) – threshold to convert independent_predictions probabilities into binary

  • do_summary (bool) – whether to aggregate result across training steps for tensorboard reporting (Default: True)

  • do_print (bool) – whether to aggregate result across training steps for console printing (Default: True)

get_output_tensors(predictions, label, build_ctx: ai4med.common.build_ctx.BuildContext)

Implements the required method.

Parameters
  • predictions – predictions produced by model

  • label – label of the training subject

  • build_ctx – build context

Returns: dict of output tensors

class DiceMaskedOutput(tags, data_format='channels_first', skip_background=False, is_onehot_targets=False, is_independent_predictions=False, jaccard=False, threshold=0.5, do_summary=True, do_print=True)

Bases: ai4med.components.aux_ops.aux_op.AuxiliaryOperation

This aux-op outputs a dict of dice values. The first element in the output dict is the average value across all classes, and if there is more than one class, the remaining elements are per-class values. If there are no ground labels for the class in question, returns nan.

Parameters
  • tags – key names of generated outputs for each class

  • data_format (str) – the input format (‘channels_last’ or ‘channels_first’)

  • skip_background (bool) – remove background class or not (Default: False)

  • is_onehot_targets (bool) – targets in One-Hot format or not (Default: False)

  • is_independent_predictions (bool) – prediction results are independent or not (Default: False)

  • jaccard (bool) – compute Jaccard Indect (a.k.a. IoU) instead of dice or not (Default: False)

  • threshold (float) – threshold to convert independent_predictions probabilities into binary

  • do_summary (bool) – whether to aggregate result across training steps for tensorboard reporting (Default: True)

  • do_print (bool) – whether to aggregate result across training steps for console printing (Default: True)

get_output_tensors(predictions, label, build_ctx: ai4med.common.build_ctx.BuildContext)

Implements the required method.

Parameters
  • predictions – predictions produced by model

  • label – label of the training subject

  • build_ctx – build context

Returns: dict of output tensors

class NegLoss(tag: str, do_summary=True, do_print=True)

Bases: ai4med.components.aux_ops.aux_op.AuxiliaryOperation

get_output_tensors(predictions, label, build_ctx: ai4med.common.build_ctx.BuildContext)

This is the required method of the aux-op. It should add additional elements to the computation graph based on model predictions, label data, and/or any objects in the build context. It can also add more objects into the build context for other aux-ops to use.

Parameters
  • predictions – the predictions computed by model architecture

  • label – label data

  • build_ctx – the build context

Returns: a dict of tensors

class ReduceMeanMasked(tag: str, mask_tag: str = None, axis=None, do_summary=True, do_print=True)

Bases: ai4med.components.aux_ops.aux_op.AuxiliaryOperation

This aux-op computes reduced mean and mask from model predictions and label data.

Parameters
  • tag (str) – the key name of the reduced mean tensor

  • mask_tag (str) – the key name of the mask tensor. Optional.

  • axis (int) – axis to apply the reduce_sum operation

  • do_summary (bool) – whether to aggregate result across training steps for tensorboard reporting (Default: True)

  • do_print (bool) – whether to aggregate result across training steps for console printing (Default: True)

get_output_tensors(predictions, label, build_ctx: ai4med.common.build_ctx.BuildContext)

Implements the required method.

Parameters
  • predictions – predictions produced by model

  • label – label of the training subject

  • build_ctx – build context

Returns: dict of 2 output tensors

© Copyright 2020, NVIDIA. Last updated on Feb 2, 2023.