text: import torch.nn as nn
  
  from typing import Optional
  from .decoder import DeepLabV3Decoder
  from ..base import SegmentationModel, SegmentationHead, ClassificationHead
  from ..encoders import get_encoder
  
  
  class DeepLabV3(SegmentationModel):
      """DeepLabV3_ implemetation from "Rethinking Atrous Convolution for Semantic Image Segmentation"
      Args:
          encoder_name: name of classification model (without last dense layers) used as feature
                  extractor to build segmentation model.
          encoder_depth: number of stages used in decoder, larger depth - more features are generated.
              e.g. for depth=3 encoder will generate list of features with following spatial shapes
              [(H,W), (H/2, W/2), (H/4, W/4), (H/8, W/8)], so in general the deepest feature will have
              spatial resolution (H/(2^depth), W/(2^depth)]
          encoder_weights: one of ``None`` (random initialization), ``imagenet`` (pre-training on ImageNet).
          decoder_channels: a number of convolution filters in ASPP module (default 256).
          in_channels: number of input channels for model, default is 3.
          classes: a number of classes for output (output shape - ``(batch, classes, h, w)``).
          activation (str, callable): activation function used in ``.predict(x)`` method for inference.
              One of [``sigmoid``, ``softmax2d``, callable, None]
          upsampling: optional, final upsampling factor
              (default is 8 to preserve input -> output spatial shape identity)
          aux_params: if specified model will have additional classification auxiliary output
              build on top of encoder, supported params:
                  - classes (int): number of classes
                  - pooling (str): one of 'max', 'avg'. Default is 'avg'.
                  - dropout (float): dropout factor in [0, 1)
                  - activation (str): activation function to apply "sigmoid"/"softmax" (could be None to return logits)
      Returns:
          ``torch.nn.Module``: **DeepLabV3**
      .. _DeeplabV3:
          https://arxiv.org/abs/1706.05587
      """
          
      def __init__(
              self,
              encoder_name: str = "resnet34",
              encoder_depth: int = 5,
              encoder_weights: Optional[str] = "imagenet",
              decoder_channels: int = 256,
              in_channels: int = 3,
              classes: int = 1,
              activation: Optional[str] = None,
              upsampling: int = 8,
              aux_params: Optional[dict] = None,
      ):
          super().__init__()
  
          self.encoder = get_encoder(
              encoder_name,
              in_channels=in_channels,
              depth=encoder_depth,
              weights=encoder_weights,
          )
          self.encoder.make_dilated(
              stage_list=[4, 5],
              dilation_list=[2, 4]
          )
  
          self.decoder = DeepLabV3Decoder(
              in_channels=self.encoder.out_channels[-1],
              out_channels=decoder_channels,
          )
  
          self.segmentation_head = SegmentationHead(
              in_channels=self.decoder.out_channels,
              out_channels=classes,
              activation=activation,
              kernel_size=1,
              upsampling=upsampling,
          )
  
          if aux_params is not None:
              self.classification_head = ClassificationHead(
                  in_channels=self.encoder.out_channels[-1], **aux_params
              )
          else:
              self.classification_head = None
  