sportslabkit.types#
Overview#
Detection represents an object detected in an image. |
|
SoccerTrack detections class for inference results. |
|
Tracklet class to be u |
Classes#
- class sportslabkit.types.Detection(box: sportslabkit.types.types.Box, score: float | None = None, class_id: int | None = None, feature: Vector | None = None)[source]#
Detection represents an object detected in an image.
The Detection class expects the following inputs:
box (np.ndarray): The bounding box of the detected object. The shape is (4,). score (float, optional): The confidence score of the detection. class_id (int, optional): The class of the detected object. feature (np.ndarray, optional): The feature vector of the detected object. The shape is (1, N).
- Parameters:
box (np.ndarray) – The bounding box of the detected object. Should be an array of shape (4,).
score (float, optional) – The confidence score of the detection.
class_id (int, optional) – The class of the detected object.
feature (np.ndarray, optional) – The feature vector of the detected object. Should be an array of shape (1, N).
- _box#
The bounding box of the detected object.
- Type:
np.ndarray
- _feature#
The feature vector of the detected object.
- Type:
np.ndarray, optional
- Raises:
ValueError – If the box does not have the shape (4,).
- class sportslabkit.types.Detections(preds: list[dict] | list[list] | list[Detection], im: str | Path | Image.Image | np.ndarray, times: tuple[float, float, float] = (0, 0, 0), names: list[str] | None = None)[source]#
SoccerTrack detections class for inference results.
Overview
Methods# show(**kwargs)-
save_image(path, **kwargs)-
save_boxes(path)-
crop(save, save_dir, exist_ok)-
to_df()-
to_list()-
merge(other)-
Members
- show(**kwargs) PIL.Image.Image#
- crop(save: bool = True, save_dir: str | Path = 'runs/detect/exp', exist_ok: bool = False) list[PIL.Image.Image]#
- to_df()#
- to_list()#
- merge(other)#
- class sportslabkit.types.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.
Overview
Methods# check if all value lengths are the same
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.
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
- register_observation_type(name: str) None#
Register a new observation type.
- Parameters:
name (str) – Name of the new observation type to be registered.
- register_observation_types(names: list[str]) None#
Register a new observation type.
- Parameters:
name (str) – Name of the new observation type to be registered.
- register_state_type(name: str) None#
Register a new state type.
- Parameters:
name (str) – Name of the new state type to be registered.
- register_state_types(names: list[str]) None#
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#
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#
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#
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#
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#
Update multiple states with new values.
- update_state(name: str, value: Any) None#
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()#
Remove most recent n=staleness observations
- update_current_observation(name: str, value: Any) None#
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#
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#
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:
- is_stale() bool#
Check if the tracker is stale.
- Returns:
True if the tracker’s staleness is greater than max_staleness, otherwise False.
- Return type:
- to_bbdf() sportslabkit.dataframe.bboxdataframe.BBoxDataFrame#
Convert the tracker predictions to a BBoxDataFrame.
- Returns:
BBoxDataFrame of the tracker
- Return type: