class_docstr: Instance Context Encoder
  1. construct feature pyramids from ResNet
  2. enlarge receptive fields (ppm)
  3. multi-scale fusion
class_docstr_tok: ["Instance","Context","Encoder","1.","construct","feature","pyramids","from","ResNet","2.","enlarge","receptive","fields","(","ppm",")","3.","multi-scale","fusion"]
code: def __init__(
      self,
      in_channels,
      out_channels=256,
      with_ppm=True,
      act_cfg=dict(type="ReLU"),
  ):
      super().__init__()
      self.num_channels = out_channels
      self.in_channels = in_channels
      self.with_ppm = with_ppm
      fpn_laterals = []
      fpn_outputs = []
      for in_channel in reversed(self.in_channels):
          lateral_conv = nn.Conv2d(in_channel, self.num_channels, 1)
          output_conv = nn.Conv2d(
              self.num_channels, self.num_channels, 3, padding=1
          )
          caffe2_xavier_init(lateral_conv)
          caffe2_xavier_init(output_conv)
          fpn_laterals.append(lateral_conv)
          fpn_outputs.append(output_conv)
      self.fpn_laterals = nn.ModuleList(fpn_laterals)
      self.fpn_outputs = nn.ModuleList(fpn_outputs)
      # ppm
      if self.with_ppm:
          self.ppm = PyramidPoolingModule(
              self.num_channels, self.num_channels // 4, act_cfg=act_cfg
          )
      # final fusion
      self.fusion = nn.Conv2d(
          self.num_channels * 3, self.num_channels, 1
      )
      kaiming_init(self.fusion)
  
file_path: mmdetection/projects/SparseInst/sparseinst/encoder.py
imports: import torch
  import torch.nn
  import torch.nn.functional
  from mmengine.model.weight_init import caffe2_xavier_init, kaiming_init
  from mmdet.registry import MODELS
label_desc: Use image node_id 1 to create a new InstanceContextEncoder object from inherited base classes: nn with example: obj = InstanceContextEncoder(in_channels, out_channels, with_ppm, act_cfg)