Necks#
Necks reshape the output of an encoder into a format suitable for the decoder. By combining different necks, you can combine any backbone with any decoder.
terratorch.models.necks.Neck
#
Bases: ABC
, Module
Base class for Neck
A neck must must implement self.process_channel_list
which returns the new channel list.
Source code in terratorch/models/necks.py
terratorch.models.necks.SelectIndices
#
Bases: Neck
Source code in terratorch/models/necks.py
__init__(channel_list, indices)
#
Select indices from the embedding list
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indices
|
list[int]
|
list of indices to select. |
required |
terratorch.models.necks.ReshapeTokensToImage
#
Bases: Neck
Source code in terratorch/models/necks.py
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 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
__init__(channel_list, remove_cls_token=True, effective_time_dim=1, h=None)
#
Reshape output of transformer encoder so it can be passed to a conv net.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
remove_cls_token
|
bool
|
Whether to remove the cls token from the first position. Defaults to True. |
True
|
effective_time_dim
|
int
|
The effective temporal dimension the transformer processes.
For a ViT, his will be given by |
1
|
h
|
int | None
|
You can choose a value for the height of the reshaped image. The embedding size will be implicitly discovered from it. |
None
|
Source code in terratorch/models/necks.py
collapse_dims(x)
#
When the encoder output has more than 3 dimensions, is necessary to reshape it.
Source code in terratorch/models/necks.py
terratorch.models.necks.InterpolateToPyramidal
#
Bases: Neck
Source code in terratorch/models/necks.py
__init__(channel_list, scale_factor=2, mode='nearest')
#
Spatially interpolate embeddings so that embedding[i - 1] is scale_factor times larger than embedding[i]
Useful to make non-pyramidal backbones compatible with hierarachical ones Args: scale_factor (int): Amount to scale embeddings by each layer. Defaults to 2. mode (str): Interpolation mode to be passed to torch.nn.functional.interpolate. Defaults to 'nearest'.
Source code in terratorch/models/necks.py
terratorch.models.necks.LearnedInterpolateToPyramidal
#
Bases: Neck
Use learned convolutions to transform the output of a non-pyramidal encoder into pyramidal ones
Always requires exactly 4 embeddings
Source code in terratorch/models/necks.py
terratorch.models.necks.PermuteDims
#
Bases: Neck
Source code in terratorch/models/necks.py
__init__(channel_list, new_order)
#
Permute dimensions of each element in the embedding list
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_order
|
list[int]
|
list of indices to be passed to tensor.permute() |
required |
Source code in terratorch/models/necks.py
terratorch.models.necks.MaxpoolToPyramidal
#
Bases: Neck
Source code in terratorch/models/necks.py
__init__(channel_list, kernel_size=2)
#
Spatially downsample embeddings so that embedding[i - 1] is scale_factor times smaller than embedding[i]
Useful to make non-pyramidal backbones compatible with hierarachical ones Args: kernel_size (int). Base kernel size to use for maxpool. Defaults to 2.
Source code in terratorch/models/necks.py
terratorch.models.necks.AddBottleneckLayer
#
Bases: Neck
Add a layer that reduces the channel dimension of the final embedding by half, and concatenates it
Useful for compatibility with some smp decoders.