parameters: (self, pred, target, label_weight, *args, **kwargs)
return_statement: return loss * self.loss_weight
docstring: Args:
          pred [batch_num, class_num]:
              The direct prediction of classification fc layer.
          target [batch_num, class_num]:
              Binary class target for each sample.
          label_weight [batch_num, class_num]:
              the value is 1 if the sample is valid and 0 if ignored.
docstring_summary: Args:
          pred [batch_num, class_num]:
              The direct prediction of classification fc layer.
          target [batch_num, class_num]:
              Binary class target for each sample.
          label_weight [batch_num, class_num]:
              the value is 1 if the sample is valid and 0 if ignored.
docstring_tokens: Args : pred [ batch_num class_num ] : The direct prediction of classification fc layer . target [ batch_num class_num ] : Binary class target for each sample . label_weight [ batch_num class_num ] : the value is 1 if the sample is valid and 0 if ignored .
function: def forward(self, pred, target, label_weight, *args, **kwargs):
          """ Args:
          pred [batch_num, class_num]:
              The direct prediction of classification fc layer.
          target [batch_num, class_num]:
              Binary class target for each sample.
          label_weight [batch_num, class_num]:
              the value is 1 if the sample is valid and 0 if ignored.
          """
          if not self.use_sigmoid:
              raise NotImplementedError
          # the target should be binary class label
          if pred.dim() != target.dim():
              target, label_weight = _expand_binary_labels(target, label_weight, pred.size(-1))
          target, label_weight = target.float(), label_weight.float()
          edges = self.edges
          mmt = self.momentum
          weights = torch.zeros_like(pred)
  
          # gradient length
          g = torch.abs(pred.sigmoid().detach() - target)
  
          valid = label_weight > 0
          tot = max(valid.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:
                  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
                  n += 1
          if n > 0:
              weights = weights / n
  
          loss = F.binary_cross_entropy_with_logits(
              pred, target, weights, reduction='sum') / tot
          return loss * self.loss_weight
function_tokens: def forward ( self , pred , target , label_weight , * args , * * kwargs ) : if not self . use_sigmoid : raise NotImplementedError # the target should be binary class label if pred . dim ( ) != target . dim ( ) : target , label_weight = _expand_binary_labels ( target , label_weight , pred . size ( - 1 ) ) target , label_weight = target . float ( ) , label_weight . float ( ) edges = self . edges mmt = self . momentum weights = torch . zeros_like ( pred ) # gradient length g = torch . abs ( pred . sigmoid ( ) . detach ( ) - target ) valid = label_weight > 0 tot = max ( valid . 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 : 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 n += 1 if n > 0 : weights = weights / n loss = F . binary_cross_entropy_with_logits ( pred , target , weights , reduction = 'sum' ) / tot return loss * self . loss_weight