gt4sd.frameworks.granular.ml.models.base_model module¶
Base model for granular.
Summary¶
Classes:
Base model class. |
|
Autoencoder model class. |
Reference¶
- class GranularBaseModel(name, data, *args, **kwargs)[source]¶
Bases:
Module
Base model class.
- position: int¶
- from_position: List[int]¶
- __init__(name, data, *args, **kwargs)[source]¶
Construct GranularBaseModel.
- Parameters
name (
str
) – model name.data (
Dict
[str
,str
]) – data name mappings.
- forward(x, *args, **kwargs)[source]¶
Forward pass in the model.
- Parameters
x (
Any
) – model input.- Return type
Any
- Returns
model output.
- abstract _run_step(x, *args, **kwargs)[source]¶
Run a step in the model.
- Parameters
x (
Any
) – model input.- Return type
Any
- Returns
model step output.
- abstract step(input_data, target_data, device='cpu', current_epoch=0, *args, **kwargs)[source]¶
Training step for the model.
- Parameters
input_data (
Any
) – input for the step.target_data (
Any
) – target for the step.device (
str
) – string representing the device to use. Defaults to “cpu”.current_epoch (
int
) – current epoch. Defaults to 0.
- Return type
Tuple
[Any
,Any
,Any
]- Returns
a tuple containing the step output, the loss and the logs for the module.
- abstract val_step(input_data, target_data, device='cpu', current_epoch=0, *args, **kwargs)[source]¶
Validation step for the model.
- Parameters
input_data (
Any
) – input for the step.target_data (
Any
) – target for the step.device (
str
) – string representing the device to use. Defaults to “cpu”.current_epoch (
int
) – current epoch. Defaults to 0.
- Return type
Any
- Returns
a tuple containing the step output, the loss and the logs for the module.
- static add_model_specific_args(parent_parser, name, *args, **kwargs)[source]¶
Adding to a parser model specific arguments.
- Parameters
parent_parser (
ArgumentParser
) – patent parser.name (
str
) – model name.
- Return type
ArgumentParser
- Returns
updated parser.
- __annotations__ = {'__call__': 'Callable[..., Any]', '_backward_hooks': 'Dict[int, Callable]', '_buffers': 'Dict[str, Optional[Tensor]]', '_forward_hooks': 'Dict[int, Callable]', '_forward_pre_hooks': 'Dict[int, Callable]', '_is_full_backward_hook': 'Optional[bool]', '_load_state_dict_post_hooks': 'Dict[int, Callable]', '_load_state_dict_pre_hooks': 'Dict[int, Callable]', '_modules': "Dict[str, Optional['Module']]", '_non_persistent_buffers_set': 'Set[str]', '_parameters': 'Dict[str, Optional[Parameter]]', '_state_dict_hooks': 'Dict[int, Callable]', '_version': 'int', 'dump_patches': 'bool', 'forward': 'Callable[..., Any]', 'from_position': typing.List[int], 'position': <class 'int'>, 'training': 'bool'}¶
- __doc__ = 'Base model class.'¶
- __module__ = 'gt4sd.frameworks.granular.ml.models.base_model'¶
- class GranularEncoderDecoderModel(name, data, *args, **kwargs)[source]¶
Bases:
GranularBaseModel
Autoencoder model class.
- latent_size: int¶
- abstract decode(z, *args, **kwargs)[source]¶
Decode a latent space point.
- Parameters
z (
Any
) – latent point.- Return type
Any
- Returns
decoded sample.
- abstract encode(x, *args, **kwargs)[source]¶
Encode a sample.
- Parameters
x (
Any
) – input sample.- Return type
Any
- Returns
latent encoding.
- encode_decode(x, *args, **kwargs)[source]¶
Encode and decode a sample.
- Parameters
x (
Any
) – input sample.- Return type
Any
- Returns
decoded sample.
- inference(z, *args, **kwargs)[source]¶
Run the model in inference mode.
- Parameters
z (
Any
) – sample.- Return type
Any
- Returns
generated output.
- sample(mu, log_var)[source]¶
Sample a point from a given mean and average following a normal log-likelihood.
- Parameters
mu (
Tensor
) – mean tensor.log_var (
Tensor
) – log varian tensor.
- Return type
Tuple
[Distribution
,Distribution
,Tensor
]- Returns
a tuple containing standard normal, localized normal and the sampled point.
- __annotations__ = {'__call__': 'Callable[..., Any]', '_backward_hooks': 'Dict[int, Callable]', '_buffers': 'Dict[str, Optional[Tensor]]', '_forward_hooks': 'Dict[int, Callable]', '_forward_pre_hooks': 'Dict[int, Callable]', '_is_full_backward_hook': 'Optional[bool]', '_load_state_dict_post_hooks': 'Dict[int, Callable]', '_load_state_dict_pre_hooks': 'Dict[int, Callable]', '_modules': "Dict[str, Optional['Module']]", '_non_persistent_buffers_set': 'Set[str]', '_parameters': 'Dict[str, Optional[Parameter]]', '_state_dict_hooks': 'Dict[int, Callable]', '_version': 'int', 'dump_patches': 'bool', 'forward': 'Callable[..., Any]', 'from_position': 'List[int]', 'latent_size': <class 'int'>, 'position': 'int', 'training': 'bool'}¶
- __doc__ = 'Autoencoder model class.'¶
- __module__ = 'gt4sd.frameworks.granular.ml.models.base_model'¶