nvidia.dali.experimental.dynamic.bbox_rotate#
- nvidia.dali.experimental.dynamic.bbox_rotate(bboxes, labels=None, /, *, batch_size=None, device=None, angle, bbox_layout=None, bbox_normalized=None, input_shape, keep_size=None, mode=None, remove_threshold=None, shape_layout=None, size=None)#
Transforms bounding boxes so that the boxes remain in the same place in the image after the image is rotated. Boxes that land outside the image with
keep_size=Truewill be removed from the output if the fraction of the remaining box after cropping is less thanremove_threshold. Iflabelsare passed as a second argument, they will also be removed synchronously.By default, boxes are expanded when rotated to ensure the original box is fully enclosed. This can be controlled with
modewhich can either retain the original height and width withmode='fixed'or between the full expansion and original shape withmode='halfway'.Warning
Boxes should be rotated first before the image as this op requires the original image shape to calculate the rotated boxes.
Example usage is below:
boxes, labels = fn.bbox_rotate( boxes, labels, angle=angle, input_shape=image.shape(), keep_size=keep_size ) image = fn.rotate(image, angle=angle, keep_size=keep_size)
- Supported backends
‘cpu’
- Parameters:
bboxes¶ (2D Tensor/Batch of float) – Coordinates of the bounding boxes that are represented as a [N,4] 2D tensor.
labels¶ (1D or 2D Tensor/Batch of int, optional) – Class labels for the bounding boxes, [N] or [N,1]. These should be provided if
keep_size=Trueas boxes may be truncated, this ensures the corresponding class labels are also removed.
- Keyword Arguments:
angle¶ (float or Tensor/Batch of float) – Rotation angle in degrees.
bbox_layout¶ (layout str, optional, default = ‘xyXY’) – Format of the bounding box input
xyWHorxyXY.bbox_normalized¶ (bool, optional, default = True) – Input bounding boxes are in normalized [0,1] format
input_shape¶ (int or list of int or Tensor/Batch of int) –
Specifies the shape of the original image the boxes belong to.
The order of dimensions is determined by the layout that is provided in
shape_layout.keep_size¶ (bool, optional, default = False) – If true, the bounding box output coordinates will assume the image canvas size was also kept (see
nvidia.dali.fn.rotate).mode¶ (str, optional, default = ‘expand’) –
Mode of the bounding box transformation. Possible values are:
expand: expands the bounding box to definitely enclose the target, but may be larger than rotated target.fixed: retains the original size of the bounding box, but may be smaller than the rotated target.halfway: halfway between the expanded size and the original size.
Note
Modes other than
expandare not recommended for datasets with high aspect ratio boxes and high rotation angles.remove_threshold¶ (float, optional, default = 0.1) – Relative area remaining threshold for removing boxes that fall outside the image boundaries after rotation. Should be between [0-1] where 0 means no removal even if box lies outside, 1 means removal if any part of the box is outside.
shape_layout¶ (layout str, optional, default = ‘HW’) –
Determines the meaning of the dimensions provided in
input_shape.Note
If unspecified,
"HW"will be assumed, which is also compatible with"HWC"since we select H and W internally (index 0, 1).size¶ (float or list of float or Tensor/Batch of float, optional, default = []) – The output canvas size optionally specified in the associated fn.rotate.