mindspore.nn.ImageGradients

class mindspore.nn.ImageGradients[源代码]

Returns two tensors, the first is along the height dimension and the second is along the width dimension.

Assume an image shape is hw. The gradients along the height and the width are dy and dx, respectively.

dy[i]={image[i+1,:]image[i,:],if 0<=i<h10,if i==h1dx[i]={image[:,i+1]image[:,i],if 0<=i<w10,if i==w1
Inputs:
  • images (Tensor) - The input image data, with format ‘NCHW’.

Outputs:
  • dy (Tensor) - vertical image gradients, the same type and shape as input.

  • dx (Tensor) - horizontal image gradients, the same type and shape as input.

Raises

ValueError – If length of shape of images is not equal to 4.

Supported Platforms:

Ascend GPU CPU

Examples

>>> net = nn.ImageGradients()
>>> image = Tensor(np.array([[[[1, 2], [3, 4]]]]), dtype=mindspore.int32)
>>> output = net(image)
>>> print(output)
(Tensor(shape=[1, 1, 2, 2], dtype=Int32, value=
[[[[2, 2],
   [0, 0]]]]), Tensor(shape=[1, 1, 2, 2], dtype=Int32, value=
[[[[1, 0],
   [1, 0]]]]))