class_docstr: Base class for segmentation heads
class_docstr_tok: ["Base","class","for","segmentation","heads"]
code: def __init__(
      self,
      opts,
      enc_conf: dict,
      use_l5_exp: Optional[bool] = False,
      *args,
      **kwargs,
  ):
      enc_ch_l5_exp_out = _check_out_channels(
          enc_conf, "exp_before_cls"
      )
      enc_ch_l5_out = _check_out_channels(enc_conf, "layer5")
      enc_ch_l4_out = _check_out_channels(enc_conf, "layer4")
      enc_ch_l3_out = _check_out_channels(enc_conf, "layer3")
      enc_ch_l2_out = _check_out_channels(enc_conf, "layer2")
      enc_ch_l1_out = _check_out_channels(enc_conf, "layer1")
  
      n_seg_classes = getattr(opts, "model.segmentation.n_classes")
      if n_seg_classes is None:
          logger.error(
              "Please specify number of segmentation classes using --model.segmentation.n-classes. Got None."
          )
  
      super().__init__(opts, *args, **kwargs)
  
      self.use_l5_exp = use_l5_exp
      self.enc_l5_exp_channels = enc_ch_l5_exp_out
      self.enc_l5_channels = enc_ch_l5_out
      self.enc_l4_channels = enc_ch_l4_out
      self.enc_l3_channels = enc_ch_l3_out
      self.enc_l2_channels = enc_ch_l2_out
      self.enc_l1_channels = enc_ch_l1_out
  
      self.n_seg_classes = n_seg_classes
      self.lr_multiplier = getattr(
          opts, "model.segmentation.lr_multiplier", 1.0
      )
      self.classifier_dropout = getattr(
          opts, "model.segmentation.classifier_dropout", 0.1
      )
      self.output_stride = getattr(
          opts, "model.segmentation.output_stride", 16
      )
  
      self.aux_head = None
      if getattr(opts, "model.segmentation.use_aux_head", False):
          drop_aux = getattr(
              opts, "model.segmentation.aux_dropout", 0.1
          )
          inner_channels = max(int(self.enc_l4_channels // 4), 128)
          self.aux_head = nn.Sequential(
              ConvLayer2d(
                  opts=opts,
                  in_channels=self.enc_l4_channels,
                  out_channels=inner_channels,
                  kernel_size=3,
                  stride=1,
                  use_norm=True,
                  use_act=True,
                  bias=False,
                  groups=1,
              ),
              Dropout2d(drop_aux),
              ConvLayer2d(
                  opts=opts,
                  in_channels=inner_channels,
                  out_channels=self.n_seg_classes,
                  kernel_size=1,
                  stride=1,
                  use_norm=False,
                  use_act=False,
                  bias=True,
                  groups=1,
              ),
          )
  
      self.upsample_seg_out = None
      if self.output_stride != 1.0:
          self.upsample_seg_out = UpSample(
              scale_factor=self.output_stride,
              mode="bilinear",
              align_corners=True,
          )
  
file_path: ml-cvnets/cvnets/models/segmentation/heads/base_seg_head.py
imports: import argparse
  from typing import Dict, Optional, Tuple
  from torch import Tensor, nn
  from cvnets.layers import ConvLayer2d, Dropout2d, UpSample
  from cvnets.misc.common import parameter_list
  from cvnets.misc.init_utils import initialize_weights
  from cvnets.models import MODEL_REGISTRY, BaseAnyNNModel
  from utils import logger
label_desc: Use image node_id 1 to create a new BaseSegHead object from inherited base classes: BaseAnyNNModel with example: obj = BaseSegHead(opts, enc_conf, use_l5_exp)