code: def __init__(
      self,
      densenet: DenseNet,
      strides: List[int],
      channels: List[int],
      layers: List[int],
      first_avg_pool=False,
  ):
      if layers is None:
          layers = [1, 2, 3, 4]
  
      super().__init__(channels, strides, layers)
  
      def except_pool(block: nn.Module):
          del block.pool
          return block
  
      self.layer0 = nn.Sequential(
          OrderedDict(
              [
                  ("conv0", densenet.features.conv0),
                  ("bn0", densenet.features.norm0),
                  ("act0", densenet.features.relu0),
              ]
          )
      )
  
      self.avg_pool = nn.AvgPool2d(kernel_size=2, stride=2)
      self.pool0 = (
          self.avg_pool if first_avg_pool else densenet.features.pool0
      )
  
      self.layer1 = nn.Sequential(
          densenet.features.denseblock1,
          except_pool(densenet.features.transition1),
      )
  
      self.layer2 = nn.Sequential(
          densenet.features.denseblock2,
          except_pool(densenet.features.transition2),
      )
  
      self.layer3 = nn.Sequential(
          densenet.features.denseblock3,
          except_pool(densenet.features.transition3),
      )
  
      self.layer4 = nn.Sequential(densenet.features.denseblock4)
  
      self._output_strides = _take(strides, layers)
      self._output_filters = _take(channels, layers)
  
imports: from collections import OrderedDict
  from typing import List
  import torch
  from torch import nn
  from torchvision.models import densenet121, densenet161, densenet169, densenet201, DenseNet
  from .common import EncoderModule, _take, make_n_channel_input
label_desc: Use image node_id 1 to create a new DenseNetEncoder object from inherited base classes: EncoderModule with example: obj = DenseNetEncoder(densenet, strides, channels, layers, first_avg_pool)