mindspore.dataset.vision.BoundingBoxAugment
- class mindspore.dataset.vision.BoundingBoxAugment(transform, ratio=0.3)[source]
Apply a given image processing operation on a random selection of bounding box regions of a given image.
- Parameters
transform (TensorOperation) – Transformation operation to be applied on random selection of bounding box regions of a given image.
ratio (float, optional) – Ratio of bounding boxes to apply augmentation on. Range: [0.0, 1.0]. Default:
0.3
.
- Raises
TypeError – If transform is an image processing operation in mindspore.dataset.vision .
TypeError – If ratio is not of type float.
ValueError – If ratio is not in range [0.0, 1.0].
RuntimeError – If given bounding box is invalid.
- Supported Platforms:
CPU
Examples
>>> import numpy as np >>> import mindspore.dataset as ds >>> import mindspore.dataset.vision as vision >>> >>> # Use the transform in dataset pipeline mode >>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.float32) >>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"]) >>> func = lambda img: (data, np.array([[0, 0, data.shape[1], data.shape[0]]]).astype(np.float32)) >>> numpy_slices_dataset = numpy_slices_dataset.map(operations=[func], ... input_columns=["image"], ... output_columns=["image", "bbox"]) >>> # set bounding box operation with ratio of 1 to apply rotation on all bounding boxes >>> bbox_aug_op = vision.BoundingBoxAugment(vision.RandomRotation(90), 1) >>> # map to apply ops >>> numpy_slices_dataset = numpy_slices_dataset.map(operations=[bbox_aug_op], ... input_columns=["image", "bbox"], ... output_columns=["image", "bbox"]) >>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True): ... print(item["image"].shape, item["image"].dtype) ... print(item["bbox"].shape, item["bbox"].dtype) ... break (100, 100, 3) float32 (1, 4) float32 >>> >>> # Use the transform in eager mode >>> data = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((3, 4)) >>> data = data.astype(np.float32) >>> func = lambda img, bboxes: (data, np.array([[0, 0, data.shape[1], data.shape[0]]]).astype(bboxes.dtype)) >>> func_data, func_bboxes = func(data, data) >>> output = vision.BoundingBoxAugment(transforms.Fill(100), 1.0)(func_data, func_bboxes) >>> print(output[0].shape, output[0].dtype) (3, 4) float32 >>> print(output[1].shape, output[1].dtype) (1, 4) float32
- Tutorial Examples: