ece_loss/loss.py
def forward_(
        self, input: Tensor, target: Tensor, epoch: int, unannotated_mapping: Callable  # pylint: disable=W0622
    ) -> Tensor:

        """
        Uses the exclusivity threshold and annealing functions as described in the Sparse-shot Learning with Exclusive
        Cross-Entropy for Extremely Many Localisations paper[1] to produce the exclusive cross entropy loss.

        :param unannotated_mapping: mapping function to retrieve location of unannotated areas/samples. E.g.: for a
            binary mask this can be a lambda x: x == 0.
        :param input:  representing the unlabelled samples, a list of bounding box confidences of shape BxN, or a list
            of pixels from re-shaped images of shape Bx(HxW), or classification predictions of shape B or multiclass
            input of shape BxC..., where C is the number of classes.
        :param target: label masks of shape BxHxW, or a list of bounding box target confidence of shape BxN, or
            classification targets of shape B.
        :param epoch: the epoch integer value of the training phase
        :return: exclusive cross-entropy
        """
        cross_entropy = self.baseloss_forward(input, target)

        # Background (uniform) sampling. Assuming all input is from the background class
        unannotated_mask = unannotated_mapping(target).bool().to(target.device)
        background_sampling = (
            self.sample_from_background(unannotated_mask)
            <= self.background_sampling_annealing(epoch, self.background_sampling_threshold)
        ) * unannotated_mask

        # Exclusivity threshold
        confidence = self.confidence_estimator(input)
        exclusivity_mask = confidence <= self.exclusivity_threshold_annealing(epoch, self.exclusivity_threshold)
        background_sampling *= exclusivity_mask

        # Focal re-weighing and sampling
        unannotated_loss = self.focal_loss(cross_entropy) * background_sampling
        annotated_loss = cross_entropy * (~unannotated_mask * 1.0)
        ece_loss = unannotated_loss + annotated_loss
        return ece_loss

        Uses the exclusivity threshold and annealing functions as described in the Sparse-shot Learning with Exclusive
        Cross-Entropy for Extremely Many Localisations paper[1] to produce the exclusive cross entropy loss.

        :param unannotated_mapping: mapping function to retrieve location of unannotated areas/samples. E.g.: for a
            binary mask this can be a lambda x: x == 0.
        :param input:  representing the unlabelled samples, a list of bounding box confidences of shape BxN, or a list
            of pixels from re-shaped images of shape Bx(HxW), or classification predictions of shape B or multiclass
            input of shape BxC..., where C is the number of classes.
        :param target: label masks of shape BxHxW, or a list of bounding box target confidence of shape BxN, or
            classification targets of shape B.
        :param epoch: the epoch integer value of the training phase
        :return: exclusive cross-entropy
        
Uses the exclusivity threshold and annealing functions as described in the Sparse-shot Learning with Exclusive
Cross-Entropy for Extremely Many Localisations paper[1] to produce the exclusive cross entropy loss.
Uses the exclusivity threshold and annealing functions as described in the Sparse - shot Learning with Exclusive Cross - Entropy for Extremely Many Localisations paper [ 1 ] to produce the exclusive cross entropy loss .
def forward_(
        self, input: Tensor, target: Tensor, epoch: int, unannotated_mapping: Callable  
    ) -> Tensor:
        cross_entropy = self.baseloss_forward(input, target)
        unannotated_mask = unannotated_mapping(target).bool().to(target.device)
        background_sampling = (
            self.sample_from_background(unannotated_mask)
            <= self.background_sampling_annealing(epoch, self.background_sampling_threshold)
        ) * unannotated_mask
        confidence = self.confidence_estimator(input)
        exclusivity_mask = confidence <= self.exclusivity_threshold_annealing(epoch, self.exclusivity_threshold)
        background_sampling *= exclusivity_mask
        unannotated_loss = self.focal_loss(cross_entropy) * background_sampling
        annotated_loss = cross_entropy * (~unannotated_mask * 1.0)
        ece_loss = unannotated_loss + annotated_loss
        return ece_loss
def forward_ ( self , input : Tensor , target : Tensor , epoch : int , unannotated_mapping : Callable ) -> Tensor : cross_entropy = self . baseloss_forward ( input , target ) unannotated_mask = unannotated_mapping ( target ) . bool ( ) . to ( target . device ) background_sampling = ( self . sample_from_background ( unannotated_mask ) <= self . background_sampling_annealing ( epoch , self . background_sampling_threshold ) ) * unannotated_mask confidence = self . confidence_estimator ( input ) exclusivity_mask = confidence <= self . exclusivity_threshold_annealing ( epoch , self . exclusivity_threshold ) background_sampling *= exclusivity_mask unannotated_loss = self . focal_loss ( cross_entropy ) * background_sampling annotated_loss = cross_entropy * ( ~ unannotated_mask * 1.0 ) ece_loss = unannotated_loss + annotated_loss return ece_loss
Uses the exclusivity threshold and annealing functions as described in the Sparse-shot Learning with Exclusive
Cross-Entropy for Extremely Many Localisations paper[1] to produce the exclusive cross entropy loss.
Uses the exclusivity threshold and annealing functions as described in the Sparse - shot Learning with Exclusive Cross - Entropy for Extremely Many Localisations paper [ 1 ] to produce the exclusive cross entropy loss .
# pylint: disable=W0622 """
        Uses the exclusivity threshold and annealing functions as described in the Sparse-shot Learning with Exclusive
        Cross-Entropy for Extremely Many Localisations paper[1] to produce the exclusive cross entropy loss.

        :param unannotated_mapping: mapping function to retrieve location of unannotated areas/samples. E.g.: for a
            binary mask this can be a lambda x: x == 0.
        :param input:  representing the unlabelled samples, a list of bounding box confidences of shape BxN, or a list
            of pixels from re-shaped images of shape Bx(HxW), or classification predictions of shape B or multiclass
            input of shape BxC..., where C is the number of classes.
        :param target: label masks of shape BxHxW, or a list of bounding box target confidence of shape BxN, or
            classification targets of shape B.
        :param epoch: the epoch integer value of the training phase
        :return: exclusive cross-entropy
        """ # Background (uniform) sampling. Assuming all input is from the background class # Exclusivity threshold # Focal re-weighing and sampling
None
self
input
Tensor
representing the unlabelled samples, a list of bounding box confidences of shape BxN, or a list
of pixels from re-shaped images of shape Bx(HxW), or classification predictions of shape B or multiclass
input of shape BxC..., where C is the number of classes.
representing the unlabelled samples a list of bounding box confidences of shape BxN or a list of pixels from re - shaped images of shape Bx ( HxW ) or classification predictions of shape B or multiclass input of shape BxC ... where C is the number of classes .
target
Tensor
label masks of shape BxHxW, or a list of bounding box target confidence of shape BxN, or
classification targets of shape B.
label masks of shape BxHxW or a list of bounding box target confidence of shape BxN or classification targets of shape B .
epoch
int
the epoch integer value of the training phase
the epoch integer value of the training phase
unannotated_mapping
Callable
mapping function to retrieve location of unannotated areas/samples. E.g.: for a
binary mask this can be a lambda x: x == 0.
mapping function to retrieve location of unannotated areas / samples . E . g . : for a binary mask this can be a lambda x : x == 0 .