armed package#

Subpackages#

Submodules#

armed.metrics module#

Custom model metrics.

armed.metrics.balanced_accuracy(y_true, y_pred)#

Balanced accuracy metric for multi-class labels. Computes the mean of the accuracy of each class.

Parameters:
  • y_true (tf.Tensor) – true labels

  • y_pred (tf.Tensor) – probabilistic predictions. Will be thresholded at 0.5.

Returns:

balanced accuracy

Return type:

tf.Tensor

armed.metrics.classification_metrics(y_true: numpy.ndarray, y_pred: numpy.ndarray, youden_point: float | None = None, fixed_sens: float = 0.8, fixed_spec: float = 0.8)#

Compute several classification metrics. * AUROC * At Youden point: balanced accuracy, Youden’s index, F1, PPV, NPV,

sensitivity, specificity

  • Sensitivity at fixed specificity

  • Specificity at fixed sensitivity

Parameters:
  • y_true (np.ndarray) – true labels

  • y_pred (np.ndarray) – probabilistic predictions

  • youden_point (float, optional) – Predetermined Youden point, e.g. based on training data. Defaults to None (computes Youden point based on y_pred).

  • fixed_sens (float, optional) – Compute specificity at this sensitivity. Defaults to 0.8.

  • fixed_spec (float, optional) – Compute sensitivity at this specificity. Defaults to 0.8.

Returns:

dictionary of metrics, Youden point

Return type:

dict, float

armed.metrics.compute_youden_point(y_true: numpy.ndarray, y_pred: numpy.ndarray)#

Compute Youden point (where the Youden index sensitivity + specificity - 1 is maximized)

Parameters:
  • y_true (np.ndarray) – true labels

  • y_pred (np.ndarray) – probabilistic predictions

Returns:

Youden point, maximum Youden index

Return type:

float, float

armed.metrics.image_metrics(img: numpy.ndarray)#

Compute image metrics, including brightness, contrast, sharpness, and SNR

Parameters:

img (np.ndarray) – image

Returns:

metrics

Return type:

dict

armed.metrics.sensitivity_at_specificity(y_true: numpy.ndarray, y_pred: numpy.ndarray, specificity: float = 0.8)#

Compute sensitivity at fixed specificity.

Parameters:
  • y_true (np.ndarray) – true labels

  • y_pred (np.ndarray) – probabilistic predictions

  • specificity (float, optional) – fixed specificity. Defaults to 0.8.

Returns:

sensitivity

Return type:

float

armed.metrics.single_sample_dice(y_true: numpy.ndarray, y_pred: numpy.ndarray, threshold: float = 0.5)#

Compute Dice score

Parameters:
  • y_true (np.ndarray) – true label image

  • y_pred (np.ndarray) – probabilistic predictions

  • threshold (float, optional) – label threshold. Defaults to 0.5.

Returns:

Dice score

Return type:

float

armed.metrics.specificity_at_sensitivity(y_true: numpy.ndarray, y_pred: numpy.ndarray, sensitivity: float = 0.8)#

Compute specificity at fixed sensitivity.

Parameters:
  • y_true (np.ndarray) – true labels

  • y_pred (np.ndarray) – probabilistic predictions

  • sensitivity (float, optional) – fixed sensitivity. Defaults to 0.8.

Returns:

specificity

Return type:

float

armed.misc module#

Miscellaneous utilities for expanding paths, getting datestamps, etc.

armed.misc.expand_data_path(path: str, make: bool = False)#

Concatenate path to DATADIR in settings.py.

Parameters:
  • path (str) – base path

  • make (bool, optional) – Make directory if it does not exist. Defaults to False.

Returns:

expanded path

Return type:

str

armed.misc.expand_results_path(path: str, make: bool = False)#

Concatenate directory path to RESULTSDIR in settings.py.

Parameters:
  • path (str) – base path

  • make (bool, optional) – Make directory if it does not exist. Defaults to False.

Returns:

expanded path

Return type:

str

armed.misc.get_datestamp(with_time: bool = False)#

Get datestamp with optional timestamp in format YYYY-MM-DD.

Parameters:
  • with_time (bool, optional) – Include timestamp in format HH-mm-SS.

  • False. (Defaults to) –

Returns:

datestamp

Return type:

str

armed.misc.make_random_onehot(n_rows: int, n_cols: int)#

Create a random one-hot encoding matrix

Parameters:
  • n_rows (int) – number of rows

  • n_cols (int) – number of columns

Returns:

one-hot matrix

Return type:

array

armed.settings module#

armed.tfutils module#

Utilities for Tensorflow sessions

armed.tfutils.set_gpu(gpu: int, mem_frac: float = 1.0)#

Assign GPU to Tensorflow session and limit memory usage

Parameters:
  • gpu (int) – GPU index

  • mem_frac (float, optional) – memory limit. Defaults to 1.0.

Module contents#