mindspore.dataset.vision.AdjustSharpness
- class mindspore.dataset.vision.AdjustSharpness(sharpness_factor)[源代码]
调整输入图像的锐度。
支持 Ascend 硬件加速,需要通过 .device("Ascend") 方式开启。
- 参数:
sharpness_factor (float) - 锐度调节因子,需为非负数。输入
0
值将得到模糊图像,1
值将得到原始图像,2
值将调整图像锐度为原来的2倍。
- 异常:
TypeError - 如果 sharpness_factor 不是float类型。
ValueError - 如果 sharpness_factor 小于0。
RuntimeError - 如果输入图像的形状不是<H, W, C>或<H, W>。
- 支持平台:
CPU
Ascend
样例:
>>> import numpy as np >>> import mindspore.dataset as ds >>> import mindspore.dataset.vision as vision >>> >>> # Use the transform in dataset pipeline mode >>> # create a dataset that reads all files in dataset_dir with 8 threads >>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8) >>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"]) >>> transforms_list = [vision.AdjustSharpness(sharpness_factor=2.0)] >>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"]) >>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True): ... print(item["image"].shape, item["image"].dtype) ... break (100, 100, 3) uint8 >>> >>> # 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)) >>> output = vision.AdjustSharpness(sharpness_factor=0)(data) >>> print(output.shape, output.dtype) (3, 4) uint8
- 教程样例:
- device(device_target='CPU')[源代码]
指定该变换执行的设备。
当执行设备是 Ascend 时,输入数据支持 uint8 或者 float32 类型,输入数据的通道仅支持1和3。输入数据的高度限制范围为[4, 8192]、宽度限制范围为[6, 4096]。
- 参数:
device_target (str, 可选) - 算子将在指定的设备上运行。当前支持
CPU
和Ascend
。默认值:CPU
。
- 异常:
TypeError - 当 device_target 的类型不为str。
ValueError - 当 device_target 的取值不为
CPU
/Ascend
。
- 支持平台:
CPU
Ascend
样例:
>>> import numpy as np >>> import mindspore.dataset as ds >>> import mindspore.dataset.vision as vision >>> >>> # Use the transform in dataset pipeline mode >>> # create a dataset that reads all files in dataset_dir with 8 threads >>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8) >>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"]) >>> transforms_list = [vision.AdjustSharpness(sharpness_factor=2.0).device("Ascend")] >>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"]) >>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True): ... print(item["image"].shape, item["image"].dtype) ... break (100, 100, 3) uint8 >>> >>> # Use the transform in eager mode >>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8) >>> output = vision.AdjustSharpness(sharpness_factor=0).device("Ascend")(data) >>> print(output.shape, output.dtype) (100, 100, 3) uint8