class_docstr: The PixelContrastCrossEntropyLoss implementation based on PaddlePaddle.
  
  The original article refers to
  Wenguan Wang, Tianfei Zhou, et al. "Exploring Cross-Image Pixel Contrast for Semantic Segmentation"
  (https://arxiv.org/abs/2101.11939).
  
  Args:
      temperature (float, optional): Controling the numerical similarity of features. Default: 0.1.
      base_temperature (float, optional): Controling the numerical range of contrast loss. Default: 0.07.
      ignore_index (int, optional): Specifies a target value that is ignored
          and does not contribute to the input gradient. Default 255.
      max_samples (int, optional): Max sampling anchors. Default: 1024.
      max_views (int): Sampled samplers of a class. Default: 100.
class_docstr_tok: ["The","PixelContrastCrossEntropyLoss","implementation","based","on","PaddlePaddle",".","The","original","article","refers","to","Wenguan","Wang",",","Tianfei","Zhou",",","et","al",".","``","Exploring","Cross-Image","Pixel","Contrast","for","Semantic","Segmentation","''","(","https",":","\/\/arxiv.org\/abs\/2101.11939",")",".","Args",":","temperature","(","float",",","optional",")",":","Controling","the","numerical","similarity","of","features",".","Default",":","0.1.","base_temperature","(","float",",","optional",")",":","Controling","the","numerical","range","of","contrast","loss",".","Default",":","0.07.","ignore_index","(","int",",","optional",")",":","Specifies","a","target","value","that","is","ignored","and","does","not","contribute","to","the","input","gradient",".","Default","255.","max_samples","(","int",",","optional",")",":","Max","sampling","anchors",".","Default",":","1024.","max_views","(","int",")",":","Sampled","samplers","of","a","class",".","Default",":","100","."]
docstr: Args:
      feats_ (Tensor): sampled pixel, shape = [total_classes, n_view, feat_dim], total_classes = batch_size * single image classes
      labels_ (Tensor): label, shape = [total_classes]
docstr_tok: ["Args",":","feats_","(","Tensor",")",":","sampled","pixel",",","shape","=","[","total_classes",",","n_view",",","feat_dim","]",",","total_classes","=","batch_size","*","single","image","classes","labels_","(","Tensor",")",":","label",",","shape","=","[","total_classes","]"]
code: def _contrastive(self, feats_, labels_):
      """
      Args:
          feats_ (Tensor): sampled pixel, shape = [total_classes, n_view, feat_dim], total_classes = batch_size * single image classes
          labels_ (Tensor): label, shape = [total_classes]
      """
      anchor_num, n_view = feats_.shape[0], feats_.shape[1]
  
      labels_ = labels_.reshape((-1, 1))
      mask = paddle.equal(
          labels_, paddle.transpose(labels_, [1, 0])
      ).astype("float32")
  
      contrast_count = n_view
      contrast_feature = paddle.concat(
          paddle.unbind(feats_, axis=1), axis=0
      )
  
      anchor_feature = contrast_feature
      anchor_count = contrast_count
  
      anchor_dot_contrast = (
          paddle.matmul(
              anchor_feature, paddle.transpose(contrast_feature, [1, 0])
          )
          / self.temperature
      )
      logits_max = paddle.max(anchor_dot_contrast, axis=1, keepdim=True)
      logits = anchor_dot_contrast - logits_max
  
      mask = paddle.tile(mask, [anchor_count, contrast_count])
      neg_mask = 1 - mask
  
      logits_mask = 1 - paddle.eye(mask.shape[0]).astype("float32")
      mask = mask * logits_mask
  
      neg_logits = paddle.exp(logits) * neg_mask
      neg_logits = neg_logits.sum(1, keepdim=True)
  
      exp_logits = paddle.exp(logits)
  
      log_prob = logits - paddle.log(exp_logits + neg_logits)
  
      mean_log_prob_pos = (mask * log_prob).sum(1) / mask.sum(1)
  
      loss = (
          -(self.temperature / self.base_temperature)
          * mean_log_prob_pos
      )
      loss = loss.mean()
  
      return loss
  
file_path: PaddleSeg/paddleseg/models/losses/pixel_contrast_cross_entropy_loss.py
imports: import paddle
  import paddle.nn
  import paddle.nn.functional
  from paddleseg.cvlibs import manager
label_desc: Use image node_id 3 for calling the PixelContrastCrossEntropyLoss obj's underlying member method code with example usage: obj._contrastive(feats_, labels_) and returns: loss