Skip to contents

Define a DeepLabv3+-style encoder-ASPP-decoder architecture for geospatial semantic segmentation.

Usage

defineDLab(
  inChn = 3,
  nCls = 3,
  actFunc = "relu",
  encBlocks = "double",
  decBlock = "double",
  useRes = FALSE,
  enChn = c(16, 32, 64, 128),
  btnChn = 256,
  lowLevelChn = 48,
  dcChn = 256,
  dilRates = c(6, 12, 18),
  dilChn = c(256, 256, 256, 256),
  negative_slope = 0.01,
  expRatio = 4
)

Arguments

inChn

Number of channels, bands, or predictor variables in the input image or raster data. Default is 3.

nCls

Number of classes being differentiated. For a binary classification, this can be either 1 or 2. If 2, the problem is treated as a multiclass problem, and a multiclass loss metric should be used. Default is 3.

actFunc

Defines activation function to use throughout the network for the non-ConvNeXt blocks. "relu" = rectified linear unit (ReLU); "lrelu" = leaky ReLU; "swish" = swish; "gelu" = GELU. Default is "relu".

encBlocks

Block implementation for the four encoder blocks. Either a single value applied to all four blocks or a length-4 character vector, with entries "double", "dws", or "convnext". Default is "double".

decBlock

Block implementation for the decoder fusion block: "double", "dws", or "convnext". Default is "double".

useRes

TRUE or FALSE. Whether to include residual connections in the "double" and "dws" encoder and decoder blocks. Has no effect on "convnext" blocks (always residual). Default is FALSE.

enChn

Vector of 4 integers defining the number of output feature maps for each of the four encoder blocks. Default is 16, 32, 64, and 128.

btnChn

Number of output feature maps from the ASPP module. Default is 256.

lowLevelChn

Number of channels to project the low-level encoder features (from the third encoder block at stride 4) to before fusing with the upsampled ASPP output. Default is 48.

dcChn

Number of output feature maps from the decoder convolution block. Default is 256.

dilRates

Vector of 3 values specifying the dilation rates used in the ASPP module. Default is 6, 12, and 18.

dilChn

Vector of 4 values specifying the number of channels to produce at each dilation rate within the ASPP module. Default is 256 for each.

negative_slope

If actFunc = "lrelu", specifies the negative slope term. Default is 0.01.

expRatio

Inverted-bottleneck expansion ratio for "convnext" blocks. Default is 4.

Value

DLab model instance as torch nn_module

Details

Define an architecture with a custom 4-block encoder, an atrous spatial pyramid pooling (ASPP) module, and a lightweight decoder that fuses high-level ASPP features with low-level encoder features. The decoder uses a single skip connection from the third encoder block (stride 4) and upsamples the ASPP output (stride 16) 4x before fusion, then upsamples 4x again to reach the original resolution. This is only loosely based on DeepLabv3+: the encoder is a plain convolutional network downsampled with max pooling rather than an atrous backbone, so the name is deliberately generic.

Each of the four encoder blocks and the single decoder block can independently use one of three block implementations via encBlocks and decBlock:

  • "double" - the standard double 3x3 convolution block (default). Becomes a residual double convolution block when useRes = TRUE.

  • "dws" - a double convolution block whose second 3x3 convolution is replaced with a depthwise separable convolution (dwsDoubleConv). Becomes a residual variant (dwsDoubleConvR) when useRes = TRUE.

  • "convnext" - a ConvNeXt-style block (doubleConvBlkCNX); always residual and always GELU, so useRes and actFunc do not affect these blocks.

The overall encoder-ASPP-decoder structure is inspired by:

Chen, L.C., Zhu, Y., Papandreou, G., Schroff, F. and Adam, H., 2018. Encoder-decoder with atrous separable convolution for semantic image segmentation. In Proceedings of the European Conference on Computer Vision (ECCV) (pp. 801-818).