elektronn2.malis.malisop module

elektronn2.malis.malisop.malis_weights(affinity_pred, affinity_gt, seg_gt, nhood, unrestrict_neg=False)[source]

Computes MALIS loss weights

Roughly speaking the malis weights quantify the impact of an edge in the predicted affinity graph on the resulting segmentation.

Parameters:
  • affinity_pred (4d np.ndarray float32) – Affinity graph of shape (#edges, x, y, z) 1: connected, 0: disconnected
  • affinity_gt (4d np.ndarray int16) – Affinity graph of shape (#edges, x, y, z) 1: connected, 0: disconnected
  • seg_gt (3d np.ndarray, int (any precision)) – Volume of segmentation IDs
  • nhood (2d np.ndarray, int) – Neighbourhood pattern specifying the edges in the affinity graph Shape: (#edges, ndim) nhood[i] contains the displacement coordinates of edge i The number and order of edges is arbitrary
  • unrestrict_neg (Bool) – Use this to relax the restriction on neg_counts. The restriction modifies the edge weights for before calculating the negative counts as: edge_weights_neg = np.maximum(affinity_pred, affinity_gt) If unrestricted the predictions are used directly.
Returns:

  • pos_counts (4d np.ndarray int32) – Impact counts for edges that should be 1 (connect)
  • neg_counts (4d np.ndarray int32) – Impact counts for edges that should be 0 (disconnect)

  • Computes for all pixel-pairs the MaxiMin-Affinity
  • Separately for pixel-pairs that should/should not be connected
  • Every time an affinity prediction is a MaxiMin-Affinity its weight is incremented by one in the output matrix (in different slices depending on whether that that pair should/should not be connected)