mindspore.dataset.vision.Resize
- class mindspore.dataset.vision.Resize(size, interpolation=Inter.LINEAR)[源代码]
- 使用给定的 - mindspore.dataset.vision.Inter插值方式,将输入图像调整至给定的尺寸大小。- 支持 Ascend 硬件加速,需要通过 .device("Ascend") 方式开启。 - 参数:
- size (Union[int, Sequence[int]]) - 图像的输出尺寸大小。若输入整型,将调整图像的较短边长度为 size ,且保持图像的宽高比不变;若输入是2元素组成的序列,其输入格式需要是 (高度, 宽度) 。 - CPU模式:通过 .device("CPU") 设定执行设备为 CPU 时,size 取值范围:[1, 16777216]。 
- Ascend模式:通过 .device("Ascend") 设定执行设备为 Ascend 时,size 取值范围:[6, 32768]。 
 
- interpolation ( - Inter, 可选) - 图像插值方法。可选值详见- mindspore.dataset.vision.Inter。 默认值:- Inter.LINEAR。- Ascend模式:通过 .device("Ascend") 设定执行设备为 Ascend 时, Inter.ANTIALIAS 、 Inter.AREA 、 Inter.PILCUBIC 插值方法不支持。 
 
 
- 异常:
- TypeError - 当 size 的类型不为int或Sequence[int]。 
- TypeError - 当 interpolation 的类型不为 - mindspore.dataset.vision.Inter。
- ValueError - 当 size 不为正数。 
- RuntimeError - 如果输入的Tensor不是 <H, W> 或 <H, W, C> 格式。 
 
- 支持平台:
- CPU- Ascend
 - 样例: - >>> import numpy as np >>> import mindspore.dataset as ds >>> import mindspore.dataset.vision as vision >>> from mindspore.dataset.vision import Inter >>> >>> # Use the transform in dataset pipeline mode >>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8) >>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"]) >>> resize_op = vision.Resize([100, 75], Inter.BICUBIC) >>> transforms_list = [resize_op] >>> 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, 75, 3) uint8 >>> >>> # Use the transform in eager mode >>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8) >>> output = vision.Resize([5, 5], Inter.BICUBIC)(data) >>> print(output.shape, output.dtype) (5, 5, 3) uint8 - 教程样例:
 - device(device_target='CPU')[源代码]
- 指定该变换执行的设备。 - 当执行设备是 Ascend 时,输入/输出数据的维度限制在[4, 6]和[32768, 32768]范围内。 - 参数:
- 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 >>> from mindspore.dataset.vision import Inter >>> >>> # Use the transform in dataset pipeline mode >>> resize_op = vision.Resize([100, 75], Inter.BICUBIC).device("Ascend") >>> transforms_list = [resize_op] >>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8) >>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"]) >>> 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, 75, 3) uint8 >>> >>> # Use the transform in eager mode >>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8) >>> output = vision.Resize([25, 25], Inter.BICUBIC).device("Ascend")(data) >>> print(output.shape, output.dtype) (25, 25, 3) uint8