sportslabkit.calibration_model#

Overview#

Classes#

BaseCalibrationModel

Base class for detection models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

DummyCalibrationModel

Base class for detection models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

LineBasedCalibrator

Base class for detection models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

Function#

show_available_models()

Print the names of all available BaseDetectionModel models.

load(model_name, **model_config)

Load a model by name.

Classes#

class sportslabkit.calibration_model.BaseCalibrationModel[source]#

Bases: abc.ABC

Base class for detection models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

Subclasses should override the ‘load’ and ‘forward’ methods. The ‘load’ method should handle loading the model from the specified repository and checkpoint, and ‘forward’ should define the forward pass of the model. Then add ConfigTemplates for your model to define the available configuration options.

The input to the model should be flexible. It accepts numpy.ndarray, torch.Tensor, pathlib Path, string file, PIL Image, or a list of any of these. All inputs will be converted to a list of numpy arrays representing the images.

The output of the model is expected to be a list of Detection objects, where each Detection object represents a detected object in an image. If the model’s output does not meet this expectation, _check_and_fix_outputs method should convert the output into a compatible format.

Example

class CustomDetectionModel(BaseDetectionModel):
def load(self):

# Load your model here pass

def forward(self, x):

# Define the forward pass here pass

model_config#

The configuration for the model.

Type:

Optional[dict]

input_is_batched#

Whether the input is batched or not. This is set by the _check_and_fix_inputs method.

Type:

bool

Overview

Methods#

read_image(img)

-

forward(x)

abc :param x: input tensor

test()

-

Members

read_image(img)#
abstract forward(x)#
Parameters:

x (Tensor) – input tensor

Returns:

output tensor

Return type:

Tensor

test()#
class sportslabkit.calibration_model.DummyCalibrationModel(homographies, mode='constant')[source]#

Bases: sportslabkit.calibration_model.base.BaseCalibrationModel

Base class for detection models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

Subclasses should override the ‘load’ and ‘forward’ methods. The ‘load’ method should handle loading the model from the specified repository and checkpoint, and ‘forward’ should define the forward pass of the model. Then add ConfigTemplates for your model to define the available configuration options.

The input to the model should be flexible. It accepts numpy.ndarray, torch.Tensor, pathlib Path, string file, PIL Image, or a list of any of these. All inputs will be converted to a list of numpy arrays representing the images.

The output of the model is expected to be a list of Detection objects, where each Detection object represents a detected object in an image. If the model’s output does not meet this expectation, _check_and_fix_outputs method should convert the output into a compatible format.

Example

class CustomDetectionModel(BaseDetectionModel):
def load(self):

# Load your model here pass

def forward(self, x):

# Define the forward pass here pass

model_config#

The configuration for the model.

Type:

Optional[dict]

input_is_batched#

Whether the input is batched or not. This is set by the _check_and_fix_inputs method.

Type:

bool

Overview

Methods#

forward(x)

param x:

input tensor

reset_image_count()

-

Members

forward(x)#
Parameters:

x (Tensor) – input tensor

Returns:

output tensor

Return type:

Tensor

reset_image_count()#
class sportslabkit.calibration_model.LineBasedCalibrator(min_line_length=50, line_distance_threshold=50, line_thickness=15, morph_size=15, dst_points=None)[source]#

Bases: sportslabkit.calibration_model.base.BaseCalibrationModel

Base class for detection models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

Subclasses should override the ‘load’ and ‘forward’ methods. The ‘load’ method should handle loading the model from the specified repository and checkpoint, and ‘forward’ should define the forward pass of the model. Then add ConfigTemplates for your model to define the available configuration options.

The input to the model should be flexible. It accepts numpy.ndarray, torch.Tensor, pathlib Path, string file, PIL Image, or a list of any of these. All inputs will be converted to a list of numpy arrays representing the images.

The output of the model is expected to be a list of Detection objects, where each Detection object represents a detected object in an image. If the model’s output does not meet this expectation, _check_and_fix_outputs method should convert the output into a compatible format.

Example

class CustomDetectionModel(BaseDetectionModel):
def load(self):

# Load your model here pass

def forward(self, x):

# Define the forward pass here pass

model_config#

The configuration for the model.

Type:

Optional[dict]

input_is_batched#

Whether the input is batched or not. This is set by the _check_and_fix_inputs method.

Type:

bool

Overview

Methods#

forward(image)

Calculate the homography matrix for the given image.

Members

forward(image)#

Calculate the homography matrix for the given image.

Parameters: - image: numpy array

The source image.

  • dst_points: numpy array or None

    The destination points for the transformation. If not provided, it defaults to the four corners of a standard soccer pitch (105m x 68m).

Returns: - numpy array

The computed homography matrix.

Functions#

sportslabkit.calibration_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.calibration_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.

  • model_config (dict, optional) – The model configuration to use when instantiating the model.

Returns:

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

Return type:

BaseDetectionModel