class_docstr: 将多个特征矩阵的值进行融合(add操作)
class_docstr_tok: ["\u5c06\u591a\u4e2a\u7279\u5f81\u77e9\u9635\u7684\u503c\u8fdb\u884c\u878d\u5408","(","add\u64cd\u4f5c",")"]
code: def forward(self, x, outputs):
      # Weights
      if self.weight:
          w = torch.sigmoid(self.w) * (
              2 / self.n
          )  # sigmoid weights (0-1)
          x = x * w[0]
  
      # Fusion
      nx = x.shape[1]  # input channels
      for i in range(self.n - 1):
          a = (
              outputs[self.layers[i]] * w[i + 1]
              if self.weight
              else outputs[self.layers[i]]
          )  # feature to add
          na = a.shape[1]  # feature channels
  
          # Adjust channels
          # 根据相加的两个特征矩阵的channel选择相加方式
          if nx == na:  # same shape 如果channel相同，直接相加
              x = x + a
          elif (
              nx > na
          ):  # slice input 如果channel不同，将channel多的特征矩阵砍掉部分channel保证相加的channel一致
              x[:, :na] = (
                  x[:, :na] + a
              )  # or a = nn.ZeroPad2d((0, 0, 0, 0, 0, dc))(a); x = x + a
          else:  # slice feature
              x = x + a[:, :nx]
  
      return x
  
imports: import torch.nn.functional
  from .utils import *
label_desc: Use image node_id 2 for calling the WeightedFeatureFusion obj's underlying member method code with example usage: obj.forward(x, outputs) and returns: x