Utils
Labelprop Index / Labelprop / Utils
Auto-generated documentation for labelprop.utils module.
- Utils
- Normalize
- NumpyEncoder
- SuperST
- binarize
- complex_propagation
- compute_metrics
- create_dict
- fuse_up_and_down
- get_chunks
- get_dices
- get_successive_fields
- get_weights
- hardmax
- propagate_by_composition
- propagate_labels
- remove_annotations
- to_batch
- to_one_hot
Normalize
Signature
class Normalize(torch.nn.Module):
def __init__(self, dim=2): ...
Normalize().forward
Signature
def forward(self, x): ...
NumpyEncoder
Special json encoder for numpy types
Signature
class NumpyEncoder(json.JSONEncoder): ...
NumpyEncoder().default
Signature
def default(self, obj): ...
SuperST
Inherit from SpatialTransformer
Signature
class SuperST(torch.nn.Module):
def __init__(self, *args, **kwargs): ...
SuperST().apply_deform
Signature
def apply_deform(self, x, flow): ...
SuperST().compose_deformation
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
Signature
def compose_list(self, flows): ...
SuperST().forward
Signature
def forward(self, x, flow): ...
binarize
Signature
def binarize(Y, lab): ...
complex_propagation
Deprecated
Signature
def complex_propagation(X, Y, model): ...
compute_metrics
Signature
def compute_metrics(y_pred, y): ...
create_dict
Signature
def create_dict(keys, values): ...
fuse_up_and_down
Fuse up and down predictions using weights
Arguments
Y_up[Tensor] - Up predictionsY_down[Tensor] - Down predictionsweights[Tensor] - Weights
Returns
[Tensor]- Fused predictions
Signature
def fuse_up_and_down(Y_up, Y_down, weights): ...
get_chunks
Signature
def get_chunks(Y): ...
get_dices
Compute dices for each slice of the volume, and for each label.
Arguments
Y_densetorch.Tensor - Dense ground truth segmentation.Ytorch.Tensor - Predicted segmentation in one direction.Y2torch.Tensor - Predicted segmentation in the other direction.selected_sliceslist - 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
Generate successive fields between slices, in both directions
Arguments
X[Tensor] - Volumemodel[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
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
Signature
def hardmax(Y, dim): ...
propagate_by_composition
Propagate labels by composition of transformations
Arguments
Xtorch.Tensor - input volumeYtorch.Tensor - input labels (sparse)hintstorch.Tensor - input hintsmodeltorch.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 directiontorch.Tensor- propagated labels in the other directiontorch.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
Deprecated
Signature
def propagate_labels(X, Y, model, model_down=None): ...
remove_annotations
Signature
def remove_annotations(Y, selected_slices): ...
to_batch
Signature
def to_batch(x, device="cpu"): ...
to_one_hot
Signature
def to_one_hot(Y, dim=0): ...