mindspore.nn.ImageGradients
- class mindspore.nn.ImageGradients[source]
Returns two tensors, the first is along the height dimension and the second is along the width dimension.
Assume an image shape is
. The gradients along the height and the width are and , respectively.- 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]]]]))