tracklab.utils package

class tracklab.utils.BBoxDataFrameAccessor(pandas_obj)[source]

Bases: object

conf()[source]
ltrb(image_shape=None, rounded=False)[source]
ltwh(image_shape=None, rounded=False)[source]
xywh(image_shape=None, rounded=False)[source]
class tracklab.utils.BBoxSeriesAccessor(pandas_obj)[source]

Bases: object

conf()[source]
ltrb(image_shape=None, rounded=False)[source]
ltwh(image_shape=None, rounded=False)[source]
xywh(image_shape=None, rounded=False)[source]
class tracklab.utils.KeypointsDataFrameAccessor(pandas_obj)[source]

Bases: object

c()[source]
conf()[source]
in_bbox_coord(bbox_ltwh)[source]
keypoints_bbox_xyc()[source]

Converts from keypoints in image coordinates to keypoints in bbox coordinates

xy(image_shape=None, rounded=False)[source]
xyc(image_shape=None, rounded=False)[source]
class tracklab.utils.KeypointsSeriesAccessor(pandas_obj)[source]

Bases: object

c()[source]
conf()[source]
in_bbox_coord(bbox_ltwh)[source]
keypoints_bbox_xyc()[source]

Converts from keypoints in image coordinates to keypoints in bbox coordinates

xy(image_shape=None, rounded=False)[source]
xyc(image_shape=None, rounded=False)[source]

Submodules

tracklab.utils.collate module

class tracklab.utils.collate.Unbatchable(iterable=(), /)[source]

Bases: tuple

tracklab.utils.collate.default_collate(batch)[source]

Puts each data field into a tensor with outer dimension batch size

tracklab.utils.coordinates module

tracklab.utils.coordinates.bbox_ltwh2ltrb(ltwh)[source]
tracklab.utils.coordinates.clip_bbox_ltrb_to_img_dim(bbox_ltrb, img_w, img_h)[source]

Clip bounding box to image dimensions. :param bbox_ltrb: bounding box, shape (4,) :type bbox_ltrb: np.ndarray :param img_w: image width :type img_w: int :param img_h: image height :type img_h: int

Returns:

clipped bounding box, shape (4,)

Return type:

bbox_ltrb (np.ndarray)

tracklab.utils.coordinates.clip_bbox_ltwh_to_img_dim(bbox_ltwh, img_w, img_h)[source]

Clip bounding box to image dimensions. :param bbox_ltwh: bounding box, shape (4,) :type bbox_ltwh: np.ndarray :param img_w: image width :type img_w: int :param img_h: image height :type img_h: int

Returns:

clipped bounding box, shape (4,)

Return type:

bbox_ltwh (np.ndarray)

tracklab.utils.coordinates.clip_bbox_ltwh_to_img_dim_old(bbox_ltwh, img_w, img_h)[source]

Clip bounding box to image dimensions. :param bbox_ltwh: bounding box, shape (4,) :type bbox_ltwh: np.ndarray :param img_w: image width :type img_w: int :param img_h: image height :type img_h: int

Returns:

clipped bounding box, shape (4,)

Return type:

bbox_ltwh (np.ndarray)

tracklab.utils.coordinates.clip_keypoints_to_image(kps, image_size)[source]

Clip keypoints to image size.

Parameters: - kps: a tensor/array of size 17x3 representing keypoints.

Can be either a numpy array or a torch tensor.

  • image_size (tuple): a tuple containing the width and height of the target image.

Returns: - clipped_kps: keypoints clipped to image size.

Returns in the same format as input (numpy array or torch tensor).

tracklab.utils.coordinates.generate_bbox_from_keypoints(keypoints, extension_factor, image_shape=None)[source]

Generates a bounding box from keypoints by computing the bounding box of the keypoints and extending it by a factor.

Parameters:
  • keypoints (np.ndarray) – A numpy array of shape (K, 3) representing the keypoints in the format (x, y, c).

  • extension_factor (tuple) – A tuple of float [top, bottom, right&left] representing the factor by which

  • keypoints. (the bounding box should be extended based on the)

  • image_shape (tuple) – A tuple of two integers representing the image dimensions (width, height).

Returns:

A numpy array of shape (4,) representing the bounding box in the format (left, top, w, h).

Return type:

np.ndarray

tracklab.utils.coordinates.keypoints_in_bbox_coord(kp_xyc_img, bbox_ltwh)[source]

Convert keypoints in image coordinates to bounding box coordinates and filter out keypoints that are outside the bounding box. :param kp_xyc_img: keypoints in image coordinates, shape (K, 2) :type kp_xyc_img: np.ndarray :param bbox_tlwh: bounding box, shape (4,) :type bbox_tlwh: np.ndarray

Returns:

keypoints in bounding box coordinates, shape (K, 2)

Return type:

kp_xyc_bbox (np.ndarray)

tracklab.utils.coordinates.ltrb_to_ltwh(bbox, image_shape=None, rounded=False)[source]

Converts coordinates [left, top, right, bottom] to [left, top, w, h]. If image_shape is provided, the bbox is clipped to the image dimensions and its dimensions are ensured to be valid.

tracklab.utils.coordinates.ltrb_to_xywh(bbox, image_shape=None, rounded=False)[source]

Converts coordinates [left, top, right, bottom] to [center_x, center_y, w, h]. If image_shape is provided, the bbox is clipped to the image dimensions and its dimensions are ensured to be valid.

tracklab.utils.coordinates.ltwh_to_ltrb(bbox, image_shape=None, rounded=False)[source]

Converts coordinates [left, top, w, h] to [left, top, right, bottom]. If image_shape is provided, the bbox is clipped to the image dimensions and its dimensions are ensured to be valid.

tracklab.utils.coordinates.ltwh_to_xywh(bbox, image_shape=None, rounded=False)[source]

Converts coordinates [left, top, w, h] to [center_x, center_y, w, h]. If image_shape is provided, the bbox is clipped to the image dimensions and its dimensions are ensured to be valid.

tracklab.utils.coordinates.rescale_keypoints(rf_keypoints, size, new_size)[source]

Rescale keypoints to new size. :param rf_keypoints: keypoints in relative coordinates, shape (K, 2) :type rf_keypoints: np.ndarray :param size: original size, (w, h) :type size: tuple :param new_size: new size, (w, h) :type new_size: tuple

Returns:

rescaled keypoints in relative coordinates, shape (K, 2)

Return type:

rf_keypoints (np.ndarray)

tracklab.utils.coordinates.round_bbox_coordinates(bbox)[source]

Round bounding box coordinates. Round to ceil value to avoid bbox with zero width or height. Because of ceil rounding, resulting bbox may be outside of image. Apply above ‘clip_bbox_ltrb_to_img_dim’ to clip bbox to image dimensions. :param bbox: bounding box, shape (4,), in tlwh or tlbr format :type bbox: np.ndarray

Returns:

rounded bounding box, shape (4,)

Return type:

bbox (np.ndarray)

tracklab.utils.coordinates.sanitize_bbox_ltrb(bbox, image_shape=None, rounded=False)[source]

Sanitizes a bounding box by clipping it to the image dimensions and ensuring that its dimensions are valid.

Parameters:
  • bbox (np.ndarray) – A numpy array of shape (4,) representing the bounding box in the format

  • `[left

  • top

  • right

  • bottom]`.

  • image_shape (tuple) – A tuple of two integers representing the image dimensions (width, height).

  • round (bool) – Whether to round the bounding box coordinates, type becomes int.

Returns:

A numpy array of shape (4,) representing the sanitized bounding box in the format [left, top, right, bottom].

Return type:

np.ndarray

tracklab.utils.coordinates.sanitize_bbox_ltwh(bbox: array, image_shape=None, rounded=False)[source]

Sanitizes a bounding box by clipping it to the image dimensions and ensuring that its dimensions are valid.

Parameters:
  • bbox (np.ndarray) – A numpy array of shape (4,) representing the bounding box in the format

  • `[left

  • top

  • width

  • height]`.

  • image_shape (tuple) – A tuple of two integers representing the image dimensions (width, height).

  • rounded (bool) – Whether to round the bounding box coordinates, type becomes int.

Returns:

A numpy array of shape (4,) representing the sanitized bounding box in the format [left, top, width, height].

Return type:

np.ndarray

tracklab.utils.coordinates.sanitize_bbox_xywh(bbox, images_shape=None, rounded=False)[source]

Sanitizes a bounding box by clipping it to the image dimensions and ensuring that its dimensions are valid.

Parameters:
  • box (np.ndarray) – A numpy array of shape (4,) representing the bounding box in the format

  • `[x_center

  • y_center

  • width

  • height]`.

  • image_shape (tuple) – A tuple of two integers representing the image dimensions (width, height).

  • rounded (bool) – Whether to round the bounding box coordinates, type becomes int.

Returns:

A numpy array of shape (4,) representing the sanitized bounding box in the format [x_center, y_center, width, height].

Return type:

np.ndarray

tracklab.utils.coordinates.sanitize_keypoints(keypoints, image_shape=None, rounded=False)[source]

Sanitizes keypoints by clipping them to the image dimensions and ensuring that their confidence values are valid.

Parameters:
  • keypoints (np.ndarray) – A numpy array of shape (K, 2 or 3) representing the keypoints in the format (x, y, (c)).

  • image_shape (tuple) – A tuple of two integers representing the image dimensions (width, height).

  • rounded (bool) – Whether to round the keypoints to integers.

Returns:

A numpy array of shape (K, 3) representing the sanitized keypoints in the format (x, y, (c)).

Return type:

np.ndarray

tracklab.utils.coordinates.xywh_to_ltrb(bbox, image_shape=None, rounded=False)[source]

Converts coordinates [center_x, center_y, w, h] to [left, top, right, bottom]. If image_shape is provided, the bbox is clipped to the image dimensions and its dimensions are ensured to be valid.

tracklab.utils.coordinates.xywh_to_ltwh(bbox, image_shape=None, rounded=False)[source]

Converts coordinates [center_x, center_y, w, h] to [left, top, w, h]. If image_shape is provided, the bbox is clipped to the image dimensions and its dimensions are ensured to be valid.

tracklab.utils.cv2 module

class tracklab.utils.cv2.VideoReader[source]

Bases: object

set_filename(filename)[source]
tracklab.utils.cv2.colored_body_parts_overlay(img, masks, clip=True, interpolation=2, alpha=0.28, mask_threshold=0.0, weight_scale=1, rgb=False)[source]
tracklab.utils.cv2.crop_bbox_ltwh(img, bbox)[source]
tracklab.utils.cv2.cv2_load_image(file_path)[source]
tracklab.utils.cv2.draw_bbox(detection, patch, bbox_color, bbox_thickness, text_font, text_scale, text_thickness, text_color, print_confidence=False, print_id=False)[source]
tracklab.utils.cv2.draw_bpbreid_heatmaps(detection, patch, heatmaps_display_threshold)[source]
tracklab.utils.cv2.draw_ignore_region(patch, image_metadata)[source]
tracklab.utils.cv2.draw_keypoints(detection, patch, kp_color, kp_radius, kp_thickness, text_font, text_scale, text_thickness, text_color, skeleton_color, skeleton_thickness, print_confidence=False, draw_skeleton=True)[source]
tracklab.utils.cv2.draw_text(img, text, pos, fontFace, fontScale, thickness, lineType=16, color_txt=(0, 0, 0), color_bg=None, alpha_bg=1.0, alignH='l', alignV='b', darken=1.0)[source]
tracklab.utils.cv2.final_patch(patch)[source]
tracklab.utils.cv2.overlay_heatmap(img, heatmap, weight=0.5, mask_threshold=0.0, color_map=2, rgb=False)[source]

Overlay a heatmap on an image with given color map. :param img: input image in OpenCV BGR format :param heatmap: heatmap to overlay in float from range 0->1. Will be resized to image size and values clipped to 0->1. :param weight: alpha blending weight between image and heatmap, 1-weight for image and weight for heatmap. Set to -1 to :param use the heatmap as alpha channel.: :param color_map: OpenCV type colormap to use for heatmap. :param mask_threshold: heatmap values below this threshold will not be displayed. :param rgb: if True, the heatmap will be converted to RGB before overlaying.

Returns:

Image with heatmap overlayed.

tracklab.utils.cv2.print_count_frame(patch, frame, nframes)[source]
tracklab.utils.cv2.scale_lightness(rgb, scale_l=1.4)[source]

tracklab.utils.easyocr module

tracklab.utils.easyocr.bbox_easyocr_to_image_ltwh(easy_ocr_bbox, bbox_tlwh)[source]

tracklab.utils.instantiate module

tracklab.utils.instantiate.call_target(_target_: Callable[[...], Any], _partial_: bool, args: Tuple[Any, ...], kwargs: Dict[str, Any], full_key: str) Any[source]

Call target (type) with args and kwargs.

tracklab.utils.monkeypatch_hydra module

tracklab.utils.monkeypatch_hydra.new_call_target(_target_: Callable[[...], Any], _partial_: bool, args: Tuple[Any, ...], kwargs: Dict[str, Any], full_key: str) Any[source]

Call target (type) with args and kwargs.

tracklab.utils.monkeypatch_hydra.new_resolve_target(target: str | type | Callable[[...], Any], full_key: str) type | Callable[[...], Any][source]

Resolve target string, type or callable into type or callable.

tracklab.utils.notebook module

class tracklab.utils.notebook.TrackEngine(cfg, engine, state, evaluator, dataset)

Bases: tuple

cfg

Alias for field number 0

dataset

Alias for field number 4

engine

Alias for field number 1

evaluator

Alias for field number 3

state

Alias for field number 2

tracklab.utils.notebook.load_from_overrides(overrides=[]) TrackEngine[source]

Load everything as in main(), but from notebook.

Use with ::

import os import sys sys.path.append(os.getcwd()+”/..”) from tracklab.utils import load_from_overrides

load_from_overrides([“train_detect=false”])

Parameters:

overrides – list of strings as used in hydra commandline

Returns:

a tuple containing : cfg, engine, state, evaluator, dataset

Return type:

track_engine

tracklab.utils.openmmlab module

tracklab.utils.openmmlab.get_checkpoint(path_to_checkpoint, download_url)[source]
tracklab.utils.openmmlab.get_config_path(package, config_name)[source]

tracklab.utils.progressbar module

tracklab.utils.wandb module

tracklab.utils.wandb.apply_recursively(d, f=<function <lambda>>, filter=<function <lambda>>, always_filter=False)[source]

Apply a function to leaf values of a dict recursively and/or filter dict

Parameters:
  • f – function taking the value of a leaf as argument and returning a transformation of that value

  • filter – condition to apply f to only (sub-)branches of the tree

  • always_filter – if true filter sub-branches, if false only filter leaves.

Returns:

transformed and filtered dict

tracklab.utils.wandb.finish()[source]
tracklab.utils.wandb.init(cfg)[source]
tracklab.utils.wandb.log(res_dict)[source]
tracklab.utils.wandb.log_metric(res_dict, name, video_dict=None)[source]
tracklab.utils.wandb.normalize_subdict(subdict)[source]