rslearn.train.model_context¶
model_context ¶
Data classes to provide various context to models.
RasterImage
dataclass
¶
A raster image is a torch.tensor containing the images and their associated timestamps.
Source code in rslearn/train/model_context.py
dim ¶
single_ts_to_chw_tensor ¶
Single timestep models expect single timestep inputs.
This function (1) checks this raster image only has 1 timestep and (2) returns the tensor for that (single) timestep (going from CTHW to CHW).
Source code in rslearn/train/model_context.py
get_hw_tensor ¶
Get a 2D HW tensor from a single-channel, single-timestep RasterImage.
This function checks that C=1 and T=1, then returns the HW tensor. Useful for per-pixel labels like segmentation masks.
Source code in rslearn/train/model_context.py
from_raster_array
classmethod
¶
from_raster_array(ra: RasterArray) -> RasterImage
Create a RasterImage from a numpy-based RasterArray.
Converts the numpy CTHW array to a torch tensor and copies timestamps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ra
|
RasterArray
|
the source RasterArray. |
required |
Returns:
| Type | Description |
|---|---|
RasterImage
|
a new RasterImage with the same data. |
Source code in rslearn/train/model_context.py
SampleMetadata
dataclass
¶
Metadata pertaining to an example.
Source code in rslearn/train/model_context.py
ModelContext
dataclass
¶
Context to pass to all model components.
Source code in rslearn/train/model_context.py
ModelOutput
dataclass
¶
The output from the Predictor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outputs
|
Iterable[Any]
|
output compatible with the configured Task. |
required |
loss_dict
|
dict[str, Tensor]
|
map from loss names to scalar tensors. |
required |
metadata
|
dict[str, Any]
|
arbitrary dict that can be used to store other outputs. |
(lambda: {})()
|