parameters: (self, pred, target, label_weight, avg_factor=None)
return_statement: return loss * self.loss_weight
docstring: Args:
          pred [batch_num, 4 (* class_num)]:
              The prediction of box regression layer. Channel number can be 4 or
              (4 * class_num) depending on whether it is class-agnostic.
          target [batch_num, 4 (* class_num)]:
              The target regression values with the same size of pred.
          label_weight [batch_num, 4 (* class_num)]:
              The weight of each sample, 0 if ignored.
docstring_summary: Args:
          pred [batch_num, 4 (* class_num)]:
              The prediction of box regression layer. Channel number can be 4 or
              (4 * class_num) depending on whether it is class-agnostic.
          target [batch_num, 4 (* class_num)]:
              The target regression values with the same size of pred.
          label_weight [batch_num, 4 (* class_num)]:
              The weight of each sample, 0 if ignored.
docstring_tokens: Args : pred [ batch_num 4 ( * class_num ) ] : The prediction of box regression layer . Channel number can be 4 or ( 4 * class_num ) depending on whether it is class - agnostic . target [ batch_num 4 ( * class_num ) ] : The target regression values with the same size of pred . label_weight [ batch_num 4 ( * class_num ) ] : The weight of each sample 0 if ignored .
function: def forward(self, pred, target, label_weight, avg_factor=None):
          """ Args:
          pred [batch_num, 4 (* class_num)]:
              The prediction of box regression layer. Channel number can be 4 or
              (4 * class_num) depending on whether it is class-agnostic.
          target [batch_num, 4 (* class_num)]:
              The target regression values with the same size of pred.
          label_weight [batch_num, 4 (* class_num)]:
              The weight of each sample, 0 if ignored.
          """
          mu = self.mu
          edges = self.edges
          mmt = self.momentum
  
          # ASL1 loss
          diff = pred - target
          loss = torch.sqrt(diff * diff + mu * mu) - mu
  
          # gradient length
          g = torch.abs(diff / torch.sqrt(mu * mu + diff * diff)).detach()
          weights = torch.zeros_like(g)
  
          valid = label_weight > 0
          tot = max(label_weight.float().sum().item(), 1.0)
          n = 0  # n: valid bins
          for i in range(self.bins):
              inds = (g >= edges[i]) & (g < edges[i+1]) & valid
              num_in_bin = inds.sum().item()
              if num_in_bin > 0:
                  n += 1
                  if mmt > 0:
                      self.acc_sum[i] = mmt * self.acc_sum[i] \
                                        + (1 - mmt) * num_in_bin
                      weights[inds] = tot / self.acc_sum[i]
                  else:
                      weights[inds] = tot / num_in_bin
          if n > 0:
              weights /= n
  
          loss = loss * weights
          loss = loss.sum() / tot
          return loss * self.loss_weight
function_tokens: def forward ( self , pred , target , label_weight , avg_factor = None ) : mu = self . mu edges = self . edges mmt = self . momentum # ASL1 loss diff = pred - target loss = torch . sqrt ( diff * diff + mu * mu ) - mu # gradient length g = torch . abs ( diff / torch . sqrt ( mu * mu + diff * diff ) ) . detach ( ) weights = torch . zeros_like ( g ) valid = label_weight > 0 tot = max ( label_weight . float ( ) . sum ( ) . item ( ) , 1.0 ) n = 0 # n: valid bins for i in range ( self . bins ) : inds = ( g >= edges [ i ] ) & ( g < edges [ i + 1 ] ) & valid num_in_bin = inds . sum ( ) . item ( ) if num_in_bin > 0 : n += 1 if mmt > 0 : self . acc_sum [ i ] = mmt * self . acc_sum [ i ] + ( 1 - mmt ) * num_in_bin weights [ inds ] = tot / self . acc_sum [ i ] else : weights [ inds ] = tot / num_in_bin if n > 0 : weights /= n loss = loss * weights loss = loss . sum ( ) / tot return loss * self . loss_weight