docstr: Tests the extended padding options of ConvLayer
docstr_tok: ["Tests","the","extended","padding","options","of","ConvLayer"]
code: def _test_extended_conv(self, orig_input, init_dict):
      """
      Tests the extended padding options of ConvLayer
      """
  
      def _w_init(shape, dtype=tf.float32, **kwargs):
          data = np.arange(
              ft.reduce(lambda prod, x: prod * x, shape, 1)
          ).astype(np.float32)
          data *= 2.374 / data.mean()
          data -= data.mean()
  
          return tf.constant(data.reshape(shape), dtype=dtype)
  
      def _b_init(shape, dtype=tf.float32, **kwargs):
          data = np.arange(shape[0]).astype(np.float32)
          data *= 0.273 / data.mean()
          data -= data.mean()
  
          return tf.constant(data.reshape(shape), dtype=dtype)
  
      init_dict["w_initializer"] = _w_init
      init_dict["b_initializer"] = _b_init
  
      conv_layer = ConvLayer(**init_dict)
      small_output = conv_layer(tf.constant(orig_input))
  
      input_shape = orig_input.shape
      multiplier = (
          init_dict["kernel_size"]
          + init_dict["dilation"]
          + init_dict["stride"]
      )
      pad = [d * multiplier for d in input_shape[1:-1]]
      paddings = [(0, 0)] + [(p, p) for p in pad] + [(0, 0)]
  
      if init_dict["padding"] == "CONSTANT":
          opts = {
              "constant_values": init_dict.get("padding_constant", 0)
          }
      else:
          opts = {}
  
      enlarged_input = np.pad(
          orig_input, paddings, init_dict["padding"].lower(), **opts
      )
  
      conv_layer.padding = "SAME"
      large_output = conv_layer(tf.constant(enlarged_input))
  
      def _extract_valid_region(output_tensor, target_tensor):
          output_shape = output_tensor.shape
          target_shape = target_tensor.shape
          extr_slices = []
          for d in range(len(target_shape)):
              opad = (output_shape[d] - target_shape[d]) // 2
              extr_slices.append(slice(opad, opad + target_shape[d]))
  
          return output_tensor[tuple(extr_slices)]
  
      assert (
          np.square(
              _extract_valid_region(enlarged_input, orig_input)
              - orig_input
          ).sum()
          <= 1e-6 * np.square(orig_input).sum()
      )
  
      with self.cached_session() as sess:
          sess.run(tf.global_variables_initializer())
  
          small_value = sess.run(small_output)
          large_value = sess.run(large_output)
  
          extr_value = _extract_valid_region(large_value, small_value)
  
          print(
              np.square(small_value - extr_value).sum()
              / np.square(extr_value).sum()
          )
  
          self.assertAllClose(small_value, extr_value, rtol=1e-3)
  
imports: from __future__ import division, absolute_import, print_function
  import functools
  import numpy
  import tensorflow
  from tensorflow.contrib.layers.python.layers import regularizers
  from niftynet.layer.convolution import ConvLayer
  from niftynet.layer.convolution import ConvolutionalLayer
  from tests.niftynet_testcase import NiftyNetTestCase
label_desc: Use image node_id 5 for calling the ConvTest obj's underlying member method code with example usage: obj._test_extended_conv(orig_input, init_dict) and returns: tf, tf, output_tensor