mindspore.dataset.vision.LinearTransformation

class mindspore.dataset.vision.LinearTransformation(transformation_matrix, mean_vector)[源代码]

使用指定的变换方阵和均值向量对输入numpy.ndarray图像进行线性变换。

先将输入图像展平为一维,从中减去均值向量,然后计算其与变换方阵的点积,最后再变形回原始shape。

参数:
  • transformation_matrix (numpy.ndarray) - shape为(D, D)的变换方阵,其中

    \(D = C \times H \times W\)

  • mean_vector (numpy.ndarray) - shape为(D,)的均值向量,其中

    \(D = C \times H \times W\)

异常:
  • TypeError - 当 transformation_matrix 的类型不为 numpy.ndarray

  • TypeError - 当 mean_vector 的类型不为 numpy.ndarray

支持平台:

CPU

样例:

>>> import numpy as np
>>> from mindspore.dataset.transforms import Compose
>>>
>>> height, width = 32, 32
>>> dim = 3 * height * width
>>> transformation_matrix = np.ones([dim, dim])
>>> mean_vector = np.zeros(dim)
>>> transforms_list = Compose([vision.Decode(to_pil=True)),
...                            vision.Resize((height,width)),
...                            vision.ToTensor(),
...                            vision.LinearTransformation(transformation_matrix, mean_vector)])
>>> # apply the transform to dataset through map function
>>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list,
...                                                 input_columns="image")