mindspore.ops.bounding_box_encode

View Source On Gitee
mindspore.ops.bounding_box_encode(anchor_box, groundtruth_box, means=(0.0, 0.0, 0.0, 0.0), stds=(1.0, 1.0, 1.0, 1.0))[source]

Encode the bounding box locations, calculate the offset between the predicted bounding boxes and the real bounding boxes, and the offset will be used as a variable for the loss.

Parameters
  • anchor_box (Tensor) – Anchor boxes. The shape of anchor_box must be \((n, 4)\).

  • groundtruth_box (Tensor) – Ground truth boxes. Which has the same shape with anchor_box.

  • means (tuple, optional) – Means for encoding bounding boxes calculation. Default: (0.0, 0.0, 0.0, 0.0) .

  • stds (tuple, optional) – The standard deviations of deltas calculation. Default: (1.0, 1.0, 1.0, 1.0) .

Returns

Tensor, encoded bounding boxes. It has the same data type and shape as input anchor_box.

Raises
  • TypeError – If means or stds is not a tuple.

  • TypeError – If anchor_box or groundtruth_box is not a Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> from mindspore import Tensor, ops
>>> anchor_box = Tensor([[2, 2, 2, 3], [2, 2, 2, 3]], mindspore.float32)
>>> groundtruth_box = Tensor([[1, 2, 1, 4], [1, 2, 1, 4]], mindspore.float32)
>>> output = ops.bounding_box_encode(anchor_box, groundtruth_box, means=(0.0, 0.0, 0.0, 0.0),
...                                  stds=(1.0, 1.0, 1.0, 1.0))
>>> print(output)
[[ -1.  0.25  0.  0.40551758]
 [ -1.  0.25  0.  0.40551758]]