Tasks#
Tasks provide a convenient abstraction over the training of a model for a specific downstream task.
They encapsulate the model, optimizer, metrics, loss as well as training, validation and testing steps.
The task expects to be passed a model_factory
, to which the model_args
arguments are passed to instantiate the model that will be trained.
The models produced by this model factory should output ModelOutput
instances and conform to the Model ABC.
Tasks are best leveraged using config files, where they are specified in the model
section under class_path
. You can check out some examples of config files here.
Below are the details of the tasks currently implemented in TerraTorch (Pixelwise Regression, Semantic Segmentation and Classification).
terratorch.tasks.SemanticSegmentationTask
#
Bases: TerraTorchTask
Semantic Segmentation Task that accepts models from a range of sources.
This class is analog in functionality to class SemanticSegmentationTask defined by torchgeo. However, it has some important differences: - Accepts the specification of a model factory - Logs metrics per class - Does not have any callbacks by default (TorchGeo tasks do early stopping by default) - Allows the setting of optimizers in the constructor - Allows to evaluate on multiple test dataloaders
Source code in terratorch/tasks/segmentation_tasks.py
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 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 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 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
|
__init__(model_args, model_factory=None, model=None, loss='ce', aux_heads=None, aux_loss=None, class_weights=None, ignore_index=None, lr=0.001, optimizer=None, optimizer_hparams=None, scheduler=None, scheduler_hparams=None, freeze_backbone=False, freeze_decoder=False, freeze_head=False, plot_on_val=10, class_names=None, tiled_inference_parameters=None, test_dataloaders_names=None, lr_overrides=None, output_on_inference='prediction', output_most_probable=True, path_to_record_metrics=None, tiled_inference_on_testing=False, tiled_inference_on_validation=False)
#
Constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_args
|
Dict
|
Arguments passed to the model factory. |
required |
model_factory
|
str
|
ModelFactory class to be used to instantiate the model. Is ignored when model is provided. |
None
|
model
|
Module
|
Custom model. |
None
|
loss
|
str
|
Loss to be used. Currently, supports 'ce', 'jaccard' or 'focal' loss. Defaults to "ce". |
'ce'
|
aux_loss
|
dict[str, float] | None
|
Auxiliary loss weights. Should be a dictionary where the key is the name given to the loss and the value is the weight to be applied to that loss. The name of the loss should match the key in the dictionary output by the model's forward method containing that output. Defaults to None. |
None
|
class_weights
|
Union[list[float], None]
|
List of class weights to be applied to the loss. |
None
|
class_weights
|
list[float] | None
|
List of class weights to be applied to the loss. Defaults to None. |
None
|
ignore_index
|
int | None
|
Label to ignore in the loss computation. Defaults to None. |
None
|
lr
|
float
|
Learning rate to be used. Defaults to 0.001. |
0.001
|
optimizer
|
str | None
|
Name of optimizer class from torch.optim to be used. |
None
|
optimizer_hparams
|
dict | None
|
Parameters to be passed for instantiation of the optimizer. Overriden by config / cli specification through LightningCLI. |
None
|
scheduler
|
str
|
Name of Torch scheduler class from torch.optim.lr_scheduler to be used (e.g. ReduceLROnPlateau). Defaults to None. Overriden by config / cli specification through LightningCLI. |
None
|
scheduler_hparams
|
dict | None
|
Parameters to be passed for instantiation of the scheduler. Overriden by config / cli specification through LightningCLI. |
None
|
freeze_backbone
|
bool
|
Whether to freeze the backbone. Defaults to False. |
False
|
freeze_decoder
|
bool
|
Whether to freeze the decoder. Defaults to False. |
False
|
freeze_head
|
bool
|
Whether to freeze the segmentation head. Defaults to False. |
False
|
plot_on_val
|
bool | int
|
Whether to plot visualizations on validation. |
10
|
class_names
|
list[str] | None
|
List of class names passed to metrics for better naming. Defaults to numeric ordering. |
None
|
tiled_inference_parameters
|
dict | None
|
Inference parameters used to determine if inference is done on the whole image or through tiling. |
None
|
test_dataloaders_names
|
list[str] | None
|
Names used to differentiate metrics when multiple dataloaders are returned by test_dataloader in the datamodule. Defaults to None, which assumes only one test dataloader is used. |
None
|
lr_overrides
|
dict[str, float] | None
|
Dictionary to override the default lr in specific parameters. The key should be a substring of the parameter names (it will check the substring is contained in the parameter name) and the value should be the new lr. Defaults to None. |
None
|
output_on_inference
|
str | list[str]
|
A string or a list defining the kind of output to be saved to file during the inference, for example, it can be "prediction", to save just the most probable class, or ["prediction", "probabilities"] to save both prediction and probabilities. |
'prediction'
|
output_most_probable
|
bool
|
A boolean to define if the prediction step will output just the most probable logit or all of them.
This argument has been deprecated and will be replaced with |
True
|
tiled_inference_on_testing
|
bool
|
A boolean to define if tiled inference will be used during the test step. |
False
|
tiled_inference_on_validation
|
bool
|
A boolean to define if tiled inference will be used during the val step. |
False
|
tiled_inference_on_testing
|
bool
|
A boolean to define if tiled inference will be used when full inference fails during the test step. |
False
|
path_to_record_metrics
|
str
|
A path to save the file containing the metrics log. |
None
|
Source code in terratorch/tasks/segmentation_tasks.py
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 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 |
|
configure_losses()
#
Initialize the loss criterion.
Raises:
Type | Description |
---|---|
ValueError
|
If loss is invalid. |
Source code in terratorch/tasks/segmentation_tasks.py
configure_metrics()
#
Initialize the performance metrics.
Source code in terratorch/tasks/segmentation_tasks.py
predict_step(batch, batch_idx, dataloader_idx=0)
#
Compute the predicted class probabilities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
Any
|
The output of your DataLoader. |
required |
batch_idx
|
int
|
Integer displaying index of this batch. |
required |
dataloader_idx
|
int
|
Index of the current dataloader. |
0
|
Returns:
Type | Description |
---|---|
Tensor
|
Output predicted probabilities. |
Source code in terratorch/tasks/segmentation_tasks.py
test_step(batch, batch_idx, dataloader_idx=0)
#
Compute the test loss and additional metrics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
Any
|
The output of your DataLoader. |
required |
batch_idx
|
int
|
Integer displaying index of this batch. |
required |
dataloader_idx
|
int
|
Index of the current dataloader. |
0
|
Source code in terratorch/tasks/segmentation_tasks.py
training_step(batch, batch_idx, dataloader_idx=0)
#
Compute the train loss and additional metrics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
Any
|
The output of your DataLoader. |
required |
batch_idx
|
int
|
Integer displaying index of this batch. |
required |
dataloader_idx
|
int
|
Index of the current dataloader. |
0
|
Source code in terratorch/tasks/segmentation_tasks.py
validation_step(batch, batch_idx, dataloader_idx=0)
#
Compute the validation loss and additional metrics. Args: batch: The output of your DataLoader. batch_idx: Integer displaying index of this batch. dataloader_idx: Index of the current dataloader.
Source code in terratorch/tasks/segmentation_tasks.py
terratorch.tasks.PixelwiseRegressionTask
#
Bases: TerraTorchTask
Pixelwise Regression Task that accepts models from a range of sources.
This class is analog in functionality to PixelwiseRegressionTask defined by torchgeo. However, it has some important differences: - Accepts the specification of a model factory - Logs metrics per class - Does not have any callbacks by default (TorchGeo tasks do early stopping by default) - Allows the setting of optimizers in the constructor - Allows to evaluate on multiple test dataloaders
Source code in terratorch/tasks/regression_tasks.py
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 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 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
|
__init__(model_args, model_factory=None, model=None, loss='mse', aux_heads=None, aux_loss=None, class_weights=None, ignore_index=None, lr=0.001, optimizer=None, optimizer_hparams=None, scheduler=None, scheduler_hparams=None, freeze_backbone=False, freeze_decoder=False, freeze_head=False, plot_on_val=10, tiled_inference_parameters=None, test_dataloaders_names=None, lr_overrides=None, tiled_inference_on_testing=False, tiled_inference_on_validation=False, path_to_record_metrics=None)
#
Constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_args
|
Dict
|
Arguments passed to the model factory. |
required |
model_factory
|
str
|
Name of ModelFactory class to be used to instantiate the model. Is ignored when model is provided. |
None
|
model
|
Module
|
Custom model. |
None
|
loss
|
str
|
Loss to be used. Currently, supports 'mse', 'rmse', 'mae' or 'huber' loss. Defaults to "mse". |
'mse'
|
aux_loss
|
dict[str, float] | None
|
Auxiliary loss weights. Should be a dictionary where the key is the name given to the loss and the value is the weight to be applied to that loss. The name of the loss should match the key in the dictionary output by the model's forward method containing that output. Defaults to None. |
None
|
class_weights
|
list[float] | None
|
List of class weights to be applied to the loss. Defaults to None. |
None
|
ignore_index
|
int | None
|
Label to ignore in the loss computation. Defaults to None. |
None
|
lr
|
float
|
Learning rate to be used. Defaults to 0.001. |
0.001
|
optimizer
|
str | None
|
Name of optimizer class from torch.optim to be used. If None, will use Adam. Defaults to None. Overriden by config / cli specification through LightningCLI. |
None
|
optimizer_hparams
|
dict | None
|
Parameters to be passed for instantiation of the optimizer. Overriden by config / cli specification through LightningCLI. |
None
|
scheduler
|
str
|
Name of Torch scheduler class from torch.optim.lr_scheduler to be used (e.g. ReduceLROnPlateau). Defaults to None. Overriden by config / cli specification through LightningCLI. |
None
|
scheduler_hparams
|
dict | None
|
Parameters to be passed for instantiation of the scheduler. Overriden by config / cli specification through LightningCLI. |
None
|
freeze_backbone
|
bool
|
Whether to freeze the backbone. Defaults to False. |
False
|
freeze_decoder
|
bool
|
Whether to freeze the decoder. Defaults to False. |
False
|
freeze_head
|
bool
|
Whether to freeze the segmentation head. Defaults to False. |
False
|
plot_on_val
|
bool | int
|
Whether to plot visualizations on validation. If true, log every epoch. Defaults to 10. If int, will plot every plot_on_val epochs. |
10
|
tiled_inference_parameters
|
dict | None
|
Inference parameters used to determine if inference is done on the whole image or through tiling. |
None
|
test_dataloaders_names
|
list[str] | None
|
Names used to differentiate metrics when multiple dataloaders are returned by test_dataloader in the datamodule. Defaults to None, which assumes only one test dataloader is used. |
None
|
lr_overrides
|
dict[str, float] | None
|
Dictionary to override the default lr in specific parameters. The key should be a substring of the parameter names (it will check the substring is contained in the parameter name)and the value should be the new lr. Defaults to None. |
None
|
tiled_inference_on_testing
|
bool
|
A boolean to define if tiled inference will be used during the test step. |
False
|
tiled_inference_on_validation
|
bool
|
A boolean to define if tiled inference will be used during the val step. |
False
|
path_to_record_metrics
|
str
|
A path to save the file containing the metrics log. |
None
|
Source code in terratorch/tasks/regression_tasks.py
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 231 232 233 234 235 236 237 238 239 240 241 |
|
configure_losses()
#
Initialize the loss criterion.
Raises:
Type | Description |
---|---|
ValueError
|
If loss is invalid. |
Source code in terratorch/tasks/regression_tasks.py
configure_metrics()
#
Initialize the performance metrics.
Source code in terratorch/tasks/regression_tasks.py
predict_step(batch, batch_idx, dataloader_idx=0)
#
Compute the predicted class probabilities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
Any
|
The output of your DataLoader. |
required |
batch_idx
|
int
|
Integer displaying index of this batch. |
required |
dataloader_idx
|
int
|
Index of the current dataloader. |
0
|
Returns:
Type | Description |
---|---|
Tensor
|
Output predicted probabilities. |
Source code in terratorch/tasks/regression_tasks.py
test_step(batch, batch_idx, dataloader_idx=0)
#
Compute the test loss and additional metrics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
Any
|
The output of your DataLoader. |
required |
batch_idx
|
int
|
Integer displaying index of this batch. |
required |
dataloader_idx
|
int
|
Index of the current dataloader. |
0
|
Source code in terratorch/tasks/regression_tasks.py
training_step(batch, batch_idx, dataloader_idx=0)
#
Compute the train loss and additional metrics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
Any
|
The output of your DataLoader. |
required |
batch_idx
|
int
|
Integer displaying index of this batch. |
required |
dataloader_idx
|
int
|
Index of the current dataloader. |
0
|
Source code in terratorch/tasks/regression_tasks.py
validation_step(batch, batch_idx, dataloader_idx=0)
#
Compute the validation loss and additional metrics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
Any
|
The output of your DataLoader. |
required |
batch_idx
|
int
|
Integer displaying index of this batch. |
required |
dataloader_idx
|
int
|
Index of the current dataloader. |
0
|
Source code in terratorch/tasks/regression_tasks.py
terratorch.tasks.ClassificationTask
#
Bases: TerraTorchTask
Classification Task that accepts models from a range of sources.
This class is analog in functionality to the class ClassificationTask defined by torchgeo. However, it has some important differences: - Accepts the specification of a model factory - Logs metrics per class - Does not have any callbacks by default (TorchGeo tasks do early stopping by default) - Allows the setting of optimizers in the constructor - It provides mIoU with both Micro and Macro averaging - Allows to evaluate on multiple test dataloaders
.. note:: * 'Micro' averaging suits overall performance evaluation but may not reflect minority class accuracy. * 'Macro' averaging gives equal weight to each class, useful for balanced performance assessment across imbalanced classes.
Source code in terratorch/tasks/classification_tasks.py
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 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 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 |
|
__init__(model_args, model_factory=None, model=None, loss='ce', aux_heads=None, aux_loss=None, class_weights=None, ignore_index=None, lr=0.001, optimizer=None, optimizer_hparams=None, scheduler=None, scheduler_hparams=None, freeze_backbone=False, freeze_decoder=False, freeze_head=False, class_names=None, test_dataloaders_names=None, lr_overrides=None, path_to_record_metrics=None)
#
Constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_args
|
Dict
|
Arguments passed to the model factory. |
required |
model_factory
|
str
|
ModelFactory class to be used to instantiate the model. Is ignored when model is provided. |
None
|
model
|
Module
|
Custom model. |
None
|
loss
|
str
|
Loss to be used. Currently, supports 'ce', 'jaccard' or 'focal' loss. Defaults to "ce". |
'ce'
|
aux_loss
|
dict[str, float] | None
|
Auxiliary loss weights. Should be a dictionary where the key is the name given to the loss and the value is the weight to be applied to that loss. The name of the loss should match the key in the dictionary output by the model's forward method containing that output. Defaults to None. |
None
|
class_weights
|
Union[list[float], None]
|
List of class weights to be applied to the loss. |
None
|
class_weights
|
list[float] | None
|
List of class weights to be applied to the loss. Defaults to None. |
None
|
ignore_index
|
int | None
|
Label to ignore in the loss computation. Defaults to None. |
None
|
lr
|
float
|
Learning rate to be used. Defaults to 0.001. |
0.001
|
optimizer
|
str | None
|
Name of optimizer class from torch.optim to be used. If None, will use Adam. Defaults to None. Overriden by config / cli specification through LightningCLI. |
None
|
optimizer_hparams
|
dict | None
|
Parameters to be passed for instantiation of the optimizer. Overriden by config / cli specification through LightningCLI. |
None
|
scheduler
|
str
|
Name of Torch scheduler class from torch.optim.lr_scheduler to be used (e.g. ReduceLROnPlateau). Defaults to None. Overriden by config / cli specification through LightningCLI. |
None
|
scheduler_hparams
|
dict | None
|
Parameters to be passed for instantiation of the scheduler. Overriden by config / cli specification through LightningCLI. |
None
|
freeze_backbone
|
bool
|
Whether to freeze the backbone. Defaults to False. |
False
|
freeze_decoder
|
bool
|
Whether to freeze the decoder. Defaults to False. |
False
|
freeze_head
|
bool
|
Whether to freeze the segmentation_head. Defaults to False. |
False
|
class_names
|
list[str] | None
|
List of class names passed to metrics for better naming. Defaults to numeric ordering. |
None
|
test_dataloaders_names
|
list[str] | None
|
Names used to differentiate metrics when multiple dataloaders are returned by test_dataloader in the datamodule. Defaults to None, which assumes only one test dataloader is used. |
None
|
lr_overrides
|
dict[str, float] | None
|
Dictionary to override the default lr in specific parameters. The key should be a substring of the parameter names (it will check the substring is contained in the parameter name)and the value should be the new lr. Defaults to None. |
None
|
path_to_record_metrics
|
str
|
A path to save the file containing the metrics log. |
None
|
Source code in terratorch/tasks/classification_tasks.py
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 |
|
configure_losses()
#
Initialize the loss criterion.
Raises:
Type | Description |
---|---|
ValueError
|
If loss is invalid. |
Source code in terratorch/tasks/classification_tasks.py
configure_metrics()
#
Initialize the performance metrics.
Source code in terratorch/tasks/classification_tasks.py
predict_step(batch, batch_idx, dataloader_idx=0)
#
Compute the predicted class probabilities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
object
|
The output of your DataLoader. |
required |
batch_idx
|
int
|
Integer displaying index of this batch. |
required |
dataloader_idx
|
int
|
Index of the current dataloader. |
0
|
Returns:
Type | Description |
---|---|
Tensor
|
Output predicted probabilities. |
Source code in terratorch/tasks/classification_tasks.py
test_step(batch, batch_idx, dataloader_idx=0)
#
Compute the test loss and additional metrics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
object
|
The output of your DataLoader. |
required |
batch_idx
|
int
|
Integer displaying index of this batch. |
required |
dataloader_idx
|
int
|
Index of the current dataloader. |
0
|
Source code in terratorch/tasks/classification_tasks.py
training_step(batch, batch_idx, dataloader_idx=0)
#
Compute the train loss and additional metrics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
object
|
The output of your DataLoader. |
required |
batch_idx
|
int
|
Integer displaying index of this batch. |
required |
dataloader_idx
|
int
|
Index of the current dataloader. |
0
|
Source code in terratorch/tasks/classification_tasks.py
validation_step(batch, batch_idx, dataloader_idx=0)
#
Compute the validation loss and additional metrics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
object
|
The output of your DataLoader. |
required |
batch_idx
|
int
|
Integer displaying index of this batch. |
required |
dataloader_idx
|
int
|
Index of the current dataloader. |
0
|
Source code in terratorch/tasks/classification_tasks.py
terratorch.tasks.MultiLabelClassificationTask
#
Bases: ClassificationTask
Source code in terratorch/tasks/multilabel_classification_tasks.py
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 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 |
|
configure_metrics()
#
Initialize the performance metrics.
Source code in terratorch/tasks/multilabel_classification_tasks.py
predict_step(batch, batch_idx, dataloader_idx=0)
#
Compute the predicted class probabilities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
object
|
The output of your DataLoader. |
required |
batch_idx
|
int
|
Integer displaying index of this batch. |
required |
dataloader_idx
|
int
|
Index of the current dataloader. |
0
|
Returns:
Type | Description |
---|---|
Tensor
|
Output predicted probabilities. |
Source code in terratorch/tasks/multilabel_classification_tasks.py
terratorch.tasks.ObjectDetectionTask
#
Bases: BaseTask
Source code in terratorch/tasks/object_detection_task.py
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 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 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 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
|
__init__(model_factory, model_args, lr=0.001, optimizer=None, optimizer_hparams=None, scheduler=None, scheduler_hparams=None, freeze_backbone=False, freeze_decoder=False, class_names=None, iou_threshold=0.5, score_threshold=0.5)
#
Initialize a new ObjectDetectionTask instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_factory
|
str
|
Name of the model factory to use. |
required |
model_args
|
dict
|
Arguments for the model factory. |
required |
lr
|
float
|
Learning rate for optimizer. Defaults to 0.001. |
0.001
|
optimizer
|
str | None
|
Name of the optimizer to use. Defaults to None. |
None
|
optimizer_hparams
|
dict | None
|
Hyperparameters for the optimizer. Defaults to None. |
None
|
scheduler
|
str | None
|
Name of the scheduler to use. Defaults to None. |
None
|
scheduler_hparams
|
dict | None
|
Hyperparameters for the scheduler. Defaults to None. |
None
|
freeze_backbone
|
bool
|
Freeze the backbone network to fine-tune the detection head. Defaults to False. |
False
|
freeze_decoder
|
bool
|
Freeze the decoder network to fine-tune the detection head. Defaults to False. |
False
|
class_names
|
list[str] | None
|
List of class names. Defaults to None. |
None
|
iou_threshold
|
float
|
Intersection over union threshold for evaluation. Defaults to 0.5. |
0.5
|
score_threshold
|
float
|
Score threshold for evaluation. Defaults to 0.5. |
0.5
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in terratorch/tasks/object_detection_task.py
apply_nms_batch(y_hat, batch_size)
#
It applies nms to a batch predictions of the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y_hat
|
Any
|
List of predictions dictionaries. |
required |
iou_threshold
|
IoU threshold for evaluation. |
required | |
score_threshold
|
Score threshold for evaluation. |
required |
Returns: fintered predictions for a batch after applying nms batch
Source code in terratorch/tasks/object_detection_task.py
apply_nms_sample(y_hat, iou_threshold=0.5, score_threshold=0.5)
#
It applies nms to a sample predictions of the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y_hat
|
Predictions dictionary. |
required | |
iou_threshold
|
IoU threshold for evaluation. |
0.5
|
|
score_threshold
|
Score threshold for evaluation. |
0.5
|
Returns: fintered predictions for a sample after applying nms batch
Source code in terratorch/tasks/object_detection_task.py
configure_metrics()
#
Configure metrics for the task.
Source code in terratorch/tasks/object_detection_task.py
configure_models()
#
It instantiates the model and freezes/unfreezes the backbone and decoder networks.
Source code in terratorch/tasks/object_detection_task.py
configure_optimizers()
#
Configure optimiser for the task.
Source code in terratorch/tasks/object_detection_task.py
predict_step(batch, batch_idx, dataloader_idx=0)
#
Output predicted bounding boxes, classes and masks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
Any
|
The output of your DataLoader. |
required |
batch_idx
|
int
|
Integer displaying index of this batch. |
required |
dataloader_idx
|
int
|
Index of the current dataloader. |
0
|
Returns:
Type | Description |
---|---|
list[dict[str, Tensor]]
|
Output predicted bounding boxes, classes and masks. |
Source code in terratorch/tasks/object_detection_task.py
reformat_batch(batch, batch_size)
#
Reformat batch to calculate loss and metrics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
Any
|
The output of your DataLoader. |
required |
batch_size
|
int
|
Size of your batch |
required |
Returns: Reformated batch
Source code in terratorch/tasks/object_detection_task.py
test_step(batch, batch_idx, dataloader_idx=0)
#
Compute the test metrics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
Any
|
The output of your DataLoader. |
required |
batch_idx
|
int
|
Integer displaying index of this batch. |
required |
dataloader_idx
|
int
|
Index of the current dataloader. |
0
|
Source code in terratorch/tasks/object_detection_task.py
training_step(batch, batch_idx, dataloader_idx=0)
#
Compute the training loss.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
Any
|
The output of your DataLoader. |
required |
batch_idx
|
int
|
Integer displaying index of this batch. |
required |
dataloader_idx
|
int
|
Index of the current dataloader. |
0
|
Returns:
Type | Description |
---|---|
Tensor
|
The loss dictionary. |
Source code in terratorch/tasks/object_detection_task.py
validation_step(batch, batch_idx, dataloader_idx=0)
#
Compute the validation metrics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
Any
|
The output of your DataLoader. |
required |
batch_idx
|
int
|
Integer displaying index of this batch. |
required |
dataloader_idx
|
int
|
Index of the current dataloader. |
0
|