sportslabkit.types.tracklet#

Overview#

Classes#

Tracklet

Tracklet class to be u

Function#

id_to_color(id_string)

-

Classes#

class sportslabkit.types.tracklet.Tracklet(max_staleness: int = 5)[source]#

Tracklet class to be u

Stores observations of different types without making predictions about the next state. New observation types can be registered, and the tracker can be extended with more functionality if needed.

Observations are stored in a dictionary, where the key is the name of the observation type and the value is a list of observations. The length of the list is equal to the number of steps the tracker has been alive. The first element of the list is the first observation, and the last element is the most recent observation.

States are stored in a dictionary, where the key is the name of the state and the value is the most recent state. The state is an indication of the current state of the tracker.

Parameters:

max_staleness (int, optional) – The maximum number of steps a tracker can be stale for before it is considered dead. Defaults to 5.

id#

unique id of the tracker

Type:

int

steps_alive#

number of steps the tracker was alive

Type:

int

staleness#

number of steps since the last positive update

Type:

float

global_step#

number of steps since the start of the tracking process

Type:

int

max_staleness#

number of steps after which a tracker is considered dead

Type:

float

Overview

Methods#

check_observation_lengths()

check if all value lengths are the same

register_observation_type(name)

Register a new observation type.

register_observation_types(names)

Register a new observation type.

update_observations(observations, global_step)

-

update_observation(name, value, global_step)

-

register_state_type(name)

Register a new state type.

register_state_types(names)

Register a new state type.

get_observation(name)

Get the most recent value of an observation type.

get_observations(name)

Get all values of an observation type.

get_state(name)

Get the most recent value of a state type.

get_states(name)

Get all values of a state type.

update_states(states, global_step)

Update multiple states with new values.

update_state(name, value)

Update the state with a new value.

cleanup()

Remove most recent n=staleness observations

update_current_observation(name, value)

Update the most recent observation with a new value.

increment_counter(global_step)

Increment the step counters, steps_alive and global_step. If global_step is provided, it will be used instead of incrementing the global_step counter.

is_active()

Check if the tracker is active.

is_stale()

Check if the tracker is stale.

to_bbdf()

Convert the tracker predictions to a BBoxDataFrame.

print(num_recent_obs, use_colors)

Pretty-print the Tracklet information.

Members

check_observation_lengths() None[source]#

check if all value lengths are the same

register_observation_type(name: str) None[source]#

Register a new observation type.

Parameters:

name (str) – Name of the new observation type to be registered.

register_observation_types(names: list[str]) None[source]#

Register a new observation type.

Parameters:

name (str) – Name of the new observation type to be registered.

update_observations(observations: dict[str, Any], global_step: int | None = None) None[source]#
update_observation(name: str, value: Any, global_step: int | None = None) None[source]#
register_state_type(name: str) None[source]#

Register a new state type.

Parameters:

name (str) – Name of the new state type to be registered.

register_state_types(names: list[str]) None[source]#

Register a new state type.

Parameters:

name (str) – Name of the new state type to be registered.

get_observation(name: str | None = None) Any | None[source]#

Get the most recent value of an observation type.

Parameters:

name (str) – Name of the observation type.

Returns:

The most recent value of the specified observation type or None if not available.

Return type:

Optional[Any]

get_observations(name: str | None = None) Any | None[source]#

Get all values of an observation type.

Parameters:

name (str) – Name of the observation type.

Returns:

All values of the specified observation type.

Return type:

List[Any]

get_state(name: str | None = None) Any | None[source]#

Get the most recent value of a state type.

Parameters:

name (str) – Name of the state type.

Returns:

The most recent value of the specified state type or None if not available.

Return type:

Optional[Any]

get_states(name: str | None = None) Any | None[source]#

Get all values of a state type.

Parameters:

name (str) – Name of the state type.

Returns:

All values of the specified state type.

Return type:

List[Any]

update_states(states: dict[str, Any], global_step: int | None = None) None[source]#

Update multiple states with new values.

Parameters:
  • states (Dict[str, Any]) – Dictionary of states to be updated.

  • global_step (Optional[int], optional) – Global step. Defaults to None.

update_state(name: str, value: Any) None[source]#

Update the state with a new value.

Parameters:
  • name (str) – Name of the state to be updated.

  • value (Any) – New value for the specified state.

cleanup()[source]#

Remove most recent n=staleness observations

update_current_observation(name: str, value: Any) None[source]#

Update the most recent observation with a new value.

Parameters:
  • name (str) – Name of the observation type to be updated.

  • value (Any) – New value for the specified observation type.

increment_counter(global_step: int | None = None) None[source]#

Increment the step counters, steps_alive and global_step. If global_step is provided, it will be used instead of incrementing the global_step counter.

is_active() bool[source]#

Check if the tracker is active.

Returns:

True if the tracker is active (i.e. steps_alive > 0, not stale, and not invalid), otherwise False.

Return type:

bool

is_stale() bool[source]#

Check if the tracker is stale.

Returns:

True if the tracker’s staleness is greater than max_staleness, otherwise False.

Return type:

bool

to_bbdf() sportslabkit.dataframe.bboxdataframe.BBoxDataFrame[source]#

Convert the tracker predictions to a BBoxDataFrame.

Returns:

BBoxDataFrame of the tracker

Return type:

BBoxDataFrame

print(num_recent_obs: int = 1, use_colors: bool = False) None[source]#

Pretty-print the Tracklet information.

Parameters:
  • num_recent_obs (int, optional) – The number of recent observations to display for each observation type. Defaults to 1.

  • use_colors (bool, optional) – Whether to use colors in the output. Defaults to False.

Functions#

sportslabkit.types.tracklet.id_to_color(id_string: str) str[source]#