ExtractBatch

class lib.infer.objects.ExtractBatch(filenames: list[str] = <factory>, images: list[np.ndarray] = <factory>, sources: list[str | None] = <factory>, is_aligned: bool = False, frame_sizes: list[tuple[int, int]] | None=None, frame_metadata: list[PNGSource] | None = None, passthrough: bool = False)

Bases: object

Dataclass for holding a batch flowing through Extraction plugins.

The batch size for post Detector plugins is not the same as the overall batch size. An image may contain 0 or more detected faces, and these need to be split and recombined to be able to utilize a plugin’s internal batch size.

Parameters:
  • filenames (list[str]) – The original frame filenames for the batch

  • images (list[np.ndarray]) – The original frames

  • sources (list[str | None]) – The full path to the source folder or video file. Default: [] (Not provided)

  • is_aligned (bool) – True if images contains aligned faces. False if it contains full frames. Default: False

  • frame_sizes (list[tuple[int, int]] | None) – The original frame (height, width) dimensions that contained the aligned images when images are aligned faces. Default: None

  • frame_metadata (list[PNGSource] | None) – The original frame meta data when aligned faces is True otherwise None

  • passthrough (bool) – True` if the contents of this item are meant to pass straight through the extraction pipeline for immediate return

Attributes Summary

frame_metadata

The original frame metadata when aligned faces is True otherwise None

frame_sizes

The original frame (heights, widths) when the images are aligned faces

is_aligned

True if images contains aligned faces.

landmark_type

The landmark type found for this batch or None if not populated

landmarks

The face landmarks found for this batch in frame space or None if not populated

lengths

The number of bboxes that belong to each frame

passthrough

Whether this item should pass straight through the pipeline for immediate return

Methods Summary

append(batch)

Append the data from the given batch object to this batch object

apply_mask(mask)

Apply a boolean mask to the batch object.

from_detected_faces(faces)

Populate an ExtractBatch with the contents of a DetectedFace object.

from_frame_faces(media)

Populate a new ExtractBatch with the contents of an FrameFaces object.

Attributes Documentation

frame_metadata: list[PNGSource] | None = None

The original frame metadata when aligned faces is True otherwise None

frame_sizes: list[tuple[int, int]] | None = None

The original frame (heights, widths) when the images are aligned faces

is_aligned: bool = False

True if images contains aligned faces. False for full frames

landmark_type

The landmark type found for this batch or None if not populated

landmarks

The face landmarks found for this batch in frame space or None if not populated

lengths

The number of bboxes that belong to each frame

passthrough: bool = False

Whether this item should pass straight through the pipeline for immediate return

Methods Documentation

append(batch: ExtractBatch) None

Append the data from the given batch object to this batch object

Parameters:

batch (ExtractBatch) – The object containing data to be appended to this object

Return type:

None

apply_mask(mask: ndarray[tuple[Any, ...], dtype[bool]]) None

Apply a boolean mask to the batch object. True values are kept, False values are discarded

Parameters:

mask (ndarray[tuple[Any, ...], dtype[bool]]) – The boolean mask to apply to the object. Must be of size (num_boxes, )

Return type:

None

from_detected_faces(faces: list[DetectedFace]) None

Populate an ExtractBatch with the contents of a DetectedFace object.

Parameters:

faces (list[DetectedFace]) – The DetectedFace objects to populate this batch

Raises:

ValueError – If attempting to add detected faces without pre-populating filename and image or if bounding boxes pre-exist or if more than one frame is held in this batch

Return type:

None

classmethod from_frame_faces(media: FrameFaces) ExtractBatch

Populate a new ExtractBatch with the contents of an FrameFaces object.

Parameters:

media (FrameFaces) – The FrameFaces to populate this batch from

Return type:

A new ExtractBatch object populated from the given FrameFaces object

aligned: ExtractBatchAligned = <dataclasses._MISSING_TYPE object>

Holds the face landmarks found for this batch any any aligned data

append(batch: ExtractBatch) None

Append the data from the given batch object to this batch object

Parameters:

batch (ExtractBatch) – The object containing data to be appended to this object

Return type:

None

apply_mask(mask: ndarray[tuple[Any, ...], dtype[bool]]) None

Apply a boolean mask to the batch object. True values are kept, False values are discarded

Parameters:

mask (ndarray[tuple[Any, ...], dtype[bool]]) – The boolean mask to apply to the object. Must be of size (num_boxes, )

Return type:

None

bboxes: npt.NDArray[np.int32] = <dataclasses._MISSING_TYPE object>

The bounding boxes found for this batch

data: np.ndarray = <dataclasses._MISSING_TYPE object>

The data for this batch that has been populated by a processing step for ingestion by the next processing step. Internally populated. Cleared at the end of each plugin

filenames: list[str] = <dataclasses._MISSING_TYPE object>

The original frame filenames

frame_ids: npt.NDArray[np.int32] = <dataclasses._MISSING_TYPE object>

A mapping of each box to which frame they came from

frame_metadata: list[PNGSource] | None = None

The original frame metadata when aligned faces is True otherwise None

frame_sizes: list[tuple[int, int]] | None = None

The original frame (heights, widths) when the images are aligned faces

from_detected_faces(faces: list[DetectedFace]) None

Populate an ExtractBatch with the contents of a DetectedFace object.

Parameters:

faces (list[DetectedFace]) – The DetectedFace objects to populate this batch

Raises:

ValueError – If attempting to add detected faces without pre-populating filename and image or if bounding boxes pre-exist or if more than one frame is held in this batch

Return type:

None

classmethod from_frame_faces(media: FrameFaces) ExtractBatch

Populate a new ExtractBatch with the contents of an FrameFaces object.

Parameters:

media (FrameFaces) – The FrameFaces to populate this batch from

Return type:

A new ExtractBatch object populated from the given FrameFaces object

identities: dict[str, npt.NDArray[np.float32]] = <dataclasses._MISSING_TYPE object>

The identity matrices for face recognition found for this batch

images: list[np.ndarray] = <dataclasses._MISSING_TYPE object>

The original frames

is_aligned: bool = False

True if images contains aligned faces. False for full frames

property landmark_type: LandmarkType | None

The landmark type found for this batch or None if not populated

property landmarks: ndarray[tuple[Any, ...], dtype[float32]] | None

The face landmarks found for this batch in frame space or None if not populated

property lengths: ndarray[tuple[Any, ...], dtype[int32]]

The number of bboxes that belong to each frame

masks: dict[str, ExtractBatchMask] = <dataclasses._MISSING_TYPE object>

The masks for this batch

matrices: npt.NDArray[np.float32] = <dataclasses._MISSING_TYPE object>

Transformation matrices for taking points from model input space to frame space. Cleared at the end of each plugin

passthrough: bool = False

Whether this item should pass straight through the pipeline for immediate return

sources: list[str | None] = <dataclasses._MISSING_TYPE object>

The full paths to the source folder or video file. None if not provided