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
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
__init__(channel_list, remove_cls_token=True, effective_time_dim=1, h=None, temporal_inputs=False)
#
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
|
temporal_inputs
|
bool
|
Used for embedding generation workflows, flag to handle temporal data correctly. |
False
|
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.