sportslabkit.detection_model#
Overview#
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. |
|
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. |
|
YOLO model wrapper. |
|
YOLO model wrapper. |
|
YOLO model wrapper. |
|
YOLO model wrapper. |
|
YOLO model wrapper. |
|
YOLO model wrapper. |
Classes#
- class sportslabkit.detection_model.BaseDetectionModel[source]#
Bases:
abc.ABCBase 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
- input_is_batched#
Whether the input is batched or not. This is set by the _check_and_fix_inputs method.
- Type:
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.detection_model.DummyDetectionModel(detections)[source]#
Bases:
sportslabkit.detection_model.base.BaseDetectionModelBase 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
- input_is_batched#
Whether the input is batched or not. This is set by the _check_and_fix_inputs method.
- Type:
Overview
Members
- forward(x)#
- Parameters:
x (Tensor) – input tensor
- Returns:
output tensor
- Return type:
Tensor
- reset_image_count()#
- static from_bbdf(bbdf)#
- class sportslabkit.detection_model.YOLOv8(model: str = '', agnostic_nms: bool = False, multi_label: bool = False, classes: list[str] | None = None, max_det: int = 1000, amp: bool = False, imgsz: int = 640, conf: float = 0.25, iou: float = 0.45, device: str = 'cpu', verbose: bool = False, augment: bool = False)[source]#
Bases:
sportslabkit.detection_model.base.BaseDetectionModelYOLO model wrapper. Receives the arguments controlling inference as ‘inference_config’ when initialized.
Overview
Attributes# -
Members
- hparam_search_space#
- forward(x, **kwargs)#
- Parameters:
x (Tensor) – input tensor
- Returns:
output tensor
- Return type:
Tensor
- class sportslabkit.detection_model.YOLOv8l(**model_config)[source]#
Bases:
YOLOv8YOLO model wrapper. Receives the arguments controlling inference as ‘inference_config’ when initialized.
- class sportslabkit.detection_model.YOLOv8m(**model_config)[source]#
Bases:
YOLOv8YOLO model wrapper. Receives the arguments controlling inference as ‘inference_config’ when initialized.
- class sportslabkit.detection_model.YOLOv8n(**model_config)[source]#
Bases:
YOLOv8YOLO model wrapper. Receives the arguments controlling inference as ‘inference_config’ when initialized.
- class sportslabkit.detection_model.YOLOv8s(**model_config)[source]#
Bases:
YOLOv8YOLO model wrapper. Receives the arguments controlling inference as ‘inference_config’ when initialized.
- class sportslabkit.detection_model.YOLOv8x(model: str = 'yolov8x', agnostic_nms: bool = False, multi_label: bool = False, classes: list[str] | None = None, max_det: int = 1000, amp: bool = False, imgsz: int = 640, conf: float = 0.25, iou: float = 0.45, device: str = 'cpu', verbose: bool = False, augment: bool = False)[source]#
Bases:
YOLOv8YOLO model wrapper. Receives the arguments controlling inference as ‘inference_config’ when initialized.
Functions#
- sportslabkit.detection_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.detection_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:
- Returns:
An instance of the requested model, or None if no match was found.
- Return type: