(self,
                        prediction_tensor,
                        target_tensor,
                        weights)
return loss
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):
        """ 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.
        """
        # ASL1 loss
        diff = prediction_tensor - target_tensor
        loss = torch.sqrt(diff * diff + self.mu * self.mu) - self.mu
        batch_size = prediction_tensor.shape[0]
        num_anchors = prediction_tensor.shape[1]
        num_codes = prediction_tensor.shape[2]

        # gradient length
        g = torch.abs(diff / torch.sqrt(self.mu * self.mu + diff * diff)).detach().view(-1, num_codes)
        weights_ghm = torch.zeros_like(g)
        
        valid = weights.view(-1, 1).expand(-1, num_codes) > 0
        # print(g.shape, prediction_tensor.shape, valid.shape)
        num_examples = max(valid.float().sum().item() / num_codes, 1.0)
        num_valid_bins = 0  # n: valid bins
        for i in range(self.bins):
            inds = (g >= self.edges[i]) & (g < self.edges[i+1]) & valid
            num_in_bin = inds.sum().item()
            if num_in_bin > 0:
                num_valid_bins += 1
                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
        if num_valid_bins > 0:
            weights_ghm /= num_valid_bins
        weights_ghm = weights_ghm.view(batch_size, num_anchors, num_codes)
        loss = loss * weights_ghm / num_examples
        return loss
def _compute_loss ( self , prediction_tensor , target_tensor , weights ) : # ASL1 loss diff = prediction_tensor - target_tensor loss = torch . sqrt ( diff * diff + self . mu * self . mu ) - self . mu batch_size = prediction_tensor . shape [ 0 ] num_anchors = prediction_tensor . shape [ 1 ] num_codes = prediction_tensor . shape [ 2 ] # gradient length g = torch . abs ( diff / torch . sqrt ( self . mu * self . mu + diff * diff ) ) . detach ( ) . view ( - 1 , num_codes ) weights_ghm = torch . zeros_like ( g ) valid = weights . view ( - 1 , 1 ) . expand ( - 1 , num_codes ) > 0 # print(g.shape, prediction_tensor.shape, valid.shape) num_examples = max ( valid . float ( ) . sum ( ) . item ( ) / num_codes , 1.0 ) num_valid_bins = 0 # n: valid bins for i in range ( self . bins ) : inds = ( g >= self . edges [ i ] ) & ( g < self . edges [ i + 1 ] ) & valid num_in_bin = inds . sum ( ) . item ( ) if num_in_bin > 0 : num_valid_bins += 1 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 if num_valid_bins > 0 : weights_ghm /= num_valid_bins weights_ghm = weights_ghm . view ( batch_size , num_anchors , num_codes ) loss = loss * weights_ghm / num_examples return loss