Rotator

class lib.infer.detect.Rotator(angles: str | None, image_size: int)

Bases: object

Handles pre-calculation of rotation matrices when rotation angles are requested and rotating images for feeding the detector. Handles reversing the rotation for any found detection bounding boxes.

Parameters:
  • rotation – List of requested rotation angles in degrees provided in command line arguments

  • image_size (int) – The size of the square image to obtain rotation matrices for

  • angles (str | None)

Methods Summary

rotate(rotation_index, images)

Rotate a batch of images by the matrix provided by the given rotation index.

un_rotate(indices_angle, roi)

Un-rotate the given bounding boxes for the given angle indices and update in place

Methods Documentation

rotate(rotation_index: int, images: ndarray) ndarray | None

Rotate a batch of images by the matrix provided by the given rotation index. Attempts to detect and handle channels first images as well as channels last

Parameters:
  • rotation_index (int) – The matrix to use. This will be an incrementing index from an enumerated loop that selects through the matrices stored for each angle

  • images (ndarray) – The original, correctly orientated, batch of images to rotate

Returns:

  • The batch of image rotated by the angle identified by the given rotation index.

  • None if the given rotation index is invalid

Return type:

ndarray | None

un_rotate(indices_angle: npt.NDArray[np.int32], roi: npt.NDArray[np.float32]) None

Un-rotate the given bounding boxes for the given angle indices and update in place

Parameters:
  • indices_angle (npt.NDArray[np.int32]) – The angle indices that correlate to the angle each roi was rotated to to obtain the result

  • roi (npt.NDArray[np.float32]) – Ragged array of (B, N, 4) detected bounding discovered at the corresponding angle index

Return type:

None

enabled

True if rotations are to be performed

rotate(rotation_index: int, images: ndarray) ndarray | None

Rotate a batch of images by the matrix provided by the given rotation index. Attempts to detect and handle channels first images as well as channels last

Parameters:
  • rotation_index (int) – The matrix to use. This will be an incrementing index from an enumerated loop that selects through the matrices stored for each angle

  • images (ndarray) – The original, correctly orientated, batch of images to rotate

Returns:

  • The batch of image rotated by the angle identified by the given rotation index.

  • None if the given rotation index is invalid

Return type:

ndarray | None

un_rotate(indices_angle: npt.NDArray[np.int32], roi: npt.NDArray[np.float32]) None

Un-rotate the given bounding boxes for the given angle indices and update in place

Parameters:
  • indices_angle (npt.NDArray[np.int32]) – The angle indices that correlate to the angle each roi was rotated to to obtain the result

  • roi (npt.NDArray[np.float32]) – Ragged array of (B, N, 4) detected bounding discovered at the corresponding angle index

Return type:

None