sportslabkit.metrics.object_detection#

Overview#

Function#

ElevenPointInterpolatedAP(rec, prec)

Calculate 11-point interpolated average precision.

iou_score(bbox_det, bbox_gt)

-

iou_scores(bbox_dets, bbox_gts, xywh, average)

-

convert_to_x1y1x2y2(bbox)

Convert bbox to x1y1x2y2 format.

convert_bboxes(bboxes)

Convert bboxes to tuples of (xmin, ymin, width, height, confidence, class_id, image_name).

validate_bboxes(bboxes, is_gt)

-

ap_score(bboxes_det_per_class, bboxes_gt_per_class, iou_threshold)

Calculate average precision.

ap_score_range(bboxes_det_per_class, bboxes_gt_per_class, start_threshold, end_threshold, step)

Calculate average precision in the specified range.

map_score(bboxes_det, bboxes_gt, iou_threshold)

Calculate mean average precision.

map_score_range(bboxes_det, bboxes_gt, start_threshold, end_threshold, step)

Calculate mean average precision.

Functions#

sportslabkit.metrics.object_detection.ElevenPointInterpolatedAP(rec: Any, prec: Any) list[Any][source]#

Calculate 11-point interpolated average precision.

Parameters:
  • rec (np.ndarray[np.float64]) – recall array

  • prec (np.ndarray[np.float64]) – precision array

Returns:

List containing information necessary for ap calculation

Return type:

Interp_ap_info (list[Any])

sportslabkit.metrics.object_detection.iou_score(bbox_det: list[int], bbox_gt: list[int]) float[source]#
sportslabkit.metrics.object_detection.iou_scores(bbox_dets: list[int] | list[list[int]], bbox_gts: list[int] | list[list[int]], xywh: bool = False, average: bool = True) list[float][source]#
sportslabkit.metrics.object_detection.convert_to_x1y1x2y2(bbox: list[int]) list[int][source]#

Convert bbox to x1y1x2y2 format.

sportslabkit.metrics.object_detection.convert_bboxes(bboxes: pd.DataFrame | BBoxDataFrame | list | tuple) list[float, float, float, float, float, str, str][source]#

Convert bboxes to tuples of (xmin, ymin, width, height, confidence, class_id, image_name).

Parameters:

bboxes (pd.DataFrame | BBoxDataFrame | list | tuple) – bboxes to convert.

Returns:

converted bboxes.

Return type:

list[float, float, float, float, float, str, str]

sportslabkit.metrics.object_detection.validate_bboxes(bboxes: list[float, float, float, float, float, str, str], is_gt=False) None[source]#
sportslabkit.metrics.object_detection.ap_score(bboxes_det_per_class: list[list[float, float, float, float, float, str, str]], bboxes_gt_per_class: list[list[float, float, float, float, float, str, str]], iou_threshold: float) dict[str, Any][source]#

Calculate average precision.

Parameters:
  • bboxes_det_per_class (list) – bbox of detected object per class.

  • bboxes_gt_per_class (list) – bbox of ground truth object per class.

  • IOUThreshold (float) – iou threshold. it is usually set to 50%, 75% or 95%.

Returns:

dict containing information about average precision

Return type:

ap(dict)

Note

bboxes_det_per_class: [bbox_det_1, bbox_det_2, …] bboxes_gt_per_class: [bbox_gt_1, bbox_gt_2, …]

#The elements of each bbox variable are as follows, each element basically corresponding to a property of the BoundingBox class of Object-Detection-Metrics. https://github.com/rafaelpadilla/Object-Detection-Metrics/blob/master/lib/BoundingBox.py

bbox_det_n(tuple): (xmin, ymin, width, height, confidence, class_id, image_name) bbox_gt_n(tuple): (xmin, ymin, width, height, 1.0, class_id, image_name)

xmin(float): xmin ymin(float): ymin width(float): width height(float): height confidence(float): class confidence class_id(str): class id image_name(str): image name

#index variable, this is written as a global variable in the def main() function. X_INDEX = 0 Y_INDEX = 1 W_INDEX = 2 H_INDEX = 3 CONFIDENCE_INDEX = 4 CLASS_ID_INDEX = 5 IMAGE_NAME_INDEX = 6

sportslabkit.metrics.object_detection.ap_score_range(bboxes_det_per_class: list[float, float, float, float, float, str, str], bboxes_gt_per_class: list[float, float, float, float, float, str, str], start_threshold: float = 0.5, end_threshold: float = 0.95, step: float = 0.05) float[source]#

Calculate average precision in the specified range.

Parameters:
  • bboxes_det_per_class (list) – bbox of detected object per class.

  • bboxes_gt_per_class (list) – bbox of ground truth object per class.

  • start_threshold (float) – start threshold of IOU. default is 0.5.

  • end_threshold (float) – end threshold of IOU. default is 0.95.

  • step (float) – step of updating threshold. default is 0.05.

Returns:

list of average precision in the specified range. ap_range(float): average of ap in the specified range.

Return type:

ap_results(list)

sportslabkit.metrics.object_detection.map_score(bboxes_det: pd.DataFrame | BBoxDataFrame | list | tuple, bboxes_gt: pd.DataFrame | BBoxDataFrame | list | tuple, iou_threshold: float) float[source]#

Calculate mean average precision.

Parameters:
  • det_df (pd.DataFrame) – dataframe of detected object.

  • gt_df (pd.DataFrame) – dataframe of ground truth object.

  • IOUThreshold (float) – iou threshold

Returns:

mean average precision

Return type:

map(float)

sportslabkit.metrics.object_detection.map_score_range(bboxes_det: pd.DataFrame | BBoxDataFrame | list | tuple, bboxes_gt: pd.DataFrame | BBoxDataFrame | list | tuple, start_threshold: float = 0.5, end_threshold: float = 0.95, step: float = 0.05) float[source]#

Calculate mean average precision.

Parameters:
  • det_df (pd.DataFrame) – dataframe of detected object.

  • gt_df (pd.DataFrame) – dataframe of ground truth object.

  • start_threshold (float) – start threshold of IOU. default is 0.5.

  • end_threshold (float) – end threshold of IOU. default is 0.95.

  • step (float) – step of updating threshold. default is 0.05.

Returns:

average of map in the specified range. (0.5 to 0.95 in increments of 0.05)

Return type:

map_range(float)

Attributes#

sportslabkit.metrics.object_detection.X_INDEX = 0[source]#
sportslabkit.metrics.object_detection.Y_INDEX = 1[source]#
sportslabkit.metrics.object_detection.W_INDEX = 2[source]#
sportslabkit.metrics.object_detection.H_INDEX = 3[source]#
sportslabkit.metrics.object_detection.CONFIDENCE_INDEX = 4[source]#
sportslabkit.metrics.object_detection.CLASS_ID_INDEX = 5[source]#
sportslabkit.metrics.object_detection.IMAGE_NAME_INDEX = 6[source]#