Decoder#
Tip
The IdentityDecoder
is typically used for classification tasks while the UNetDecoder
is suited for pixel-wise segmentation or regression tasks.
terratorch.models.decoders.identity_decoder.IdentityDecoder
#
Bases: Module
Identity decoder. Useful to pass the feature straight to the head.
Source code in terratorch/models/decoders/identity_decoder.py
__init__(embed_dim, out_index=-1)
#
Constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embed_dim
|
int
|
Input embedding dimension |
required |
out_index
|
int
|
Index of the input list to take.. Defaults to -1. |
-1
|
Source code in terratorch/models/decoders/identity_decoder.py
terratorch.models.decoders.unet_decoder.UNetDecoder
#
Bases: Module
UNetDecoder. Wrapper around UNetDecoder from segmentation_models_pytorch to avoid ignoring the first layer.
Source code in terratorch/models/decoders/unet_decoder.py
__init__(embed_dim, channels, use_batchnorm=True, attention_type=None)
#
Constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embed_dim
|
list[int]
|
Input embedding dimension for each input. |
required |
channels
|
list[int]
|
Channels used in the decoder. |
required |
use_batchnorm
|
bool
|
Whether to use batchnorm. Defaults to True. |
True
|
attention_type
|
str | None
|
Attention type to use. Defaults to None |
None
|
Source code in terratorch/models/decoders/unet_decoder.py
terratorch.models.decoders.upernet_decoder.UperNetDecoder
#
Bases: Module
UperNetDecoder. Adapted from MMSegmentation.
Source code in terratorch/models/decoders/upernet_decoder.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
|
__init__(embed_dim, pool_scales=(1, 2, 3, 6), channels=256, align_corners=True, scale_modules=False)
#
Constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embed_dim
|
list[int]
|
Input embedding dimension for each input. |
required |
pool_scales
|
tuple[int]
|
Pooling scales used in Pooling Pyramid Module applied on the last feature. Default: (1, 2, 3, 6). |
(1, 2, 3, 6)
|
channels
|
int
|
Channels used in the decoder. Defaults to 256. |
256
|
align_corners
|
bool
|
Wheter to align corners in rescaling. Defaults to True. |
True
|
scale_modules
|
bool
|
Whether to apply scale modules to the inputs. Needed for plain ViT. Defaults to False. |
False
|
Source code in terratorch/models/decoders/upernet_decoder.py
forward(inputs)
#
Forward function for feature maps before classifying each pixel with Args: inputs (list[Tensor]): List of multi-level img features.
Returns:
Name | Type | Description |
---|---|---|
feats |
Tensor
|
A tensor of shape (batch_size, self.channels, H, W) which is feature map for last layer of decoder head. |
Source code in terratorch/models/decoders/upernet_decoder.py
psp_forward(inputs)
#
Forward function of PSP module.
Source code in terratorch/models/decoders/upernet_decoder.py
terratorch.models.decoders.fcn_decoder.FCNDecoder
#
Bases: Module
Fully Convolutional Decoder
Source code in terratorch/models/decoders/fcn_decoder.py
__init__(embed_dim, channels=256, num_convs=4, in_index=-1)
#
Constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embed_dim
|
_type_
|
Input embedding dimension |
required |
channels
|
int
|
Number of channels for each conv. Defaults to 256. |
256
|
num_convs
|
int
|
Number of convs. Defaults to 4. |
4
|
in_index
|
int
|
Index of the input list to take. Defaults to -1. |
-1
|
Source code in terratorch/models/decoders/fcn_decoder.py
terratorch.models.decoders.linear_decoder.LinearDecoder
#
Bases: Module
A linear decoder using a transposed convolution layer for upsampling.
Source code in terratorch/models/decoders/linear_decoder.py
__init__(embed_dim, num_classes, upsampling_size, in_index=-1)
#
Constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embed_dim
|
list[int]
|
A list of embedding dimensions for different feature maps. |
required |
num_classes
|
int
|
Number of output classes. |
required |
upsampling_size
|
int
|
Kernel and stride size for transposed convolution. |
required |
in_index
|
int
|
Index of the input feature map to use. Defaults to -1." |
-1
|
Source code in terratorch/models/decoders/linear_decoder.py
terratorch.models.decoders.mlp_decoder.MLPDecoder
#
Bases: Module
Identity decoder. Useful to pass the feature straight to the head.
Source code in terratorch/models/decoders/mlp_decoder.py
__init__(embed_dim, channels=100, out_dim=100, activation='ReLU', out_index=-1)
#
Constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embed_dim
|
int
|
Input embedding dimension |
required |
out_index
|
int
|
Index of the input list to take.. Defaults to -1. |
-1
|
Source code in terratorch/models/decoders/mlp_decoder.py
terratorch.models.decoders.aspp_head
#
ASPPHead
#
Bases: Module
Rethinking Atrous Convolution for Semantic Image Segmentation.
This head is the implementation of DeepLabV3
<https://arxiv.org/abs/1706.05587>
_.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dilations
|
tuple[int]
|
Dilation rates for ASPP module. Default: (1, 6, 12, 18). |
(1, 6, 12, 18)
|
Source code in terratorch/models/decoders/aspp_head.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
ASPPSegmentationHead
#
Bases: ASPPHead
Rethinking Atrous Convolution for Semantic Image Segmentation.
This head is the implementation of DeepLabV3
<https://arxiv.org/abs/1706.05587>
_.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dilations
|
tuple[int]
|
Dilation rates for ASPP module. Default: (1, 6, 12, 18). |
(1, 6, 12, 18)
|
Source code in terratorch/models/decoders/aspp_head.py
segmentation_head(features)
#
ASPPRegressionHead
#
Bases: ASPPHead
Rethinking Atrous Convolution for regression.
This head is the implementation of DeepLabV3
<https://arxiv.org/abs/1706.05587>
_.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dilations
|
tuple[int]
|
Dilation rates for ASPP module. Default: (1, 6, 12, 18). |
(1, 6, 12, 18)
|