docstr: Using Sobel to compute gradient. Return the magnitude.
docstr_tok: ["Using","Sobel","to","compute","gradient",".","Return","the","magnitude","."]
code: def sobel(self, input):
      """Using Sobel to compute gradient. Return the magnitude."""
      if not len(input.shape) == 4:
          raise ValueError(
              "Invalid input shape, we expect NCHW, but it is ",
              input.shape,
          )
  
      n, c, h, w = input.shape
  
      input_pad = paddle.reshape(input, (n * c, 1, h, w))
      input_pad = F.pad(input_pad, pad=[1, 1, 1, 1], mode="replicate")
  
      grad_x = F.conv2d(input_pad, self.kernel_x, padding=0)
      grad_y = F.conv2d(input_pad, self.kernel_y, padding=0)
  
      mag = paddle.sqrt(grad_x * grad_x + grad_y * grad_y + self.eps)
      mag = paddle.reshape(mag, (n, c, h, w))
  
      return mag
  
imports: import paddle
  import paddle.nn
  import paddle.nn.functional
  from paddleseg.cvlibs import manager
  import cv2
label_desc: Use image node_id 3 for calling the GradientLoss obj's underlying member method code with example usage: obj.sobel(input) and returns: mag