sportslabkit.vector_model#

Overview#

Classes#

BaseVectorModel

Abstract Base Class for handling vector-based models.

SklearnVectorModel

A specialized subclass of BaseVectorModel for scikit-learn pipelines.

Detection

Detection represents an object detected in an image.

Function#

inheritors(cls)

Get all subclasses of a given class.

show_available_models()

Print the names of all available BaseDetectionModel models.

load(model_name, **model_config)

Load a model by name.

Classes#

class sportslabkit.vector_model.BaseVectorModel(input_vector_size: int | None = None, output_vector_size: int | None = None)[source]#

Bases: abc.ABC

Abstract Base Class for handling vector-based models.

This class encapsulates model loading, input/output validation, and forward pass operations.

Overview

Methods#

forward(inputs, **kwargs)

abc Define the forward pass of the model. Must be overridden by subclasses.

load(path)

Load the model from disk.

Members

abstract forward(inputs: sportslabkit.types.Vector, **kwargs: Any) sportslabkit.types.Vector#

Define the forward pass of the model. Must be overridden by subclasses.

Parameters:
  • inputs (Vector) – The input data.

  • **kwargs (Any) – Additional arguments to be passed to the forward method.

Returns:

The output data.

Return type:

Vector

load(path: str) None#

Load the model from disk.

Parameters:

path (str) – The path to the model file.

class sportslabkit.vector_model.SklearnVectorModel(model_path: str = '', input_vector_size: int | None = None, output_vector_size: int | None = None)[source]#

Bases: sportslabkit.vector_model.base.BaseVectorModel

A specialized subclass of BaseVectorModel for scikit-learn pipelines.

This class is designed to facilitate the use of scikit-learn pipelines as vector-based models within the SportsLabKit ecosystem. It overrides the abstract methods from BaseVectorModel to provide implementations tailored for scikit-learn pipelines.

model#

The loaded scikit-learn pipeline model. None if the model is not loaded.

Type:

Pipeline | None

Overview

Methods#

forward(inputs, **kwargs)

Implement the forward pass specific to scikit-learn pipelines.

Members

forward(inputs: sportslabkit.types.Vector, **kwargs: Any) sportslabkit.types.Vector#

Implement the forward pass specific to scikit-learn pipelines.

This method takes a vector input and passes it through the scikit-learn pipeline’s predict method. Additional keyword arguments can be passed to the predict method via **kwargs.

Parameters:
  • inputs (Vector) – The input vector, which should match the expected input shape of the pipeline.

  • **kwargs (Any) – Additional keyword arguments to pass to the pipeline’s predict method.

Returns:

The output vector from the pipeline’s predict method.

Return type:

Vector

Raises:

ValueError – If the model attribute is None, indicating that the model has not been loaded.

class sportslabkit.vector_model.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

_score#

The confidence score of the detection.

Type:

float, optional

_class_id#

The class of the detected object.

Type:

int, optional

_feature#

The feature vector of the detected object.

Type:

np.ndarray, optional

Raises:

ValueError – If the box does not have the shape (4,).

Functions#

sportslabkit.vector_model.inheritors(cls)[source]#

Get all subclasses of a given class.

Parameters:

cls (type) – The class to find subclasses of.

Returns:

A set of the subclasses of the input class.

Return type:

set[type]

sportslabkit.vector_model.show_available_models()[source]#

Print the names of all available BaseDetectionModel models.

The models are subclasses of BaseDetectionModel. The names are printed as a list to the console.

sportslabkit.vector_model.load(model_name, **model_config)[source]#

Load a model by name.

The function searches subclasses of BaseDetectionModel for a match with the given name. If a match is found, an instance of the model is returned. If no match is found, a warning is logged and the function returns None.

Parameters:

model_name (str) – The name of the model to load.

Returns:

An instance of the requested model, or None if no match was found.

Return type:

BaseDetectionModel