mindspore.dataset.vision.Rescale
- class mindspore.dataset.vision.Rescale(rescale, shift)[source]
Rescale the input image with the given rescale and shift. This operation will rescale the input image with: output = image * rescale + shift.
Note
This operation is executed on the CPU by default, but it is also supported to be executed on the GPU or Ascend via heterogeneous acceleration.
- Parameters
- Raises
- Supported Platforms:
CPU
GPU
Ascend
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=(1, 100, 100, 3)).astype(np.uint8) >>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"]) >>> transforms_list = [vision.Rescale(1.0 / 255.0, -1.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) float32 >>> >>> # Use the transform in eager mode >>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8) >>> output = vision.Rescale(1.0 / 255.0, -1.0)(data) >>> print(output.shape, output.dtype) (100, 100, 3) float32
- Tutorial Examples: