vis4d.engine.connectors.util

Utility functions for the connectors module.

Functions

data_key(key[, sensors])

Returns a SourceKeyDescription with data as source.

get_field_from_prediction(prediction, ...)

Extracts a field from the prediction dict.

get_inputs_for_pred_and_data(...)

Extracts input data from the provided SourceKeyDescription.

pred_key(key)

Returns a SourceKeyDescription with prediction as source.

remap_pred_keys(info, parent_key)

Remaps the key of a connection mapping to a new parent key.

Classes

SourceKeyDescription

Defines a data entry by providing the key and source of the data.

class SourceKeyDescription[source]

Defines a data entry by providing the key and source of the data.

key

Key that is used to index data from the specified source

Type:

str

source

Which datasource to choose from. Options are [‘data’, ‘prediction’] where data referes to the output of the dataloader and prediction refers to the model output

Type:

str

sensors

Which sensors to use for the data.

Type:

Sequence[str]

data_key(key, sensors=None)[source]

Returns a SourceKeyDescription with data as source.

Parameters:
  • key (str) – Key to use for the data entry.

  • sensors (Sequence[str] | None, optional) – Which sensors to use for the data. Defaults to None.

Returns:

A SourceKeyDescription with data as source.

Return type:

SourceKeyDescription

get_field_from_prediction(prediction, old_key_name)[source]

Extracts a field from the prediction dict.

Parameters:
  • prediction (DictData) – Dict containing the model prediction output.

  • old_key_name (SourceKeyDescription) – Description of the data to extract.

Returns:

Data extracted from the prediction dict.

Return type:

Tensor | DictStrArrNested

get_inputs_for_pred_and_data(connection_dict, prediction, data)[source]

Extracts input data from the provided SourceKeyDescription.

Parameters:
  • connection_dict (dict[str, SourceKeyDescription]) – Input Key description which is used to gather and remap data from the two data dicts.

  • prediction (DictData) – Dict containing the model prediction output.

  • data (DictData) – Dict containing the dataloader output.

Raises:

ValueError – If the datasource is invalid.

Returns:

Dict containing new kwargs

consisting of new key name and data extracted from the data dicts.

Return type:

out (dict[str, Tensor | DictStrArrNested])

pred_key(key)[source]

Returns a SourceKeyDescription with prediction as source.

Parameters:

key (str) – Key to use for the data entry.

Returns:

A SourceKeyDescription with prediction as source.

Return type:

SourceKeyDescription

remap_pred_keys(info, parent_key)[source]

Remaps the key of a connection mapping to a new parent key.

Parameters:
Returns:

Description with new key.

Return type:

SourceKeyDescription