mindspore.ops.ExtractGlimpse

class mindspore.ops.ExtractGlimpse(centered=True, normalized=True, uniform_noise=True, noise='uniform')[source]

Extracts glimpse from the input image tensor and return a window.

Note

If the window and input image tensor not overlap, random noise is filled.

Parameters
  • centered (bool, optional) – An optional bool. Indicates if the offset coordinates are centered relative to the image, in which case the (0, 0) offset is relative to the center of the center of the input images. If false, the (0, 0) offset corresponds to the upper left corner of the input images. Defaults to True.

  • normalized (bool, optional) – An optional bool. indicates if the offset coordinates are normalized. Defaults to True.

  • uniform_noise (bool, optional) – An optional bool. indicates if the noise should be generated using a uniform distribution or a Gaussian distribution. Defaults to True.

  • noise (str, optional) – An optional string. The value can be ‘uniform’, ‘gaussian’ and ‘zero’. The window is determined by size and offsets. When the window and input image tensor not overlap, random noise is filled. The result is variable when noise is equal to ‘uniform’ and ‘gaussian’. When noise is equal to ‘zero’, the value of uniform_noise must be ‘False’ and the filling noise will be zero so that the result is fixed. When uniform_noise is ‘True’, the value of noise only can be ‘uniform’. When uniform_noise is ‘False’, the value of noise can be ‘uniform’, ‘gaussian’ and ‘zero’. Defaults to uniform.

Inputs:
  • x (Tensor) - A 4-D float tensor of shape [batch_size, height, width, channels]. Types allowed: float32.

  • size (Tensor) - A 1-D tensor of 2 elements containing the size of the glimpses to extract. The glimpse height must be specified first, following by the glimpse width. Types allowed: int32. The value of size must be greater than zero.

  • offsets (Tensor) - A 2-D integer tensor of shape [batch_size, 2] containing the y, x locations of the center of each window. Types allowed: float32.

Outputs:

A 4-D tensor of shape [batch_size, glimpse_height, glimpse_width, channels] with type: float32.

Raises
  • TypeError – If centered is not a bool.

  • TypeError – If normalize is not a bool.

  • TypeError – If uniform_noise is not a bool.

  • ValueError – If noise is not uniform, gaussian or zero.

  • ValueError – If the value of size is not constant value.

  • ValueError – If the batch_size of input is inconsistent with the batch_size of offsets.

  • ValueError – If the value of offsets[1] is not 2.

  • ValueError – If the input is not Tensor.

Supported Platforms:

GPU CPU

Examples

>>> x = Tensor([[[[0.0], [1.0], [2.0]], [[3.0], [4.0], [5.0]], [[6.0], [7.0], [8.0]]]], dtype=mindspore.float32)
>>> size = Tensor((2, 2), dtype=mindspore.int32)
>>> offsets = Tensor([[1, 1]], dtype=mindspore.float32)
>>> ops = P.image_ops.ExtractGlimpse(centered = False, normalized = False,
>>>                                  uniform_noise = False, noise = "uniform")
>>> output = ops(x, size, offsets)
>>> print(output)
[[[[0.]
   [1.]]
  [[3.]
   [4.]]]]