dgs.models.embedding_generator.pose_based.LinearPBEG¶
- class dgs.models.embedding_generator.pose_based.LinearPBEG(*args: Any, **kwargs: Any)[source]¶
Model to compute a pose-embedding given a pose, or batch of poses describing them as a single vector.
Module Name¶
LinearPBEG
Description¶
The model consists of one or multiple linear layers followed by a single sigmoid activation function. The number of linear layers is determined by the length of the hidden_layers parameter.
- Params:
joint_shape ((tuple[int, int])) – The number of joints and number of dimensions of the joints as tuple. For data from ‘COCO’ the number of joints is 17 and all joints are two-dimensional. Therefore, resulting in
joint_shape = (17, 2)
.- Optional Params:
hidden_layers ((Union[list[int], tuple[int, …], None], optional)) – Respective size of every hidden layer. The value can be None to use only one single linear NN-layer to cast the inputs to the outputs. Default
DEF_VAL.embed_gen.pose.LPBEG.hidden_layers
.bias ((bool, optional)) – Whether to use a bias term in the linear layers. Default
DEF_VAL.embed_gen.pose.LPBEG.bias
.bbox_format ((Union[str, tv_tensors.BoundingBoxFormat], optional)) – The target format of the bounding box coordinates. This will have influence on the results. Default
DEF_VAL.embed_gen.pose.LPBEG.bbox_format
.
- Important Inherited Params:
embedding_size ((int)) – Output shape or size of the embedding.
Methods
- __init__(*args, **kwargs)¶
- configure_torch_module(module: torch.nn.Module, train: bool | None = None) torch.nn.Module ¶
Set compute mode and send model to the device or multiple parallel devices if applicable.
- Parameters:
module – The torch module instance to configure.
train – Whether to train or eval this module, defaults to the value set in the base config.
- Returns:
The module on the specified device or in parallel.
- embedding_key_exists(s: State) bool ¶
Return whether the embedding_key of this model exists in a given state.
- forward(ds: State) tuple[torch.Tensor, torch.Tensor] [source]¶
Forward pass of the linear pose-based embedding generator.
- Params:
ds – Either an already flattened tensor, containing the values of the key-point coordinates and the bounding box as a single tensor of shape
[B x self.J * self.j_dim + 4]
, or the key-point coordinates and bounding boxes as tensors of shapes[B x self.J]
and[B x 4]
.- Returns:
This modules’ prediction.
embeddings
is describing the key-points and bounding boxes as a tensor of shape[B x E]
.ids
is the probability to predict a class. The ids are given as a tensor of shape[B x num_classes]
with values in range [0, 1].
- terminate() None ¶
Terminate this module and all of its submodules.
If nothing has to be done, just pass. Is used for terminating parallel execution and threads in specific models.
- validate_params(validations: dict[str, list[str | type | tuple[str, any] | Callable[[any, any], bool]]], attrib_name: str = 'params') None ¶
Given per key validations, validate this module’s parameters.
Throws exceptions on invalid or nonexistent params.
- Parameters:
attrib_name – name of the attribute to validate, should be “params” and only for base class “config”
validations –
Dictionary with the name of the parameter as key and a list of validations as value. Every validation in this list has to be true for the validation to be successful.
- The value for the validation can have multiple types:
A lambda function or other type of callable
A string as reference to a predefined validation function with one argument
None for existence
A tuple with a string as reference to a predefined validation function with one additional argument
It is possible to write nested validations, but then every nested validation has to be a tuple, or a tuple of tuples. For convenience, there are implementations for “any”, “all”, “not”, “eq”, “neq”, and “xor”. Those can have data which is a tuple containing other tuples or validations, or a single validation.
Lists and other iterables can be validated using “forall” running the given validations for every item in the input. A single validation or a tuple of (nested) validations is accepted as data.
Example
This example is an excerpt of the validation for the BaseModule-configuration.
>>> validations = { "device": [ str, ("any", [ ("in", ["cuda", "cpu"]), ("instance", torch.device) ] ) ], "print_prio": [("in", PRINT_PRIORITY)], "callable": (lambda value: value == 1), }
And within the class
__init__()
call:>>> self.validate_params()
- Raises:
InvalidParameterException – If one of the parameters is invalid.
ValidationException – If the validation list is invalid or contains an unknown validation.
Attributes
Get the device of this module.
Get whether this module is set to training-mode.
Get the name of the module.
Get the name of the module.
Get the escaped name of the module usable in filepaths by replacing spaces and underscores.
Get the (floating point) precision used in multiple parts of this module.
The size of the embedding.
The number of classes in the dataset / embedding.