ReAlign

class lib.infer.align.ReAlign(enabled: bool, plugin: ExtractPlugin, margin: float)

Bases: object

Handles re-aligning faces based on first-pass results

Parameters:
  • enabled (bool) – True if realigns are to be performed

  • plugin (ExtractPlugin) – The plugin that will be processing re-aligns

  • margin (float) – The % amount that re-feed allows bounding box points to drift

Attributes Summary

default_crop_matrices

The default crop matrices used for calculating re-feeds

Methods Summary

__call__(batch, landmarks, iteration)

Process the outputs from the plugin when re-aligning data

get_images(matrices, feeds)

Obtain the sub-crops from the main image patches based on the roi stored in the batch and populate them to the batch's data attribute

Attributes Documentation

default_crop_matrices

The default crop matrices used for calculating re-feeds

Methods Documentation

__call__(batch: ExtractBatch, landmarks: npt.NDArray[np.float32], iteration: int) None

Process the outputs from the plugin when re-aligning data

Is called twice.
  • First pass: aligns the image based on the first pass landmarks, stores image patches

that next pass’ feed will be generated from and creates ROI boxes for this aligned patch - 2nd pass: Rotates detections back to frame alignment and updates the ROI to correctly scale and shift the alignments back to frame space downstream

Parameters:
  • batch (ExtractBatch) – The batch object being processed for re-aligns

  • landmarks (npt.NDArray[np.float32]) – The (x, y) detected landmarks for a batch in mean-space

  • iteration (int) – The re-align iteration that is being request. Either 1 or 2

Return type:

None

get_images(matrices: npt.NDArray[np.float32], feeds: int) npt.NDArray[np.float32]

Obtain the sub-crops from the main image patches based on the roi stored in the batch and populate them to the batch’s data attribute

Parameters:
  • matrices (npt.NDArray[np.float32]) – The matrices that define the crops to extract from the expanded patch in shape (N x total_feeds, 3, 3)

  • feeds (int) – The number of feeds that are to be made through the model for this batch

Return type:

The aligned images that are to be used for 2nd pass re-align

__call__(batch: ExtractBatch, landmarks: npt.NDArray[np.float32], iteration: int) None

Process the outputs from the plugin when re-aligning data

Is called twice.
  • First pass: aligns the image based on the first pass landmarks, stores image patches

that next pass’ feed will be generated from and creates ROI boxes for this aligned patch - 2nd pass: Rotates detections back to frame alignment and updates the ROI to correctly scale and shift the alignments back to frame space downstream

Parameters:
  • batch (ExtractBatch) – The batch object being processed for re-aligns

  • landmarks (npt.NDArray[np.float32]) – The (x, y) detected landmarks for a batch in mean-space

  • iteration (int) – The re-align iteration that is being request. Either 1 or 2

Return type:

None

property default_crop_matrices: npt.NDArray[np.float32]

The default crop matrices used for calculating re-feeds

enabled

True if re-aligns are enabled

get_images(matrices: npt.NDArray[np.float32], feeds: int) npt.NDArray[np.float32]

Obtain the sub-crops from the main image patches based on the roi stored in the batch and populate them to the batch’s data attribute

Parameters:
  • matrices (npt.NDArray[np.float32]) – The matrices that define the crops to extract from the expanded patch in shape (N x total_feeds, 3, 3)

  • feeds (int) – The number of feeds that are to be made through the model for this batch

Return type:

The aligned images that are to be used for 2nd pass re-align

iterations

The total number of iterations through the align process required for the selected re-align configuration