mindspore.dataset.vision.TenCrop

View Source On Gitee
class mindspore.dataset.vision.TenCrop(size, use_vertical_flip=False)[source]

Crop the given image into one central crop and four corners with the flipped version of these.

Parameters
  • size (Union[int, Sequence[int, int]]) – The size of the cropped image. If a single integer is provided, a square of size (size, size) will be cropped with this value. If a sequence of length 2 is provided, an image of size (height, width) will be cropped.

  • use_vertical_flip (bool, optional) – If True, flip the images vertically. Otherwise, flip them horizontally. Default: False.

Raises
  • TypeError – If size is not of type integer or sequence of integer.

  • TypeError – If use_vertical_flip is not of type boolean.

  • ValueError – If size is not positive.

Supported Platforms:

CPU

Examples

>>> import mindspore.dataset as ds
>>> import mindspore.dataset.vision as vision
>>> import numpy
>>> from mindspore.dataset.transforms import Compose
>>>
>>> transforms_list = Compose([vision.Decode(to_pil=True),
...                            vision.TenCrop(size=200),
...                            # 4D stack of 10 images
...                            lambda *images: numpy.stack([vision.ToTensor()(image) for image in images])])
>>> # apply the transform to dataset through map function
>>> image_folder_dataset = ds.ImageFolderDataset("/path/to/image_folder_dataset_directory")
>>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list,
...                                                 input_columns="image")
Tutorial Examples: