Utils

Labelprop Index / Labelprop / Utils

Auto-generated documentation for labelprop.utils module.

Normalize

Show source in utils.py:228

Signature

class Normalize(torch.nn.Module):
    def __init__(self, dim=2): ...

Normalize().forward

Show source in utils.py:233

Signature

def forward(self, x): ...

NumpyEncoder

Show source in utils.py:18

Special json encoder for numpy types

Signature

class NumpyEncoder(json.JSONEncoder): ...

NumpyEncoder().default

Show source in utils.py:20

Signature

def default(self, obj): ...

SuperST

Show source in utils.py:29

Inherit from SpatialTransformer

Signature

class SuperST(torch.nn.Module):
    def __init__(self, *args, **kwargs): ...

SuperST().apply_deform

Show source in utils.py:56

Signature

def apply_deform(self, x, flow): ...

SuperST().compose_deformation

Show source in utils.py:35

Returns flow_k_j(flow_i_k(.)) flow

Arguments

flow_i_k flow_k_j

Returns

  • [Tensor] - Flow field flow_i_j = flow_k_j(flow_i_k(.))

Signature

def compose_deformation(self, flow_i_k, flow_k_j): ...

SuperST().compose_list

Show source in utils.py:46

Signature

def compose_list(self, flows): ...

SuperST().forward

Show source in utils.py:53

Signature

def forward(self, x, flow): ...

binarize

Show source in utils.py:86

Signature

def binarize(Y, lab): ...

complex_propagation

Show source in utils.py:375

Deprecated

Signature

def complex_propagation(X, Y, model): ...

compute_metrics

Show source in utils.py:399

Signature

def compute_metrics(y_pred, y): ...

create_dict

Show source in utils.py:96

Signature

def create_dict(keys, values): ...

fuse_up_and_down

Show source in utils.py:128

Fuse up and down predictions using weights

Arguments

  • Y_up [Tensor] - Up predictions
  • Y_down [Tensor] - Down predictions
  • weights [Tensor] - Weights

Returns

  • [Tensor] - Fused predictions

Signature

def fuse_up_and_down(Y_up, Y_down, weights): ...

get_chunks

Show source in utils.py:67

Signature

def get_chunks(Y): ...

get_dices

Show source in utils.py:417

Compute dices for each slice of the volume, and for each label.

Arguments

  • Y_dense torch.Tensor - Dense ground truth segmentation.
  • Y torch.Tensor - Predicted segmentation in one direction.
  • Y2 torch.Tensor - Predicted segmentation in the other direction.
  • selected_slices list - List of index of manually segmented slices that were provided during the inference.

Signature

def get_dices(Y_dense, Y, Y2, selected_slices): ...

get_successive_fields

Show source in utils.py:166

Generate successive fields between slices, in both directions

Arguments

  • X [Tensor] - Volume
  • model [type] - Registration model

Returns

  • [list] - List of fields in one direction
  • [list] - List of fields in the other direction

Signature

def get_successive_fields(X, model): ...

get_weights

Show source in utils.py:102

Get weights for each slice based on the distance to the closest annotated slice

Arguments

  • Y [Tensor] - Sparsely annotated volume segmentation

Returns

  • [Tensor] - Weights

Signature

def get_weights(Y): ...

hardmax

Show source in utils.py:64

Signature

def hardmax(Y, dim): ...

propagate_by_composition

Show source in utils.py:236

Propagate labels by composition of transformations

Arguments

  • X torch.Tensor - input volume
  • Y torch.Tensor - input labels (sparse)
  • hints torch.Tensor - input hints
  • model torch.nn.Module - model to use for registration fields (list) (optionnal): list of fields to use for composition (if None, will be computed) criteria ('ncc' or 'distance') (optionnal): criteria to use for weighting. Default is ncc reduction ('none', 'mean' or 'local_mean') (optionnal): reduction method to use for weighting. Default is none func (torch.nn.Module) (optionnal): function to use for normalization. Default is Normalize(2) device (str) (optionnal): device to use. Default is 'cuda' return_weights (bool) (optionnal): whether to return weights. Default is False patch_size (int) (optionnal): patch size to compute NCC. Default is 31 (31x31 px) extrapolate (bool) (optionnal): whether to extrapolate propagation to the whole volume. Default is False

Returns

  • torch.Tensor - propagated labels in a single direction
  • torch.Tensor - propagated labels in the other direction
  • torch.Tensor - propagated labels in both directions (fused)

if return_weights: - torch.Tensor - weights used for fusion

Signature

def propagate_by_composition(
    X,
    Y,
    hints,
    model,
    fields=None,
    criteria="ncc",
    reduction="none",
    func=Normalize(2),
    device="cuda",
    return_weights=False,
    patch_size=31,
    extrapolate=False,
): ...

propagate_labels

Show source in utils.py:190

Deprecated

Signature

def propagate_labels(X, Y, model, model_down=None): ...

remove_annotations

Show source in utils.py:89

Signature

def remove_annotations(Y, selected_slices): ...

to_batch

Show source in utils.py:61

Signature

def to_batch(x, device="cpu"): ...

to_one_hot

Show source in utils.py:58

Signature

def to_one_hot(Y, dim=0): ...