class mindspore.ops.CheckValid[源代码]

Checks bounding box.

Checks whether the bounding box cross data and data border are valid.


specifying the valid boundary (heights x ratio, weights x ratio).

  • bboxes (Tensor) - Bounding boxes tensor with shape (N, 4). “N” indicates the number of bounding boxes, the value “4” indicates “x0”, “x1”, “y0”, and “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, width * ratio). Data type must be float16 or float32.


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.

  • 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


>>> import mindspore
>>> import mindspore.nn as nn
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> class Net(nn.Cell):
...     def __init__(self):
...         super(Net, self).__init__()
...         self.check_valid = ops.CheckValid()
...     def construct(self, x, y):
...         valid_result = self.check_valid(x, y)
...         return valid_result
>>> bboxes = Tensor(np.linspace(0, 6, 12).reshape(3, 4), mindspore.float32)
>>> img_metas = Tensor(np.array([2, 1, 3]), mindspore.float32)
>>> net = Net()
>>> output = net(bboxes, img_metas)
>>> print(output)
[ True False False]