code: def __init__(
      self,
      cnf: InvertedResidualConfig,
      norm_layer: Callable[..., nn.Module],
  ):
      super(InvertedResidual, self).__init__()
  
      if cnf.stride not in [1, 2]:
          raise ValueError("illegal stride value.")
  
      self.use_res_connect = (
          cnf.stride == 1 and cnf.input_c == cnf.out_c
      )
  
      layers = OrderedDict()
      activation_layer = nn.SiLU  # alias Swish
  
      # expand
      if cnf.expanded_c != cnf.input_c:
          layers.update(
              {
                  "expand_conv": ConvBNActivation(
                      cnf.input_c,
                      cnf.expanded_c,
                      kernel_size=1,
                      norm_layer=norm_layer,
                      activation_layer=activation_layer,
                  )
              }
          )
  
      # depthwise
      layers.update(
          {
              "dwconv": ConvBNActivation(
                  cnf.expanded_c,
                  cnf.expanded_c,
                  kernel_size=cnf.kernel,
                  stride=cnf.stride,
                  groups=cnf.expanded_c,
                  norm_layer=norm_layer,
                  activation_layer=activation_layer,
              )
          }
      )
  
      if cnf.use_se:
          layers.update(
              {"se": SqueezeExcitation(cnf.input_c, cnf.expanded_c)}
          )
  
      # project
      layers.update(
          {
              "project_conv": ConvBNActivation(
                  cnf.expanded_c,
                  cnf.out_c,
                  kernel_size=1,
                  norm_layer=norm_layer,
                  activation_layer=nn.Identity,
              )
          }
      )
  
      self.block = nn.Sequential(layers)
      self.out_channels = cnf.out_c
      self.is_strided = cnf.stride > 1
  
      # 只有在使用shortcut连接时才使用dropout层
      if self.use_res_connect and cnf.drop_rate > 0:
          self.dropout = DropPath(cnf.drop_rate)
      else:
          self.dropout = nn.Identity()
  
imports: import math
  import copy
  from functools import partial
  from collections import OrderedDict
  from typing import Optional, Callable
  import torch
  import torch.nn
  from torch import Tensor
  from torch.nn import functional
label_desc: Use image node_id 1 to create a new InvertedResidual object from inherited base classes: nn with example: obj = InvertedResidual(cnf, norm_layer)