class_docstr: This class implements the inverted residual block, as described in `MobileNetv2 <https://arxiv.org/abs/1801.04381>`_ paper
  
  Args:
      in_channels (int): :math:`C_{in}` from an expected input of size :math:`(N, C_{in}, H_{in}, W_{in})`
      out_channels (int): :math:`C_{out}` from an expected output of size :math:`(N, C_{out}, H_{out}, W_{out)`
      stride (int): Use convolutions with a stride. Default: 1
      expand_ratio (Union[int, float]): Expand the input channels by this factor in depth-wise conv
      skip_connection (Optional[bool]): Use skip-connection. Default: True
  
  Shape:
      - Input: :math:`(N, C_{in}, H_{in}, W_{in})`
      - Output: :math:`(N, C_{out}, H_{out}, W_{out})`
  
  .. note::
      If `in_channels =! out_channels` and `stride > 1`, we set `skip_connection=False`
class_docstr_tok: ["This","class","implements","the","inverted","residual","block",",","as","described","in","`","MobileNetv2","<","https",":","\/\/arxiv.org\/abs\/1801.04381",">","`","_","paper","Args",":","in_channels","(","int",")",":",":","math",":","`","C_","{","in","}","`","from","an","expected","input","of","size",":","math",":","`","(","N",",","C_","{","in","}",",","H_","{","in","}",",","W_","{","in","}",")","`","out_channels","(","int",")",":",":","math",":","`","C_","{","out","}","`","from","an","expected","output","of","size",":","math",":","`","(","N",",","C_","{","out","}",",","H_","{","out","}",",","W_","{","out",")","`","stride","(","int",")",":","Use","convolutions","with","a","stride",".","Default",":","1","expand_ratio","(","Union","[","int",",","float","]",")",":","Expand","the","input","channels","by","this","factor","in","depth-wise","conv","skip_connection","(","Optional","[","bool","]",")",":","Use","skip-connection",".","Default",":","True","Shape",":","-","Input",":",":","math",":","`","(","N",",","C_","{","in","}",",","H_","{","in","}",",","W_","{","in","}",")","`","-","Output",":",":","math",":","`","(","N",",","C_","{","out","}",",","H_","{","out","}",",","W_","{","out","}",")","`","..","note",":",":","If","`","in_channels","=","!","out_channels","`","and","`","stride",">","1","`",",","we","set","`","skip_connection=False","`"]
code: def __init__(
      self,
      in_channels: int,
      out_channels: int,
      stride: int,
      expand_ratio: Union[int, float],
      skip_connection: Optional[bool] = True,
  ) -> None:
      assert stride in [1, 2]
      hidden_dim = make_divisible(
          int(round(in_channels * expand_ratio)), 8
      )
  
      super().__init__()
  
      block = nn.Sequential()
      if expand_ratio != 1:
          block.add_module(
              name="exp_1x1",
              module=ConvLayer(
                  in_channels=in_channels,
                  out_channels=hidden_dim,
                  kernel_size=1,
              ),
          )
  
      block.add_module(
          name="conv_3x3",
          module=ConvLayer(
              in_channels=hidden_dim,
              out_channels=hidden_dim,
              stride=stride,
              kernel_size=3,
              groups=hidden_dim,
          ),
      )
  
      block.add_module(
          name="red_1x1",
          module=ConvLayer(
              in_channels=hidden_dim,
              out_channels=out_channels,
              kernel_size=1,
              use_act=False,
              use_norm=True,
          ),
      )
  
      self.block = block
      self.in_channels = in_channels
      self.out_channels = out_channels
      self.exp = expand_ratio
      self.stride = stride
      self.use_res_connect = (
          self.stride == 1
          and in_channels == out_channels
          and skip_connection
      )
  
imports: from typing import Optional, Tuple, Union, Dict
  import math
  import torch
  import torch.nn
  from torch import Tensor
  from torch.nn import functional
  from transformer import TransformerEncoder
  from model_config import get_config
label_desc: Use image node_id 1 to create a new InvertedResidual object from inherited base classes: nn with example: obj = InvertedResidual(in_channels, out_channels, stride, expand_ratio, skip_connection)