docstr: Implementation of a standard densely connected network (DenseNet).
  
  Contains the following attachable blocks:
      block{block_idx}-{idx}: This is the output of each dense block,
          indexed by the block index and the index of the dense layer
      transition-{idx}: This is the output of the transition layers
      trunk_output: The final output of the `DenseNet`. This is
          where a `fully_connected` head is normally attached.
  
  Args:
      small_input: set to `True` for 32x32 sized image inputs.
      final_bn_relu: set to `False` to exclude the final batchnorm and
          ReLU layers. These settings are useful when training Siamese
          networks.
      use_se: Enable squeeze and excitation
      se_reduction_ratio: The reduction ratio to apply in the excitation
          stage. Only used if `use_se` is `True`.
docstr_tok: ["Implementation","of","a","standard","densely","connected","network","(","DenseNet",")",".","Contains","the","following","attachable","blocks",":","block","{","block_idx","}","-","{","idx","}",":","This","is","the","output","of","each","dense","block",",","indexed","by","the","block","index","and","the","index","of","the","dense","layer","transition-","{","idx","}",":","This","is","the","output","of","the","transition","layers","trunk_output",":","The","final","output","of","the","`","DenseNet","`",".","This","is","where","a","`","fully_connected","`","head","is","normally","attached",".","Args",":","small_input",":","set","to","`","True","`","for","32x32","sized","image","inputs",".","final_bn_relu",":","set","to","`","False","`","to","exclude","the","final","batchnorm","and","ReLU","layers",".","These","settings","are","useful","when","training","Siamese","networks",".","use_se",":","Enable","squeeze","and","excitation","se_reduction_ratio",":","The","reduction","ratio","to","apply","in","the","excitation","stage",".","Only","used","if","`","use_se","`","is","`","True","`","."]
code: def __init__(
      self,
      num_blocks,
      num_classes,
      init_planes,
      growth_rate,
      expansion,
      small_input,
      final_bn_relu,
      use_se=False,
      se_reduction_ratio=16,
  ):
      """
      Implementation of a standard densely connected network (DenseNet).
  
      Contains the following attachable blocks:
          block{block_idx}-{idx}: This is the output of each dense block,
              indexed by the block index and the index of the dense layer
          transition-{idx}: This is the output of the transition layers
          trunk_output: The final output of the `DenseNet`. This is
              where a `fully_connected` head is normally attached.
  
      Args:
          small_input: set to `True` for 32x32 sized image inputs.
          final_bn_relu: set to `False` to exclude the final batchnorm and
              ReLU layers. These settings are useful when training Siamese
              networks.
          use_se: Enable squeeze and excitation
          se_reduction_ratio: The reduction ratio to apply in the excitation
              stage. Only used if `use_se` is `True`.
      """
      super().__init__()
  
      # assertions:
      assert isinstance(num_blocks, Sequence)
      assert all(is_pos_int(b) for b in num_blocks)
      assert num_classes is None or is_pos_int(num_classes)
      assert is_pos_int(init_planes)
      assert is_pos_int(growth_rate)
      assert is_pos_int(expansion)
      assert type(small_input) == bool
  
      # initial convolutional block:
      self._num_classes = num_classes
      self.num_blocks = num_blocks
      self.small_input = small_input
      if self.small_input:
          self.initial_block = nn.Sequential(
              nn.Conv2d(
                  3,
                  init_planes,
                  kernel_size=3,
                  stride=1,
                  padding=1,
                  bias=False,
              ),
              nn.BatchNorm2d(init_planes),
              nn.ReLU(inplace=INPLACE),
          )
      else:
          self.initial_block = nn.Sequential(
              nn.Conv2d(
                  3,
                  init_planes,
                  kernel_size=7,
                  stride=2,
                  padding=3,
                  bias=False,
              ),
              nn.BatchNorm2d(init_planes),
              nn.ReLU(inplace=INPLACE),
              nn.MaxPool2d(kernel_size=3, stride=2, padding=1),
          )
      # loop over spatial resolutions:
      num_planes = init_planes
      blocks = nn.Sequential()
      for idx, num_layers in enumerate(num_blocks):
          # add dense block
          block = self._make_dense_block(
              num_layers,
              num_planes,
              idx,
              growth_rate=growth_rate,
              expansion=expansion,
              use_se=use_se,
              se_reduction_ratio=se_reduction_ratio,
          )
          blocks.add_module(f"block_{idx}", block)
          num_planes = num_planes + num_layers * growth_rate
  
          # add transition layer:
          if idx != len(num_blocks) - 1:
              trans = _Transition(num_planes, num_planes // 2)
              blocks.add_module(f"transition-{idx}", trans)
              num_planes = num_planes // 2
  
      blocks.add_module(
          "trunk_output",
          self._make_trunk_output_block(num_planes, final_bn_relu),
      )
  
      self.features = blocks
  
      # initialize weights of convolutional and batchnorm layers:
      for m in self.modules():
          if isinstance(m, nn.Conv2d):
              n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
              m.weight.data.normal_(0, math.sqrt(2.0 / n))
          elif isinstance(m, nn.BatchNorm2d):
              m.weight.data.fill_(1)
              m.bias.data.zero_()
          elif isinstance(m, nn.Linear):
              m.bias.data.zero_()
  
imports: import math
  from collections import OrderedDict
  from typing import Any, Dict, Sequence
  import torch
  import torch.nn
  from classy_vision.generic.util import is_pos_int
  from .None import register_model
  from .classy_model import ClassyModel
  from .squeeze_and_excitation_layer import SqueezeAndExcitationLayer
label_desc: Use image node_id 1 to create a new DenseNet object from inherited base classes: ClassyModel with example: obj = DenseNet(num_blocks, num_classes, init_planes, growth_rate, expansion, small_input, final_bn_relu, use_se, se_reduction_ratio)