rslearn.models.task_embedding¶
task_embedding ¶
Task embedding modules.
PositionalEncoding ¶
Bases: Module
Simple sinusoidal positional encoding for the task embedding. From torch docs.
Source code in rslearn/models/task_embedding.py
forward ¶
Apply positional encoding to the input tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Tensor, shape |
required |
BaseTaskEmbedding ¶
Bases: Module
Base class for task embedding modules.
Source code in rslearn/models/task_embedding.py
register_tasks ¶
Register the tasks.
This must happen post-init so that we can dynamically determine the tasks to use, so it doesn't have to be specified in the config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_names
|
list[str]
|
The names of the tasks. |
required |
Source code in rslearn/models/task_embedding.py
compute_embeds ¶
Compute the task-specific embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
list[tensor]
|
The encoder features. |
required |
inputs
|
list[dict[str, Any]]
|
The inputs to the model. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
The task-specific embeddings. |
Source code in rslearn/models/task_embedding.py
TaskChannelEmbedding ¶
Bases: BaseTaskEmbedding
Registers task-specific 'tokens', i.e. embeddings.
Each embedding is learned per-channel and copied over the full spatial dimensions. Optionally, add a spatial sinusoidal positional embedding to the task embedding.
Source code in rslearn/models/task_embedding.py
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 | |
register_tasks ¶
Register the tasks.
This must happen post-init so that we can dynamically determine the tasks to use, so it doesn't have to be specified in the config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_names
|
list[str]
|
The names of the tasks. |
required |
Source code in rslearn/models/task_embedding.py
compute_embeds ¶
Compute the task-specific embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
list[dict[str, Any]]
|
The inputs to the model. |
required |
features
|
list[tensor]
|
computed encoder features |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
The task-specific embeddings, shape (B, T, C), T = HW |
Tensor
|
The embeddings are repeated over the spatial dimensions, and optionally |
Tensor
|
a sinusoidal positional embedding is added. |
Source code in rslearn/models/task_embedding.py
forward ¶
forward(features: list[tensor], inputs: list[dict[str, Any]], embeds: Tensor | None = None) -> list[tensor]
Compute and apply task-specific embeddings to encoder features.
Optionally, add a spatial sinusoidal positional embedding to the task embedding. Otherwise, the task embedding is repeated over the spatial dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
list[tensor]
|
The encoder features, a 1-list of B x C x H x W features. |
required |
inputs
|
list[dict[str, Any]]
|
The inputs to the model. |
required |
embeds
|
Tensor | None
|
Already-computed task embeddings, if provided, skip the computation. |
None
|
Returns:
| Type | Description |
|---|---|
list[tensor]
|
The encoder features with the task-specific embeddings added. |
Source code in rslearn/models/task_embedding.py
TaskMHAEmbedding ¶
Bases: TaskChannelEmbedding
Multi-headed cross-attention over the spatial dimensions.
The task embedding is the query and the features are the key and value. We copy the task embedding over the spatial dimensions, and optionally add a sinusoidal positional embedding before the MHA layer.
Source code in rslearn/models/task_embedding.py
register_tasks ¶
Register the tasks.
This must happen post-init so that we can dynamically determine the tasks to use, so it doesn't have to be specified in the config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_names
|
list[str]
|
The names of the tasks. |
required |
Source code in rslearn/models/task_embedding.py
forward ¶
forward(features: list[tensor], inputs: list[dict[str, Any]], embeds: Tensor | None = None) -> list[tensor]
Compute and apply task-specific embeddings to encoder features.
Also apply the MHA layer across the spatial dimension, with the task embedding as the query and the features as the key and value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
list[tensor]
|
The encoder features, a 1-list of B x C x H x W features. |
required |
inputs
|
list[dict[str, Any]]
|
The inputs to the model. |
required |
embeds
|
Tensor | None
|
Already-computed task embeddings, if provided, skip the computation. |
None
|
Returns:
| Type | Description |
|---|---|
list[tensor]
|
The encoder features with the task-specific embeddings added. |