class_docstr: Context Encoding for Semantic Segmentation.
  
  This head is the implementation of `EncNet
  <https://arxiv.org/abs/1803.08904>`_.
  
  Args:
      num_codes (int): Number of code words. Default: 32.
      use_se_loss (bool): Whether use Semantic Encoding Loss (SE-loss) to
          regularize the training. Default: True.
      add_lateral (bool): Whether use lateral connection to fuse features.
          Default: False.
      loss_se_decode (dict): Config of decode loss.
          Default: dict(type='CrossEntropyLoss', use_sigmoid=True).
class_docstr_tok: ["Context","Encoding","for","Semantic","Segmentation",".","This","head","is","the","implementation","of","`","EncNet","<","https",":","\/\/arxiv.org\/abs\/1803.08904",">","`","_",".","Args",":","num_codes","(","int",")",":","Number","of","code","words",".","Default",":","32.","use_se_loss","(","bool",")",":","Whether","use","Semantic","Encoding","Loss","(","SE-loss",")","to","regularize","the","training",".","Default",":","True",".","add_lateral","(","bool",")",":","Whether","use","lateral","connection","to","fuse","features",".","Default",":","False",".","loss_se_decode","(","dict",")",":","Config","of","decode","loss",".","Default",":","dict","(","type='CrossEntropyLoss","'",",","use_sigmoid=True",")","."]
docstr: Convert segmentation label to onehot.
  
  Args:
      seg_label (Tensor): Segmentation label of shape (N, H, W).
      num_classes (int): Number of classes.
  
  Returns:
      Tensor: Onehot labels of shape (N, num_classes).
docstr_tok: ["Convert","segmentation","label","to","onehot",".","Args",":","seg_label","(","Tensor",")",":","Segmentation","label","of","shape","(","N",",","H",",","W",")",".","num_classes","(","int",")",":","Number","of","classes",".","Returns",":","Tensor",":","Onehot","labels","of","shape","(","N",",","num_classes",")","."]
code: def _convert_to_onehot_labels(seg_label, num_classes):
      """Convert segmentation label to onehot.
  
      Args:
          seg_label (Tensor): Segmentation label of shape (N, H, W).
          num_classes (int): Number of classes.
  
      Returns:
          Tensor: Onehot labels of shape (N, num_classes).
      """
  
      batch_size = seg_label.size(0)
      onehot_labels = seg_label.new_zeros((batch_size, num_classes))
      for i in range(batch_size):
          hist = (
              seg_label[i]
              .float()
              .histc(bins=num_classes, min=0, max=num_classes - 1)
          )
          onehot_labels[i] = hist > 0
      return onehot_labels
  
file_path: lavis/lavis/common/annotator/uniformer/mmseg/models/decode_heads/enc_head.py
imports: import torch
  import torch.nn
  import torch.nn.functional
  from annotator.uniformer.mmcv.cnn import ConvModule, build_norm_layer
  from annotator.uniformer.mmseg.ops import Encoding, resize
  from ..builder import HEADS, build_loss
  from .decode_head import BaseDecodeHead
label_desc: Use image node_id 4 for calling the EncHead obj's underlying member method code with example usage: obj._convert_to_onehot_labels(seg_label, num_classes) and returns: onehot_labels