class_docstr: This class defines the `MobileNet architecture <https://arxiv.org/abs/1704.04861>`_
class_docstr_tok: ["This","class","defines","the","`","MobileNet","architecture","<","https",":","\/\/arxiv.org\/abs\/1704.04861",">","`","_"]
code: def __init__(self, opts, *args, **kwargs) -> None:
      image_channels = 3
      num_classes = getattr(
          opts, "model.classification.n_classes", 1000
      )
      classifier_dropout = getattr(
          opts, "model.classification.classifier_dropout", 0.0
      )
      if classifier_dropout == 0.0:
          width_mult = getattr(
              opts,
              "model.classification.mobilenetv1.width_multiplier",
              1.0,
          )
          val = round(0.1 * width_mult, 3)
          classifier_dropout = bound_fn(
              min_val=0.0, max_val=0.1, value=val
          )
  
      super().__init__(opts, *args, **kwargs)
  
      cfg = get_configuration(opts=opts)
  
      self.model_conf_dict = dict()
      input_channels = cfg["conv1_out"]
      self.conv_1 = ConvLayer2d(
          opts=opts,
          in_channels=image_channels,
          out_channels=input_channels,
          kernel_size=3,
          stride=2,
          use_norm=True,
          use_act=True,
      )
      self.model_conf_dict["conv1"] = {
          "in": image_channels,
          "out": input_channels,
      }
  
      self.layer_1, out_channels = self._make_layer(
          opts=opts,
          mv1_config=cfg["layer1"],
          input_channel=input_channels,
      )
      self.model_conf_dict["layer1"] = {
          "in": input_channels,
          "out": out_channels,
      }
      input_channels = out_channels
  
      self.layer_2, out_channels = self._make_layer(
          opts=opts,
          mv1_config=cfg["layer2"],
          input_channel=input_channels,
      )
      self.model_conf_dict["layer2"] = {
          "in": input_channels,
          "out": out_channels,
      }
      input_channels = out_channels
  
      self.layer_3, out_channels = self._make_layer(
          opts=opts,
          mv1_config=cfg["layer3"],
          input_channel=input_channels,
      )
      self.model_conf_dict["layer3"] = {
          "in": input_channels,
          "out": out_channels,
      }
      input_channels = out_channels
  
      self.layer_4, out_channels = self._make_layer(
          opts=opts,
          mv1_config=cfg["layer4"],
          input_channel=input_channels,
          dilate=self.dilate_l4,
      )
  
      self.model_conf_dict["layer4"] = {
          "in": input_channels,
          "out": out_channels,
      }
      input_channels = out_channels
  
      self.layer_5, out_channels = self._make_layer(
          opts=opts,
          mv1_config=cfg["layer5"],
          input_channel=input_channels,
          dilate=self.dilate_l5,
      )
      self.model_conf_dict["layer5"] = {
          "in": input_channels,
          "out": out_channels,
      }
      input_channels = out_channels
  
      self.conv_1x1_exp = Identity()
      self.model_conf_dict["exp_before_cls"] = {
          "in": input_channels,
          "out": input_channels,
      }
  
      pool_type = getattr(opts, "model.layer.global_pool", "mean")
  
      self.classifier = nn.Sequential()
      self.classifier.add_module(
          name="global_pool",
          module=GlobalPool(pool_type=pool_type, keep_dim=False),
      )
      if 0.0 < classifier_dropout < 1.0:
          self.classifier.add_module(
              name="classifier_dropout",
              module=Dropout(p=classifier_dropout),
          )
      self.classifier.add_module(
          name="classifier_fc",
          module=LinearLayer(
              in_features=input_channels,
              out_features=num_classes,
              bias=True,
          ),
      )
  
      self.model_conf_dict["cls"] = {
          "in": input_channels,
          "out": num_classes,
      }
  
      # check model
      self.check_model()
  
      # weight initialization
      self.reset_parameters(opts=opts)
  
file_path: ml-cvnets/cvnets/models/classification/mobilenetv1.py
imports: import argparse
  from typing import Dict, List, Optional, Tuple
  from torch import nn
  from cvnets.layers import ConvLayer2d, Dropout, GlobalPool, Identity, LinearLayer, SeparableConv2d
  from cvnets.models import MODEL_REGISTRY
  from cvnets.models.classification.base_image_encoder import BaseImageEncoder
  from cvnets.models.classification.config.mobilenetv1 import get_configuration
  from utils.math_utils import bound_fn
label_desc: Use image node_id 1 to create a new MobileNetv1 object from inherited base classes: BaseImageEncoder with example: obj = MobileNetv1(opts)