docstr: MobileNet V2 main class
  
  Args:
      num_classes (int): Number of classes
      width_mult (float): Width multiplier - adjusts number of channels in each layer by this amount
      inverted_residual_setting: Network structure
      round_nearest (int): Round the number of channels in each layer to be a multiple of this number
      Set to 1 to turn off rounding
      block: Module specifying inverted residual building block for mobilenet
      norm_layer: Module specifying the normalization layer to use
      dropout (float): The droupout probability
docstr_tok: ["MobileNet","V2","main","class","Args",":","num_classes","(","int",")",":","Number","of","classes","width_mult","(","float",")",":","Width","multiplier","-","adjusts","number","of","channels","in","each","layer","by","this","amount","inverted_residual_setting",":","Network","structure","round_nearest","(","int",")",":","Round","the","number","of","channels","in","each","layer","to","be","a","multiple","of","this","number","Set","to","1","to","turn","off","rounding","block",":","Module","specifying","inverted","residual","building","block","for","mobilenet","norm_layer",":","Module","specifying","the","normalization","layer","to","use","dropout","(","float",")",":","The","droupout","probability"]
code: def __init__(
      self,
      num_classes: int = 1000,
      width_mult: float = 1.0,
      inverted_residual_setting: Optional[List[List[int]]] = None,
      round_nearest: int = 8,
      block: Optional[Callable[..., nn.Module]] = None,
      norm_layer: Optional[Callable[..., nn.Module]] = None,
      dropout: float = 0.2,
  ) -> None:
      """
      MobileNet V2 main class
  
      Args:
          num_classes (int): Number of classes
          width_mult (float): Width multiplier - adjusts number of channels in each layer by this amount
          inverted_residual_setting: Network structure
          round_nearest (int): Round the number of channels in each layer to be a multiple of this number
          Set to 1 to turn off rounding
          block: Module specifying inverted residual building block for mobilenet
          norm_layer: Module specifying the normalization layer to use
          dropout (float): The droupout probability
  
      """
      super().__init__()
      _log_api_usage_once(self)
  
      if block is None:
          block = InvertedResidual
  
      if norm_layer is None:
          norm_layer = nn.BatchNorm2d
  
      input_channel = 32
      last_channel = 1280
  
      if inverted_residual_setting is None:
          inverted_residual_setting = [
              # t, c, n, s
              [1, 16, 1, 1],
              [6, 24, 2, 2],
              [6, 32, 3, 2],
              [6, 64, 4, 2],
              [6, 96, 3, 1],
              [6, 160, 3, 2],
              [6, 320, 1, 1],
          ]
  
      # only check the first element, assuming user knows t,c,n,s are required
      if (
          len(inverted_residual_setting) == 0
          or len(inverted_residual_setting[0]) != 4
      ):
          raise ValueError(
              f"inverted_residual_setting should be non-empty or a 4-element list, got {inverted_residual_setting}"
          )
  
      # building first layer
      input_channel = _make_divisible(
          input_channel * width_mult, round_nearest
      )
      self.last_channel = _make_divisible(
          last_channel * max(1.0, width_mult), round_nearest
      )
      features: List[nn.Module] = [
          Conv2dNormActivation(
              3,
              input_channel,
              stride=2,
              norm_layer=norm_layer,
              activation_layer=nn.ReLU6,
          )
      ]
      # building inverted residual blocks
      for t, c, n, s in inverted_residual_setting:
          output_channel = _make_divisible(
              c * width_mult, round_nearest
          )
          for i in range(n):
              stride = s if i == 0 else 1
              features.append(
                  block(
                      input_channel,
                      output_channel,
                      stride,
                      expand_ratio=t,
                      norm_layer=norm_layer,
                  )
              )
              input_channel = output_channel
      # building last several layers
      features.append(
          Conv2dNormActivation(
              input_channel,
              self.last_channel,
              kernel_size=1,
              norm_layer=norm_layer,
              activation_layer=nn.ReLU6,
          )
      )
      # make it nn.Sequential
      self.features = nn.Sequential(*features)
  
      # building classifier
      self.classifier = nn.Sequential(
          nn.Dropout(p=dropout),
          nn.Linear(self.last_channel, num_classes),
      )
  
      # weight initialization
      for m in self.modules():
          if isinstance(m, nn.Conv2d):
              nn.init.kaiming_normal_(m.weight, mode="fan_out")
              if m.bias is not None:
                  nn.init.zeros_(m.bias)
          elif isinstance(m, (nn.BatchNorm2d, nn.GroupNorm)):
              nn.init.ones_(m.weight)
              nn.init.zeros_(m.bias)
          elif isinstance(m, nn.Linear):
              nn.init.normal_(m.weight, 0, 0.01)
              nn.init.zeros_(m.bias)
  
imports: from functools import partial
  from typing import Any, Callable, List, Optional
  import torch
  from torch import nn, Tensor
  from ..ops.misc import Conv2dNormActivation
  from ..transforms._presets import ImageClassification
  from ..utils import _log_api_usage_once
  from ._api import register_model, Weights, WeightsEnum
  from ._meta import _IMAGENET_CATEGORIES
  from ._utils import _make_divisible, _ovewrite_named_param, handle_legacy_interface
label_desc: Use image node_id 1 to create a new MobileNetV2 object from inherited base classes: nn with example: obj = MobileNetV2(num_classes, width_mult, inverted_residual_setting, round_nearest, block, norm_layer, dropout)