class_docstr: This class defines the `EfficientNet architecture <https://arxiv.org/abs/1905.11946>`_
class_docstr_tok: ["This","class","defines","the","`","EfficientNet","architecture","<","https",":","\/\/arxiv.org\/abs\/1905.11946",">","`","_"]
code: def __init__(
      self,
      opts,
      *args,
      **kwargs: Any,
  ) -> None:
      super().__init__(opts, *args, **kwargs)
  
      classifier_dropout = getattr(
          opts, "model.classification.classifier_dropout"
      )
  
      network_config = get_configuration(opts)
      last_channels = network_config["last_channels"]
      total_layers = network_config["total_layers"]
      num_classes = getattr(
          opts, "model.classification.n_classes", 1000
      )
      stochastic_depth_prob = getattr(
          opts,
          "model.classification.efficientnet.stochastic_depth_prob",
          0.2,
      )
  
      # building first layer
      image_channels = 3
      in_channels = network_config["layer_1"][0].in_channels
      self.conv_1 = ConvLayer2d(
          opts=opts,
          in_channels=image_channels,
          out_channels=in_channels,
          kernel_size=3,
          stride=2,
          use_norm=True,
          use_act=True,
      )
  
      self.model_conf_dict["conv1"] = {
          "in": image_channels,
          "out": in_channels,
      }
  
      # building inverted residual blocks
      prev_layers_cnt = 0  # counts the number of layers added so far
      for layer_name in [
          "layer_1",
          "layer_2",
          "layer_3",
          "layer_4",
          "layer_5",
      ]:
          dilation = False
          if layer_name == "layer_4":
              dilation = self.dilate_l4
          elif layer_name == "layer_5":
              dilation = self.dilate_l5
          layer, prev_layers_cnt = self._make_layer(
              opts=opts,
              block_config=network_config[layer_name],
              stochastic_depth_prob=stochastic_depth_prob,
              prev_layers_cnt=prev_layers_cnt,
              total_layers=total_layers,
              dilate=dilation,
          )
  
          setattr(self, layer_name, layer)
          # we have saved mappings without underscore in layer_name, so removing it
          self.model_conf_dict[layer_name.replace("_", "")] = {
              "in": network_config[layer_name][0].in_channels,
              "out": network_config[layer_name][-1].out_channels,
          }
  
      # building last several layers
      in_channels = network_config["layer_5"][-1].out_channels
      out_channels = last_channels
      self.conv_1x1_exp = ConvLayer2d(
          opts=opts,
          in_channels=in_channels,
          out_channels=out_channels,
          kernel_size=1,
          use_act=True,
          use_norm=True,
      )
  
      self.model_conf_dict["exp_before_cls"] = {
          "in": in_channels,
          "out": out_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, inplace=True),
          )
      self.classifier.add_module(
          name="classifier_fc",
          module=LinearLayer(
              in_features=out_channels,
              out_features=num_classes,
              bias=True,
          ),
      )
  
file_path: ml-cvnets/cvnets/models/classification/efficientnet.py
imports: import argparse
  from typing import Any, Optional, Tuple
  from torch import nn
  from cvnets.layers import ConvLayer2d, Dropout, GlobalPool, LinearLayer
  from cvnets.models import MODEL_REGISTRY
  from cvnets.models.classification.base_image_encoder import BaseImageEncoder
  from cvnets.models.classification.config.efficientnet import EfficientNetBlockConfig, get_configuration
  from cvnets.modules import EfficientNetBlock
label_desc: Use image node_id 1 to create a new EfficientNet object from inherited base classes: BaseImageEncoder with example: obj = EfficientNet(opts)