discopat.core package

Subpackages

Submodules

discopat.core.value_objects module

class discopat.core.value_objects.ComputingDevice(*values)[source]

Bases: Enum

cpu = 'cpu'
gpu = 'gpu'
class discopat.core.value_objects.DataSource(*values)[source]

Bases: Enum

local = 'local'
osf = 'osf'
class discopat.core.value_objects.Framework(*values)[source]

Bases: Enum

torch = 'torch'

Module contents

class discopat.core.Annotation(label, score)[source]

Bases: Metadata

Abstract class to represent annotations and model predictions.

Parameters:
  • label (str)

  • score (float)

classmethod printable_fields()[source]

List of the relevant fields to serialise the object.

Return type:

list[str]

abstractmethod rescale(w_ratio, h_ratio)[source]

Rescale object.

Parameters:
  • w_ratio (float) – Width ratio.

  • h_ratio (float) – Height ratio.

Return type:

None

to_dict()[source]

Serialise object to a dictionary.

Return type:

dict

property type: str

Handle for annotation types (box, keypoint, track, …).

class discopat.core.Array[source]

Bases: ABC

class discopat.core.Box(label, x, y, width, height, score)[source]

Bases: Annotation

Class to represent bounding boxes.

Parameters:
  • label (str)

  • x (float)

  • y (float)

  • width (float)

  • height (float)

  • score (float)

classmethod from_dict(data_as_dict)[source]

Make object from a dictionary.

Parameters:

data_as_dict (dict)

Return type:

Self

classmethod printable_fields()[source]

List of the relevant fields to serialise the object.

Return type:

list[str]

rescale(w_ratio, h_ratio)[source]

Rescale object.

Parameters:
  • w_ratio (float) – Width ratio.

  • h_ratio (float) – Height ratio.

Return type:

None

property xmax: float

Xmax for XYXY format.

property xmin: float

Xmin for XYXY format.

property ymax: float

Ymax for XYXY format.

property ymin: float

Ymin for XYXY format.

class discopat.core.CDModel[source]

Bases: Model

Abstract class representing convolutional-dictionary-based models.

class discopat.core.ComputingDevice(*values)[source]

Bases: Enum

cpu = 'cpu'
gpu = 'gpu'
class discopat.core.DataLoader(*args, **kwargs)[source]

Bases: Protocol[X_co, Y_co]

Generic interface for objects yielding (X, y) pairs.

property batch_size: int | None

Return the number of samples per batch, if known.

property dataset: Dataset[X_co, Y_co]

Return the underlying dataset from which batches are drawn.

class discopat.core.DataSource(*values)[source]

Bases: Enum

local = 'local'
osf = 'osf'
class discopat.core.Dataset(*args, **kwargs)[source]

Bases: Protocol[X_co, Y_co]

A dataset providing indexed access to samples.

class discopat.core.Frame(name, width, height, annotations, image_array=None)[source]

Bases: Metadata

Class to model movie frames or images.

Parameters:
  • name (str)

  • width (int)

  • height (int)

  • annotations (list[Annotation])

  • image_array (Array)

classmethod from_dict(data_as_dict)[source]

Make object from a dictionary.

Parameters:

data_as_dict (dict)

Return type:

Self

classmethod printable_fields()[source]

List of the relevant fields to serialise the object.

Return type:

list[str]

resize(target_width, target_height)[source]

Resize the image to (target_width, target_height).

Parameters:
  • target_width (int)

  • target_height (int)

Return type:

None

to_dict()[source]

Serialise object to a dictionary.

Return type:

dict

class discopat.core.Framework(*values)[source]

Bases: Enum

torch = 'torch'
class discopat.core.Keypoint(label, point_list, score)[source]

Bases: Annotation

Class to represent keypoint annotations (e.g., for pose estimation).

Parameters:
  • label (str)

  • point_list (list[tuple[float, float]])

  • score (float)

classmethod from_dict(data_as_dict)[source]

Make object from a dictionary.

Parameters:

data_as_dict (dict)

Return type:

Self

classmethod printable_fields()[source]

List of the relevant fields to serialise the object.

Return type:

list[str]

rescale(w_ratio, h_ratio)[source]

Rescale object.

Parameters:
  • w_ratio (float) – Width ratio.

  • h_ratio (float) – Height ratio.

Return type:

None

class discopat.core.Model[source]

Bases: ABC

Abstract class to represent a pattern detection model.

abstractmethod classmethod from_dict(model_as_dict)[source]
Parameters:

model_as_dict (dict)

Return type:

Self

abstractmethod post_process(raw_predictions)[source]

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

Parameters:

raw_predictions (Any)

Return type:

list[Annotation]

abstractmethod 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:

Array

abstractmethod predict(frame)[source]

Run the predictions of the model on a frame.

Parameters:

frame (Frame) – Object representing the image or movie frame on which the model will be applied.

Returns:

The input frame where the model predictions have been

appended to the list of already present annotations.

Return type:

Frame

abstractmethod to_dict()[source]
Return type:

dict

class discopat.core.Movie(name, frames, tracks)[source]

Bases: Metadata

Parameters:
  • name (str)

  • frames (list[Frame])

  • tracks (list[Track])

classmethod from_dict(data_as_dict)[source]

Make object from a dictionary.

Parameters:

data_as_dict (dict)

Return type:

Self

classmethod printable_fields()[source]

List of the relevant fields to serialise the object.

Return type:

list[str]

to_coco(image_file_extension='png')[source]

Convert movie to COCO annotation format.

Parameters:

image_file_extension (str)

Return type:

dict

to_dict()[source]

Serialise object to a dictionary.

Return type:

dict

class discopat.core.NNModel(net, label_map, model_parameters)[source]

Bases: Model

Abstract class representing neural-network-based models.

Parameters:
  • net (NeuralNet)

  • label_map (dict[str, int])

  • model_parameters (dict)

predict(frame)[source]

Run the predictions of the model on a frame.

The method follows the following scheme:
  • input_frame ——[pre-processing ]–> input_array,

  • input_array ——[ net ]–> raw_predictions,

  • raw_predictions –[post_processing]–> output_frame.

Parameters:

frame (Frame) – Object representing the image or movie frame on which the model will be applied.

Returns:

The input frame where the model predictions have been

appended to the list of already present annotations.

Return type:

Frame

abstractmethod set_device(device)[source]
Parameters:

device (ComputingDevice)

Return type:

None

class discopat.core.NeuralNet[source]

Bases: object

Abstract class to model a neural network.

class discopat.core.Track(track_id, box_list)[source]

Bases: Annotation

Class to represent object tracks accross frames in a movie.

Parameters:
  • track_id (int)

  • box_list (list[tuple[int, Box]])