(self,
                        prediction_tensor,
                        target_tensor,
                        weights,
                        class_indices=None)
return per_entry_cross_ent * weights_ghm.view(batch_size, num_anchors, num_class) / num_examples
Args:
        input [batch_num, class_num]:
            The direct prediction of classification fc layer.
        target [batch_num, class_num]:
            Binary target (0 or 1) for each sample each class. The value is -1
            when the sample is ignored.
Args:
        input [batch_num, class_num]:
            The direct prediction of classification fc layer.
        target [batch_num, class_num]:
            Binary target (0 or 1) for each sample each class. The value is -1
            when the sample is ignored.
Args : input [ batch_num class_num ] : The direct prediction of classification fc layer . target [ batch_num class_num ] : Binary target ( 0 or 1 ) for each sample each class . The value is - 1 when the sample is ignored .
def _compute_loss(self,
                        prediction_tensor,
                        target_tensor,
                        weights,
                        class_indices=None):
        """ Args:
        input [batch_num, class_num]:
            The direct prediction of classification fc layer.
        target [batch_num, class_num]:
            Binary target (0 or 1) for each sample each class. The value is -1
            when the sample is ignored.
        """
        input = prediction_tensor
        target = target_tensor
        batch_size = prediction_tensor.shape[0]
        num_anchors = prediction_tensor.shape[1]
        num_class = prediction_tensor.shape[2]
        edges = self.edges
        weights_ghm = torch.zeros_like(input).view(-1, num_class)
        per_entry_cross_ent = (_sigmoid_cross_entropy_with_logits(
            labels=target_tensor, logits=prediction_tensor))
        # gradient length
        g = torch.abs(input.sigmoid().detach() - target).view(-1, num_class)
        valid = weights.view(-1, 1).expand(-1, num_class) > 0
        num_examples = max(valid.float().sum().item(), 1.0)
        num_valid_bins = 0  # n valid bins
        self.count -= 1
        num_bins = []
        for i in range(self.bins):
            inds = (g >= edges[i]) & (g < edges[i+1]) & valid
            num_in_bin = inds.sum().item()
            num_bins.append(num_in_bin)
            if num_in_bin > 0:
                if self.momentum > 0:
                    self.acc_sum[i] = self.momentum * self.acc_sum[i] \
                        + (1 - self.momentum) * num_in_bin
                    weights_ghm[inds] = num_examples / self.acc_sum[i]
                else:
                    weights_ghm[inds] = num_examples / num_in_bin
                num_valid_bins += 1
        if self.count <= 0:
            print("GHMC loss bins:", num_bins)
            self.count = 50
        if num_valid_bins > 0:
            weights_ghm = weights_ghm / num_valid_bins
        return per_entry_cross_ent * weights_ghm.view(batch_size, num_anchors, num_class) / num_examples
def _compute_loss ( self , prediction_tensor , target_tensor , weights , class_indices = None ) : input = prediction_tensor target = target_tensor batch_size = prediction_tensor . shape [ 0 ] num_anchors = prediction_tensor . shape [ 1 ] num_class = prediction_tensor . shape [ 2 ] edges = self . edges weights_ghm = torch . zeros_like ( input ) . view ( - 1 , num_class ) per_entry_cross_ent = ( _sigmoid_cross_entropy_with_logits ( labels = target_tensor , logits = prediction_tensor ) ) # gradient length g = torch . abs ( input . sigmoid ( ) . detach ( ) - target ) . view ( - 1 , num_class ) valid = weights . view ( - 1 , 1 ) . expand ( - 1 , num_class ) > 0 num_examples = max ( valid . float ( ) . sum ( ) . item ( ) , 1.0 ) num_valid_bins = 0 # n valid bins self . count -= 1 num_bins = [ ] for i in range ( self . bins ) : inds = ( g >= edges [ i ] ) & ( g < edges [ i + 1 ] ) & valid num_in_bin = inds . sum ( ) . item ( ) num_bins . append ( num_in_bin ) if num_in_bin > 0 : if self . momentum > 0 : self . acc_sum [ i ] = self . momentum * self . acc_sum [ i ] + ( 1 - self . momentum ) * num_in_bin weights_ghm [ inds ] = num_examples / self . acc_sum [ i ] else : weights_ghm [ inds ] = num_examples / num_in_bin num_valid_bins += 1 if self . count <= 0 : print ( "GHMC loss bins:" , num_bins ) self . count = 50 if num_valid_bins > 0 : weights_ghm = weights_ghm / num_valid_bins return per_entry_cross_ent * weights_ghm . view ( batch_size , num_anchors , num_class ) / num_examples