class_docstr: Gradient-checking for ExtractImagePatches op.
class_docstr_tok: ["Gradient-checking","for","ExtractImagePatches","op","."]
code: def testGradient(self):
      # Set graph seed for determinism.
      random_seed = 42
      random_seed_lib.set_random_seed(random_seed)
  
      with self.cached_session():
          for test_case in self._TEST_CASES:
              np.random.seed(random_seed)
              in_shape = test_case["in_shape"]
              in_val = constant_op.constant(
                  np.random.random(in_shape), dtype=dtypes.float32
              )
              # Avoid `dangerous-default-value` pylint error by creating default
              # args to `extract` as tuples.
              ksizes = tuple(test_case["ksizes"])
              strides = tuple(test_case["strides"])
              rates = tuple(test_case["rates"])
  
              for padding in ["VALID", "SAME"]:
  
                  def extract(
                      in_val,
                      ksizes=ksizes,
                      strides=strides,
                      rates=rates,
                      padding=padding,
                  ):
                      return array_ops.extract_image_patches(
                          in_val, ksizes, strides, rates, padding
                      )
  
                  err = gradient_checker_v2.max_error(
                      *gradient_checker_v2.compute_gradient(
                          extract, [in_val]
                      )
                  )
                  self.assertLess(err, 1e-4)
  
imports: from absl.testing import parameterized
  import numpy
  from tensorflow.python.eager import context
  from tensorflow.python.eager.polymorphic_function import polymorphic_function
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import random_seed
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import gradient_checker
  from tensorflow.python.ops import gradient_checker_v2
  from tensorflow.python.ops import variables
  from tensorflow.python.platform import test
label_desc: Use image node_id 1 for calling the ExtractImagePatchesGradTest obj's underlying member method code with example usage: obj.testGradient() and returns: array_ops