discopat.nn_models package

Submodules

discopat.nn_models.detr module

class discopat.nn_models.detr.DETRModel(net, label_map, model_parameters)[source]

Bases: NNModel

Parameters:
  • net (NeuralNet)

  • label_map (dict[str, int])

  • model_parameters (dict)

post_process(raw_predictions)[source]

Adapt the internal detector’s predictions to discopat’s format.

Parameters:

raw_predictions (list[dict[Tensor]])

Return type:

list[Box]

pre_process(frame)[source]

Prepare the frame’s array to pass through the internal detector.

Can be a neural net, a convolutional sparse encoder…

Parameters:

frame (Frame)

Return type:

Tensor

class discopat.nn_models.detr.PostProcess(*args, **kwargs)[source]

Bases: Module

Convert the model’s output into the format expected by the coco api.

forward(outputs, target_sizes)[source]

Perform the computation.

Parameters:
  • outputs (raw outputs of the model)

  • target_sizes (tensor of dimension [batch_size x 2] containing the size of each images of the batch) – For evaluation, this must be the original image size (before any data augmentation) For visualization, this should be the image size after data augment, but before padding

discopat.nn_models.faster_rcnn module

class discopat.nn_models.faster_rcnn.FasterRCNNModel(net, label_map, model_parameters)[source]

Bases: NNModel

Parameters:
  • net (NeuralNet)

  • label_map (dict[str, int])

  • model_parameters (dict)

classmethod from_dict(model_as_dict)[source]
Parameters:

model_as_dict (dict)

Return type:

Self

make_box_from_tensors(box_xyxy, label, score)[source]
Parameters:
  • box_xyxy (Tensor)

  • label (Tensor)

  • score (Tensor)

Return type:

Box

post_process(raw_predictions)[source]

Adapt the internal detector’s predictions to discopat’s format.

Parameters:

raw_predictions (list[dict[Tensor]])

Return type:

list[Box]

pre_process(frame)[source]

Prepare the frame’s array to pass through the internal detector.

Can be a neural net, a convolutional sparse encoder…

Parameters:

frame (Frame)

Return type:

Tensor

property reversed_label_map
set_device(device)[source]
Parameters:

device (ComputingDevice)

Return type:

None

to_dict()[source]
Return type:

dict

static xyxy_to_xywh(xmin, ymin, xmax, ymax)[source]
Parameters:
  • xmin (float)

  • ymin (float)

  • xmax (float)

  • ymax (float)

Return type:

tuple[float, float, float, float]

class discopat.nn_models.faster_rcnn.TorchNetBuilder[source]

Bases: object

build(model_as_dict)[source]
Parameters:

model_as_dict (dict[str, str])

Return type:

NeuralNet

discopat.nn_models.torch_box_ops module

Utilities for bounding box manipulation and GIoU.

discopat.nn_models.torch_box_ops.box_cxcywh_to_xyxy(x)[source]
discopat.nn_models.torch_box_ops.box_iou(boxes1, boxes2)[source]
discopat.nn_models.torch_box_ops.generalized_box_iou(boxes1, boxes2)[source]

Generalized IoU from https://giou.stanford.edu/.

The boxes should be in [x0, y0, x1, y1] format

Returns a [N, M] pairwise matrix, where N = len(boxes1) and M = len(boxes2)

Module contents

class discopat.nn_models.FasterRCNNModel(net, label_map, model_parameters)[source]

Bases: NNModel

Parameters:
  • net (NeuralNet)

  • label_map (dict[str, int])

  • model_parameters (dict)

classmethod from_dict(model_as_dict)[source]
Parameters:

model_as_dict (dict)

Return type:

Self

make_box_from_tensors(box_xyxy, label, score)[source]
Parameters:
  • box_xyxy (Tensor)

  • label (Tensor)

  • score (Tensor)

Return type:

Box

post_process(raw_predictions)[source]

Adapt the internal detector’s predictions to discopat’s format.

Parameters:

raw_predictions (list[dict[Tensor]])

Return type:

list[Box]

pre_process(frame)[source]

Prepare the frame’s array to pass through the internal detector.

Can be a neural net, a convolutional sparse encoder…

Parameters:

frame (Frame)

Return type:

Tensor

property reversed_label_map
set_device(device)[source]
Parameters:

device (ComputingDevice)

Return type:

None

to_dict()[source]
Return type:

dict

static xyxy_to_xywh(xmin, ymin, xmax, ymax)[source]
Parameters:
  • xmin (float)

  • ymin (float)

  • xmax (float)

  • ymax (float)

Return type:

tuple[float, float, float, float]