docstr: Verifies the gradients of the erosion function.
  
  Args:
    image_shape: Input shape, [batch, in_height, in_width, channels].
    kernel_shape: Filter shape, [filter_height, filter_width, channels].
    strides: Output strides, specified as [stride_height, stride_width].
    rates: Atrous rates, specified as [rate_height, rate_width].
    padding: Padding type.
    use_gpu: Whether we are running on GPU.
docstr_tok: ["Verifies","the","gradients","of","the","erosion","function",".","Args",":","image_shape",":","Input","shape",",","[","batch",",","in_height",",","in_width",",","channels","]",".","kernel_shape",":","Filter","shape",",","[","filter_height",",","filter_width",",","channels","]",".","strides",":","Output","strides",",","specified","as","[","stride_height",",","stride_width","]",".","rates",":","Atrous","rates",",","specified","as","[","rate_height",",","rate_width","]",".","padding",":","Padding","type",".","use_gpu",":","Whether","we","are","running","on","GPU","."]
code: def _ConstructAndTestGradient(
      self, image_shape, kernel_shape, strides, rates, padding, use_gpu
  ):
      """Verifies the gradients of the erosion function.
  
      Args:
        image_shape: Input shape, [batch, in_height, in_width, channels].
        kernel_shape: Filter shape, [filter_height, filter_width, channels].
        strides: Output strides, specified as [stride_height, stride_width].
        rates: Atrous rates, specified as [rate_height, rate_width].
        padding: Padding type.
        use_gpu: Whether we are running on GPU.
      """
      assert image_shape[3] == kernel_shape[2]
  
      np.random.seed(1)  # Make it reproducible.
      image = np.random.random_sample(image_shape).astype(np.float32)
      kernel = np.random.random_sample(kernel_shape).astype(np.float32)
  
      strides = [1] + strides + [1]
      rates = [1] + rates + [1]
  
      image_tensor = constant_op.constant(
          image, shape=image_shape, name="input"
      )
      kernel_tensor = constant_op.constant(
          kernel, shape=kernel_shape, name="filter"
      )
  
      def compute_erosion2d(image_tensor, kernel_tensor):
          return nn_ops.erosion2d(
              image_tensor,
              kernel_tensor,
              strides=strides,
              rates=rates,
              padding=padding,
              name="erosion2d",
          )
  
      with test_util.device(use_gpu=use_gpu):
          with self.cached_session():
              # Small delta is necessary for argmax to remain the same.
              err1 = gradient_checker_v2.max_error(
                  *gradient_checker_v2.compute_gradient(
                      lambda x: compute_erosion2d(x, kernel_tensor),
                      [image_tensor],
                  )
              )
              err2 = gradient_checker_v2.max_error(
                  *gradient_checker_v2.compute_gradient(
                      lambda x: compute_erosion2d(image_tensor, x),
                      [kernel_tensor],
                  )
              )
              err = max(err1, err2)
  
      print("Erosion gradient error = %f" % err)
      self.assertLess(err, 1e-4)
  
imports: from absl.testing import parameterized
  import numpy
  from tensorflow.python.framework import config
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import errors_impl
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import gradient_checker_v2
  from tensorflow.python.ops import nn_ops
  import tensorflow.python.ops.nn_grad
  from tensorflow.python.platform import test
label_desc: Use image node_id 10 for calling the ErosionTest obj's underlying member method code with example usage: obj._ConstructAndTestGradient(image_shape, kernel_shape, strides, rates, padding, use_gpu) and returns: nn_ops