mindspore.dataset.vision.RandomGrayscale

class mindspore.dataset.vision.RandomGrayscale(prob=0.1)[源代码]

按照指定的概率将输入PIL图像转换为灰度图。

参数:
  • prob (float,可选) - 执行灰度转换的概率,取值范围:[0.0, 1.0]。默认值: 0.1

异常:
  • TypeError - 当 prob 的类型不为float。

  • ValueError - 当 prob 取值不在[0.0, 1.0]范围内。

支持平台:

CPU

样例:

>>> import mindspore.dataset as ds
>>> import mindspore.dataset.vision as vision
>>> from mindspore.dataset.transforms import Compose
>>>
>>> transforms_list = Compose([vision.Decode(to_pil=True),
...                            vision.RandomGrayscale(0.3),
...                            vision.ToTensor()])
>>> # 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")
教程样例: