rslearn.train.transforms.transform¶
transform ¶
Transform base class.
Transform ¶
Bases: Module
An rslearn transform.
Provides helper functions for subclasses to select input and target keys and to transform them.
Attributes:
| Name | Type | Description |
|---|---|---|
skip_missing |
If True, selectors that don't exist in the input/target dicts will be silently skipped. Useful when working with optional inputs. |
Source code in rslearn/train/transforms/transform.py
apply_fn ¶
apply_fn(fn: Callable, input_dict: dict[str, Any], target_dict: dict[str, Any], selectors: list[str], **kwargs: dict[str, Any]) -> None
Apply the specified function on the selectors in input/target dicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable
|
the function to apply |
required |
input_dict
|
dict[str, Any]
|
the input dict |
required |
target_dict
|
dict[str, Any]
|
the target dict |
required |
selectors
|
list[str]
|
the selectors to apply the function on. |
required |
kwargs
|
dict[str, Any]
|
additional arguments to pass to the function |
{}
|
Source code in rslearn/train/transforms/transform.py
Identity ¶
Bases: Transform
Identity transform.
Source code in rslearn/train/transforms/transform.py
forward ¶
forward(input_dict: dict[str, Any], target_dict: dict[str, Any]) -> tuple[dict[str, Any], dict[str, Any]]
Simply returns the provided input_dict and target_dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dict
|
dict[str, Any]
|
input dict. |
required |
target_dict
|
dict[str, Any]
|
target_dict. |
required |
Returns:
| Type | Description |
|---|---|
tuple[dict[str, Any], dict[str, Any]]
|
unchanged (input_dict, target_dict) |
Source code in rslearn/train/transforms/transform.py
get_dict_and_subselector ¶
get_dict_and_subselector(input_dict: dict[str, Any], target_dict: dict[str, Any], selector: str) -> tuple[dict[str, Any], str]
Determine whether to use input or target dict, and the sub-selector.
For example, if the selector is "input/x", then we use input dict and the sub-selector is "x".
If neither input/ nor target/ prefixes are present, then we assume it is for input dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dict
|
dict[str, Any]
|
the input dict |
required |
target_dict
|
dict[str, Any]
|
the target dict |
required |
selector
|
str
|
the full selector configured by the user |
required |
Returns:
| Type | Description |
|---|---|
tuple[dict[str, Any], str]
|
a tuple (referenced dict, sub-selector string) |
Source code in rslearn/train/transforms/transform.py
read_selector ¶
Read the item referenced by the selector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dict
|
dict[str, Any]
|
the input dict |
required |
target_dict
|
dict[str, Any]
|
the target dict |
required |
selector
|
str
|
the selector specifying the item to read |
required |
Returns:
| Type | Description |
|---|---|
Any
|
the item specified by the selector |
Source code in rslearn/train/transforms/transform.py
write_selector ¶
write_selector(input_dict: dict[str, Any], target_dict: dict[str, Any], selector: str, v: Any) -> None
Write the item to the specified selector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dict
|
dict[str, Any]
|
the input dict |
required |
target_dict
|
dict[str, Any]
|
the target dict |
required |
selector
|
str
|
the selector specifying the item to write |
required |
v
|
Any
|
the value to write |
required |
Source code in rslearn/train/transforms/transform.py
selector_exists ¶
Check if the specified selector exists in the dicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dict
|
dict[str, Any]
|
the input dict |
required |
target_dict
|
dict[str, Any]
|
the target dict |
required |
selector
|
str
|
the selector specifying the item to check |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the selector exists, False otherwise |