예제 #1
0
 def _assertBackwardOpMatchesExpected(self,
                                      grads_np,
                                      input_shape=None,
                                      dtype=None,
                                      expected=None,
                                      large_tolerance=False):
     if input_shape is None:
         self.fail("input_shape must be specified")
     if expected is None:
         self.fail("expected must be specified")
     with self.session() as sess, self.test_scope():
         dtype = dtype or np.float32
         grads = array_ops.placeholder(np.float32)
         resized = gen_image_ops.resize_bilinear_grad(
             grads,
             np.zeros([1, input_shape[0], input_shape[1], 1], dtype=dtype),
             align_corners=True)
         out = sess.run(resized,
                        {grads: grads_np[np.newaxis, :, :, np.newaxis]})
         if large_tolerance:
             self.assertAllClose(expected[np.newaxis, :, :, np.newaxis],
                                 out,
                                 rtol=0.1,
                                 atol=0.01)
         else:
             self.assertAllCloseAccordingToType(
                 expected[np.newaxis, :, :, np.newaxis], out)
def _ResizeBilinearGrad(op, grad):
    """The derivatives for bilinear resizing.

  Args:
    op: The ResizeBilinear op.
    grad: The tensor representing the gradient w.r.t. the output.

  Returns:
    The gradients w.r.t. the input.
  """
    grad0 = gen_image_ops.resize_bilinear_grad(
        grad, op.inputs[0], align_corners=op.get_attr("align_corners"))
    return [grad0, None]
예제 #3
0
def _ResizeBilinearGrad(op, grad):
  """The derivatives for bilinear resizing.

  Args:
    op: The ResizeBilinear op.
    grad: The tensor representing the gradient w.r.t. the output.

  Returns:
    The gradients w.r.t. the input.
  """
  grad0 = gen_image_ops.resize_bilinear_grad(
      grad, op.inputs[0], align_corners=op.get_attr("align_corners"))
  return [grad0, None]
예제 #4
0
 def _assertBackwardOpMatchesExpected(self,
                                      grads_np,
                                      input_shape=None,
                                      dtype=None,
                                      expected=None):
   if input_shape is None:
     self.fail("input_shape must be specified")
   if expected is None:
     self.fail("expected must be specified")
   with self.test_session() as sess, self.test_scope():
     dtype = dtype or np.float32
     grads = array_ops.placeholder(np.float32)
     resized = gen_image_ops.resize_bilinear_grad(
         grads,
         np.zeros([1, input_shape[0], input_shape[1], 1], dtype=dtype),
         align_corners=True)
     out = sess.run(resized, {grads: grads_np[np.newaxis, :, :, np.newaxis]})
     self.assertAllCloseAccordingToType(expected[np.newaxis, :, :, np.newaxis],
                                        out)