Detection

Welcome to the documentation about the detectors.

detector

Copyright (c) 2021-2022 UCLouvain, ICTEAM Licensed under GPL-3.0 [see LICENSE for details] Written by Jonathan Samelson (2021-2022)

class Detector[source]

Bases: abc.ABC

abstract detect(org_frame: numpy.array) pytb.output.detection.Detection[source]

Performs an inference on the given frame.

Parameters

org_frame (np.array) – The given frame to infer detections

Returns

A set of detections of the detected objects

Return type

Detection

detector_factory

Copyright (c) 2021-2022 UCLouvain, ICTEAM Licensed under GPL-3.0 [see LICENSE for details] Written by Jonathan Samelson (2021-2022), Arthur Pisvin (2023)

class DetectorFactory[source]

Bases: object

static create_detector(proc_parameters: dict) pytb.detection.detector.Detector[source]

Creates a detector given a dictionary of parameters provided that the defined parameters are valid. Otherwise, an error message is given indicating the invalid parameters. Based on a model type and an implementation, it initializes the appropriate detector with the given parameters.

Parameters

proc_parameters (dict) – A dictionary describing the detector to initialize.

Returns

A concrete implementation of a Detector (e.g YOLO).

Return type

Detection

static _bboxes_2d_detector(proc_parameters: dict) pytb.detection.bboxes.bboxes_2d_detector.bboxes_2d_detector.BBoxes2DDetector[source]

Creates a BBoxes2DDetector given a dictionary of parameters. It then branches on the model type to initialize a concrete detector implementation (e.g YOLO).

static _pose_detector(proc_parameters: dict) None[source]

TODO. No implementation of pose detector yet. Creates a PoseDetector given a dictionary of parameters. It then branches on the model type to initialize a concrete detector implementation (e.g XXX).

detection_manager

Copyright (c) 2021-2022 UCLouvain, ICTEAM Licensed under GPL-3.0 [see LICENSE for details] Written by Jonathan Samelson (2021-2022)

class DetectionManager(detector: pytb.detection.detector.Detector, preprocess_parameters: dict, postprocess_parameters: dict)[source]

Bases: object

__init__(detector: pytb.detection.detector.Detector, preprocess_parameters: dict, postprocess_parameters: dict)[source]

This class is used to handle all the steps of the detection in one single detect method. Specifically, it applies the preprocess parameters, infer the detections and filters out the results using the postprocess parameters. This constructor initialize a DetectionManager provided that the preprocess and post process parameters are valid. Otherwise, an error message is given indicating the invalid parameter(s).

Parameters
  • detector (Detector) – A concrete implementation of a Detector initialized using the detector_factory.

  • preprocess_parameters (dict) – A dictionary containing the image transformation before proceeding to the detection.

  • postprocess_parameters (dict) – A dictionary containing the thresholds to filter out the results of the detection.

Returns

An initialized DetectionManager that can be called on each frame using detect method.

Return type

Detection

detect(org_frame: numpy.ndarray) pytb.output.detection.Detection[source]

Proceeds to the detection on the given frame. It first transforms the image using the preprocess parameters of this instance of DetectionManager. Then, it infers the results of the detection (see the concrete implementation of the provided detector). Finally, it filters out the result using the postprocess parameters of this instance of DetectionManager.

bboxes_2d_detector

Hereby, you find two tables that (1) list the parameters in relation with the JSON config file that can be used for each detector and (2) give details on their usage.

List of detectors and their parameters

Detector

Parameters

BackgroundSubtractor (mean/median)

contour_thresh, intensity, max_last_images

BackgroundSubtractor (frame_diff)

contour_thresh, intensity

FasterRCNN / MaskRCNN

model_path*, input_width, input_height, use_coco_weights, GPU

YOLO4 (YOLOv 2, 3, 4)

model_path, config_path, input_width, input_height, conf_thresh, nms_thresh, nms_across_classes, GPU, haf_precision

YOLO5

model_path, input_width, input_height, conf_thresh, nms_thresh, nms_across_classes, GPU

Detectron2

model_path, config_path, conf_thresh, nms_thresh, GPU

* In FasterRCNN and MAskRCNN: model_path is not needed in case use_coco_weights is true.

List of parameters and their usage

Parameter

Default value

Description

model_path

/

The path to the weight of the model to be used (e.g. for YOLOv5, ending with .pt)

config_path

/

The path to the configuration file describing the model

input_width / input_height

416

The input path of the image in the detector. This allows to setup the first layers of the network to match the image shape.

conf_thresh

0

The minimum confidence threshold of the detected objects if the implementation allows to provide one.

nms_thresh

0

The minimum non-max suppression threshold of the detected objects when the implementation allows to provide one.

nms_across_classes

true

Whether to perform the NMS algorithm across the different classes of object or separately.

GPU

false

Whether to use the GPU if available.

haf_precision

false

Whether to use the half precision capability of the recent GPU cards.

use_coco_weights

true

Whether to use the default weights available on PyTorch. If True, it will be downloading in cache automatically.

contour_thresh

3

From cv2.approxPolyDP: Specifies the approximation accuracy. This is the maximum distance between the original curve and its approximation.

intensity

50

The minimum intensity of the pixels in the foreground image.

max_last_images

50

The number of last images that will be based to determine the brackground and the foreground (either with a mean or median computation)

Copyright (c) 2021-2022 UCLouvain, ICTEAM Licensed under GPL-3.0 [see LICENSE for details] Written by Jonathan Samelson (2021-2022)

class BBoxes2DDetector(proc_parameters: dict)[source]

Bases: pytb.detection.detector.Detector, abc.ABC

__init__(proc_parameters: dict)[source]

This class encompasses the attributes that are common to most detectors of 2D bounding boxes. Initializes the detector with the given parameters.

Parameters

proc_parameters (dict) – A dictionary containing the parameters of the desired detector.

abstract detect(org_frame: numpy.array) pytb.output.bboxes_2d.BBoxes2D[source]

Performs an inference on the given frame.

Parameters

org_frame (np.array) – The given frame to infer detections

Returns

A set of 2D bounding boxes identifying detected objects of the detected objects

Return type

BBoxes2D