rslearn.models.component¶
component ¶
Model component API.
FeatureExtractor ¶
Bases: Module, ABC
A feature extractor that performs initial processing of the inputs.
The FeatureExtractor is the first component in the encoders list for SingleTaskModel and MultiTaskModel.
Source code in rslearn/models/component.py
forward
abstractmethod
¶
forward(context: ModelContext) -> Any
Extract an initial intermediate from the model context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ModelContext
|
the model context. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
any intermediate to pass to downstream components. Oftentimes this is a FeatureMaps. |
Source code in rslearn/models/component.py
IntermediateComponent ¶
Bases: Module, ABC
An intermediate component in the model.
In SingleTaskModel and MultiTaskModel, modules after the first module in the encoders list are IntermediateComponents, as are modules before the last module in the decoders list(s).
Source code in rslearn/models/component.py
forward
abstractmethod
¶
forward(intermediates: Any, context: ModelContext) -> Any
Process the given intermediate into another intermediate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intermediates
|
Any
|
the output from the previous component (either a FeatureExtractor or another IntermediateComponent). |
required |
context
|
ModelContext
|
the model context. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
any intermediate to pass to downstream components. |
Source code in rslearn/models/component.py
Predictor ¶
Bases: Module, ABC
A predictor that computes task-specific outputs and a loss dict.
In SingleTaskModel and MultiTaskModel, the last module(s) in the decoders list(s) are Predictors.
Source code in rslearn/models/component.py
forward
abstractmethod
¶
forward(intermediates: Any, context: ModelContext, targets: list[dict[str, Tensor]] | None = None) -> ModelOutput
Compute task-specific outputs and loss dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intermediates
|
Any
|
the output from the previous component. |
required |
context
|
ModelContext
|
the model context. |
required |
targets
|
list[dict[str, Tensor]] | None
|
the training targets, or None during prediction. |
None
|
Returns:
| Type | Description |
|---|---|
ModelOutput
|
a tuple of the task-specific outputs (which should be compatible with the configured Task) and loss dict. The loss dict maps from a name for each loss to a scalar tensor. |
Source code in rslearn/models/component.py
FeatureMaps
dataclass
¶
An intermediate output type for multi-resolution feature maps.
Source code in rslearn/models/component.py
TokenFeatureMaps
dataclass
¶
An intermediate output type for multi-resolution BCHWN feature maps with a token dimension.
Unlike FeatureMaps, these include an additional dimension for unpooled tokens.