mlreco.models.layers.cluster_cnn.losses.misc module¶
-
mlreco.models.layers.cluster_cnn.losses.misc.iou_batch(pred: torch.BoolTensor, labels: torch.BoolTensor, eps=0.0)[source]¶ pred: N x C labels: N x C (one-hot)
-
class
mlreco.models.layers.cluster_cnn.losses.misc.VectorEstimationLoss(cfg, name='vector_estimation_loss')[source]¶ Bases:
torch.nn.modules.module.Module-
__init__(cfg, name='vector_estimation_loss')[source]¶ Initializes internal Module state, shared by both nn.Module and ScriptModule.
-
compute_loss_single_graph(vec_pred, pos)[source]¶ - INPUTS:
x (N x 4) : sin/cos predictions for phi and theta.
pos (N x 3 Tensor): spatial coordinates (batch, semantic_id)
-
forward(graph)[source]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
__module__= 'mlreco.models.layers.cluster_cnn.losses.misc'¶
-
training: bool¶
-
-
class
mlreco.models.layers.cluster_cnn.losses.misc.BinaryLogDiceLoss(gamma=1)[source]¶ Bases:
torch.nn.modules.module.Module-
__init__(gamma=1)[source]¶ Initializes internal Module state, shared by both nn.Module and ScriptModule.
-
forward(logits, targets, eps=1e-06)[source]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
__module__= 'mlreco.models.layers.cluster_cnn.losses.misc'¶
-
training: bool¶
-
-
class
mlreco.models.layers.cluster_cnn.losses.misc.IoUScore[source]¶ Bases:
torch.nn.modules.module.Module-
forward(y_pred, y_true)[source]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
__module__= 'mlreco.models.layers.cluster_cnn.losses.misc'¶
-
training: bool¶
-
-
class
mlreco.models.layers.cluster_cnn.losses.misc.BinaryCELogDiceLoss(gamma=0.3, w_ce=0.2, w_dice=0.8)[source]¶ Bases:
torch.nn.modules.module.Module-
__init__(gamma=0.3, w_ce=0.2, w_dice=0.8)[source]¶ Initializes internal Module state, shared by both nn.Module and ScriptModule.
-
forward(logits, targets, weight=None, eps=0.001, reduction='none')[source]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
__module__= 'mlreco.models.layers.cluster_cnn.losses.misc'¶
-
training: bool¶
-
-
class
mlreco.models.layers.cluster_cnn.losses.misc.MincutLoss(mincut_weight=1.0, **kwargs)[source]¶ Bases:
mlreco.models.layers.cluster_cnn.losses.misc.BinaryCELogDiceLoss-
__init__(mincut_weight=1.0, **kwargs)[source]¶ Initializes internal Module state, shared by both nn.Module and ScriptModule.
-
forward(logits, targets, weight=None, eps=0.001, reduction='none')[source]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
__module__= 'mlreco.models.layers.cluster_cnn.losses.misc'¶
-
training: bool¶
-
-
class
mlreco.models.layers.cluster_cnn.losses.misc.LovaszHingeLoss(reduction='none')[source]¶ Bases:
torch.nn.modules.loss._Loss-
__init__(reduction='none')[source]¶ Initializes internal Module state, shared by both nn.Module and ScriptModule.
-
forward(logits, targets)[source]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
__module__= 'mlreco.models.layers.cluster_cnn.losses.misc'¶
-
reduction: str¶
-
-
class
mlreco.models.layers.cluster_cnn.losses.misc.LovaszSoftmaxWithLogitsLoss(reduction='none')[source]¶ Bases:
torch.nn.modules.loss._Loss-
__init__(reduction='none')[source]¶ Initializes internal Module state, shared by both nn.Module and ScriptModule.
-
forward(logits, targets)[source]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
__module__= 'mlreco.models.layers.cluster_cnn.losses.misc'¶
-
reduction: str¶
-
-
mlreco.models.layers.cluster_cnn.losses.misc.find_cluster_means(features, labels)[source]¶ For a given image, compute the centroids mu_c for each cluster label in the embedding space. Inputs:
features (torch.Tensor): the pixel embeddings, shape=(N, d) where N is the number of pixels and d is the embedding space dimension. labels (torch.Tensor): ground-truth group labels, shape=(N, )
- Returns
(n_c, d) tensor where n_c is the number of distinct instances. Each row is a (1,d) vector corresponding to the coordinates of the i-th centroid.
- Return type
cluster_means (torch.Tensor)
-
mlreco.models.layers.cluster_cnn.losses.misc.intra_cluster_loss(features, cluster_means, labels, margin=1.0)[source]¶
-
mlreco.models.layers.cluster_cnn.losses.misc.margin_smoothing_loss(sigma, sigma_means, labels, margin=0)[source]¶
-
mlreco.models.layers.cluster_cnn.losses.misc.get_probs(embeddings, margins, labels, eps=1e-06)[source]¶
-
mlreco.models.layers.cluster_cnn.losses.misc.multivariate_kernel(centroid, log_sigma, Lprime, eps=1e-08)[source]¶
-
mlreco.models.layers.cluster_cnn.losses.misc.bhattacharyya_distance_matrix(v1, v2, eps=1e-08)[source]¶
-
mlreco.models.layers.cluster_cnn.losses.misc.get_graphspice_logits(sp_emb, ft_emb, cov, groups, sp_centroids, ft_centroids, eps=0.001, compute_accuracy=True)[source]¶
-
class
mlreco.models.layers.cluster_cnn.losses.misc.FocalLoss(alpha=1, gamma=2, logits=False, reduce=True)[source]¶ Bases:
torch.nn.modules.module.ModuleOriginal Paper: https://arxiv.org/abs/1708.02002 Implementation: https://www.kaggle.com/c/tgs-salt-identification-challenge/discussion/65938
-
__init__(alpha=1, gamma=2, logits=False, reduce=True)[source]¶ Initializes internal Module state, shared by both nn.Module and ScriptModule.
-
forward(inputs, targets)[source]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
__module__= 'mlreco.models.layers.cluster_cnn.losses.misc'¶
-
training: bool¶
-
-
class
mlreco.models.layers.cluster_cnn.losses.misc.WeightedFocalLoss(alpha=1, gamma=2, logits=False, reduce=True)[source]¶ Bases:
mlreco.models.layers.cluster_cnn.losses.misc.FocalLoss-
__init__(alpha=1, gamma=2, logits=False, reduce=True)[source]¶ Initializes internal Module state, shared by both nn.Module and ScriptModule.
-
forward(inputs, targets)[source]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
__module__= 'mlreco.models.layers.cluster_cnn.losses.misc'¶
-
training: bool¶
-