sportslabkit.detection_model.base#

Overview#

Classes#

BaseDetectionModel

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#

convert_to_detection(pred)

Convert an output to a single detection object.

Attributes#

model

-

Classes#

class sportslabkit.detection_model.base.BaseDetectionModel[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)[source]#
abstract forward(x)[source]#
Parameters:

x (Tensor) – input tensor

Returns:

output tensor

Return type:

Tensor

test()[source]#

Functions#

sportslabkit.detection_model.base.convert_to_detection(pred)[source]#

Convert an output to a single detection object.

Handles the following input types: - dict with keys: bbox_left, bbox_top, bbox_width, bbox_height, conf, class - list or tuple with 6 items: bbox_left, bbox_top, bbox_width, bbox_height, conf, class - Detection object

Parameters:

pred – prediction object to convert

Returns:

Detection object

Attributes#

sportslabkit.detection_model.base.model[source]#