| 13 | |
| 14 | |
| 15 | class AbstractTransform(ABC): |
| 16 | def __init__(self, exp_type: str): |
| 17 | input_output_dimensions = get_data_dims(exp_type=exp_type) |
| 18 | self.spatial_input_dim: Dict[str, int] = input_output_dimensions['spatial_dim'] |
| 19 | self.input_dim: Dict[str, int] = input_output_dimensions['input_dim'] |
| 20 | self.log = get_logger(__name__) |
| 21 | |
| 22 | @property |
| 23 | def output_dim(self) -> Union[int, Dict[str, int]]: |
| 24 | """ |
| 25 | Returns: |
| 26 | The number of feature dimensions that the transformed data will have. |
| 27 | If the transform returns an array, output_dim should be an int. |
| 28 | If the transform returns a dict of str -> array, output_dim should be a dict str -> int, that |
| 29 | described the number of features for each key in the transformed output. |
| 30 | |
| 31 | """ |
| 32 | return self._out_dim |
| 33 | |
| 34 | def transform(self, X: Dict[str, np.ndarray]) -> Any: |
| 35 | """ |
| 36 | How to transform dict |
| 37 | X = { |
| 38 | 'layer': layer_array, # shape (#layers, #layer-features) |
| 39 | 'levels': levels_array, # shape (#levels, #level-features) |
| 40 | 'globals': globals_array (#global-features,) |
| 41 | } |
| 42 | to the form the model will use/receive it in forward. |
| 43 | Implementation will be applied (with multi-processing) in the _get_item(.) method of the dataset |
| 44 | --> IMPORTANT: the arrays in X will *not* have the batch dimension! |
| 45 | """ |
| 46 | raise NotImplementedError |
| 47 | |
| 48 | def batched_transform(self, X: Dict[str, np.ndarray]) -> Any: |
| 49 | """ |
| 50 | How to transform dict |
| 51 | X = { |
| 52 | 'layer': layer_array, # shape (batch-size, #layers, #layer-features) |
| 53 | 'levels': levels_array, # shape (batch-size, #levels, #level-features) |
| 54 | 'globals': globals_array (batch-size, #global-features,) |
| 55 | } |
| 56 | to the form the model will use/receive it in forward. |
| 57 | """ |
| 58 | raise NotImplementedError |
| 59 | |
| 60 | |
| 61 | class IdentityTransform(AbstractTransform): |
nothing calls this directly
no outgoing calls
no test coverage detected