mindspore.ops.check_valid

mindspore.ops.check_valid(bboxes, img_metas)[source]

Checks whether the bounding box is in the image.

bboxes contain several sets of bounding boxes, each represented by two abscissa points \((x0, x1)\) and two ordinate points \((y0, y1)\) . img_metas provides information about the original image, including three parameters \((height, width, ratio)\) , which specify the valid boundary of the image.

when the following conditions are met:

\(x0 >= 0\)

\(y0 >= 0\)

\(x1 <= width * ratio - 1\)

\(y1 <= height * ratio - 1\)

the bounding box is considered to be within the image.

Warning

The bounding box specified by bboxes and the image information specified by img_metas need to be valid, i.e.: \(x0 <= x1\) , \(y0 <= y1\) , and \((height, width, ratio)\) are all positive.

Parameters
  • bboxes (Tensor) – Bounding boxes tensor with shape \((N, 4)\) . \(N\) indicates the number of bounding boxes, the value 4 indicates four coordinate points \((x0, y0, x1, y1)\) . Data type must be float16 or float32.

  • img_metas (Tensor) – Raw image size information with the format of \((height, width, ratio)\) , specifying the valid boundary \((height * ratio - 1, width * ratio - 1)\) . Data type must be float16 or float32.

Returns

Tensor, with shape of \((N,)\) and dtype of bool, specifying whether the bounding boxes is in the image. True indicates valid, while False indicates invalid.

Raises
  • TypeError – If bboxes or img_metas is not a Tensor.

  • TypeError – If dtype of bboxes or img_metas is neither float16 nor float32.

Supported Platforms:

Ascend GPU CPU

Examples

>>> bboxes = Tensor(np.linspace(0, 6, 12).reshape(3, 4), mindspore.float32)
>>> img_metas = Tensor(np.array([2, 1, 3]), mindspore.float32)
>>> output = ops.check_valid(bboxes, img_metas)
>>> print(output)
[ True False False]