class_docstr: Position encoding with sine and cosine functions.
  
  See `End-to-End Object Detection with Transformers
  <https://arxiv.org/pdf/2005.12872>`_ for details.
  
  Args:
      num_feats (int): The feature dimension for each position
          along x-axis or y-axis. Note the final returned dimension
          for each position is 2 times of this value.
      temperature (int, optional): The temperature used for scaling
          the position embedding. Defaults to 10000.
      normalize (bool, optional): Whether to normalize the position
          embedding. Defaults to False.
      scale (float, optional): A scale factor that scales the position
          embedding. The scale will be used only when `normalize` is True.
          Defaults to 2*pi.
      eps (float, optional): A value added to the denominator for
          numerical stability. Defaults to 1e-6.
      offset (float): offset add to embed when do the normalization.
          Defaults to 0.
      init_cfg (dict or list[dict], optional): Initialization config dict.
          Defaults to None
class_docstr_tok: ["Position","encoding","with","sine","and","cosine","functions",".","See","`","End-to-End","Object","Detection","with","Transformers","<","https",":","\/\/arxiv.org\/pdf\/2005.12872",">","`","_","for","details",".","Args",":","num_feats","(","int",")",":","The","feature","dimension","for","each","position","along","x-axis","or","y-axis",".","Note","the","final","returned","dimension","for","each","position","is","2","times","of","this","value",".","temperature","(","int",",","optional",")",":","The","temperature","used","for","scaling","the","position","embedding",".","Defaults","to","10000.","normalize","(","bool",",","optional",")",":","Whether","to","normalize","the","position","embedding",".","Defaults","to","False",".","scale","(","float",",","optional",")",":","A","scale","factor","that","scales","the","position","embedding",".","The","scale","will","be","used","only","when","`","normalize","`","is","True",".","Defaults","to","2","*","pi",".","eps","(","float",",","optional",")",":","A","value","added","to","the","denominator","for","numerical","stability",".","Defaults","to","1e-6",".","offset","(","float",")",":","offset","add","to","embed","when","do","the","normalization",".","Defaults","to","0.","init_cfg","(","dict","or","list","[","dict","]",",","optional",")",":","Initialization","config","dict",".","Defaults","to","None"]
docstr: Forward function for `SinePositionalEncoding`.
  
  Args:
      mask (Tensor): ByteTensor mask. Non-zero values representing
          ignored positions, while zero values means valid positions
          for this image. Shape [bs, h, w].
      input (Tensor, optional): Input image/feature Tensor.
          Shape [bs, c, h, w]
  
  Returns:
      pos (Tensor): Returned position embedding with shape
          [bs, num_feats*2, h, w].
docstr_tok: ["Forward","function","for","`","SinePositionalEncoding","`",".","Args",":","mask","(","Tensor",")",":","ByteTensor","mask",".","Non-zero","values","representing","ignored","positions",",","while","zero","values","means","valid","positions","for","this","image",".","Shape","[","bs",",","h",",","w","]",".","input","(","Tensor",",","optional",")",":","Input","image\/feature","Tensor",".","Shape","[","bs",",","c",",","h",",","w","]","Returns",":","pos","(","Tensor",")",":","Returned","position","embedding","with","shape","[","bs",",","num_feats","*","2",",","h",",","w","]","."]
code: def forward(
      self, mask: Tensor, input: Optional[Tensor] = None
  ) -> Tensor:
      """Forward function for `SinePositionalEncoding`.
  
      Args:
          mask (Tensor): ByteTensor mask. Non-zero values representing
              ignored positions, while zero values means valid positions
              for this image. Shape [bs, h, w].
          input (Tensor, optional): Input image/feature Tensor.
              Shape [bs, c, h, w]
  
      Returns:
          pos (Tensor): Returned position embedding with shape
              [bs, num_feats*2, h, w].
      """
      assert not (mask is None and input is None)
  
      if mask is not None:
          B, H, W = mask.size()
          device = mask.device
          # For convenience of exporting to ONNX,
          # it's required to convert
          # `masks` from bool to int.
          mask = mask.to(torch.int)
          not_mask = 1 - mask  # logical_not
          y_embed = not_mask.cumsum(1, dtype=torch.float32)
          x_embed = not_mask.cumsum(2, dtype=torch.float32)
      else:
          # single image or batch image with no padding
          B, _, H, W = input.shape
          device = input.device
          x_embed = torch.arange(
              1, W + 1, dtype=torch.float32, device=device
          )
          x_embed = x_embed.view(1, 1, -1).repeat(B, H, 1)
          y_embed = torch.arange(
              1, H + 1, dtype=torch.float32, device=device
          )
          y_embed = y_embed.view(1, -1, 1).repeat(B, 1, W)
      if self.normalize:
          y_embed = (
              (y_embed + self.offset)
              / (y_embed[:, -1:, :] + self.eps)
              * self.scale
          )
          x_embed = (
              (x_embed + self.offset)
              / (x_embed[:, :, -1:] + self.eps)
              * self.scale
          )
      dim_t = torch.arange(
          self.num_feats, dtype=torch.float32, device=device
      )
      dim_t = self.temperature ** (2 * (dim_t // 2) / self.num_feats)
      pos_x = x_embed[:, :, :, None] / dim_t
      pos_y = y_embed[:, :, :, None] / dim_t
      # use `view` instead of `flatten` for dynamically exporting to ONNX
  
      pos_x = torch.stack(
          (pos_x[:, :, :, 0::2].sin(), pos_x[:, :, :, 1::2].cos()),
          dim=4,
      ).view(B, H, W, -1)
      pos_y = torch.stack(
          (pos_y[:, :, :, 0::2].sin(), pos_y[:, :, :, 1::2].cos()),
          dim=4,
      ).view(B, H, W, -1)
      pos = torch.cat((pos_y, pos_x), dim=3).permute(0, 3, 1, 2)
      return pos
  
imports: import math
  from typing import Optional
  import torch
  import torch.nn
  from mmengine.model import BaseModule
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.utils import MultiConfig, OptMultiConfig
label_desc: Use image node_id 2 for calling the SinePositionalEncoding obj's underlying member method code with example usage: obj.forward(mask, input) and returns: pos