class_docstr: Implements feed-forward networks (FFNs) with residual connection.
  
  Args:
      embed_dims (int): The feature dimension. Same as
          `MultiheadAttention`.
      feedforward_channels (int): The hidden dimension of FFNs.
      num_fcs (int): The number of fully-connected layers in FFNs.
      act_cfg (dict): The activation config for FFNs.
      dropout (float): Probability of an element to be zeroed. Default 0.0.
class_docstr_tok: ["Implements","feed-forward","networks","(","FFNs",")","with","residual","connection",".","Args",":","embed_dims","(","int",")",":","The","feature","dimension",".","Same","as","`","MultiheadAttention","`",".","feedforward_channels","(","int",")",":","The","hidden","dimension","of","FFNs",".","num_fcs","(","int",")",":","The","number","of","fully-connected","layers","in","FFNs",".","act_cfg","(","dict",")",":","The","activation","config","for","FFNs",".","dropout","(","float",")",":","Probability","of","an","element","to","be","zeroed",".","Default","0.0","."]
code: def __init__(
      self,
      embed_dims,
      feedforward_channels,
      num_fcs=2,
      act_cfg=dict(type="ReLU", inplace=True),
      dropout=0.0,
      add_residual=True,
  ):
      super(FFN, self).__init__()
      assert num_fcs >= 2, (
          "num_fcs should be no less " f"than 2. got {num_fcs}."
      )
      self.embed_dims = embed_dims
      self.feedforward_channels = feedforward_channels
      self.num_fcs = num_fcs
      self.act_cfg = act_cfg
      self.dropout = dropout
      self.activate = build_activation_layer(act_cfg)
  
      layers = nn.ModuleList()
      in_channels = embed_dims
      for _ in range(num_fcs - 1):
          layers.append(
              nn.Sequential(
                  Linear(in_channels, feedforward_channels),
                  self.activate,
                  nn.Dropout(dropout),
              )
          )
          in_channels = feedforward_channels
      layers.append(Linear(feedforward_channels, embed_dims))
      self.layers = nn.Sequential(*layers)
      self.dropout = nn.Dropout(dropout)
      self.add_residual = add_residual
  
imports: import torch
  import torch.nn
  from mmcv.cnn import Linear, build_activation_layer, build_norm_layer, xavier_init
  from .builder import TRANSFORMER
label_desc: Use image node_id 1 to create a new FFN object from inherited base classes: nn with example: obj = FFN(embed_dims, feedforward_channels, num_fcs, act_cfg, dropout, add_residual)