Merge pull request #23592 from feihugis:Issue-23511_Eager_MaxPool3DGrad

PiperOrigin-RevId: 220829227
This commit is contained in:
TensorFlower Gardener 2018-11-09 11:02:13 -08:00
commit afc175f7b3
3 changed files with 28 additions and 1 deletions

View File

@ -114,9 +114,11 @@ cuda_py_test(
":backprop",
":context",
":test",
"//third_party/py/numpy",
"//tensorflow/python:embedding_ops",
"//tensorflow/python:array_ops",
"//tensorflow/python:control_flow_ops",
"//tensorflow/python:layers",
"//tensorflow/python:math_ops",
"//tensorflow/python:nn_ops",
"//tensorflow/python:resource_variable_ops",

View File

@ -30,6 +30,7 @@ from tensorflow.python.framework import dtypes
from tensorflow.python.framework import ops
from tensorflow.python.framework import tensor_shape
from tensorflow.python.framework import test_util
from tensorflow.python.layers.pooling import max_pooling3d
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import control_flow_ops
from tensorflow.python.ops import custom_gradient
@ -1140,5 +1141,29 @@ class BackpropTest(test.TestCase):
g = f(c)
self.assertAllEqual(self.evaluate(t.gradient(g, c)), 4.0)
@test_util.run_in_graph_and_eager_modes
def testMaxPooling3DGradient(self):
def forward(a):
r = max_pooling3d(a, pool_size=pool_size, strides=strides, padding='SAME')
return r
input_sizes = [1, 3, 2, 4, 1]
pool_size = (2, 2, 1)
strides = (1, 1, 1)
total_size = np.prod(input_sizes)
x = np.arange(1, total_size + 1, dtype=np.float32)
aa = constant_op.constant(x, shape=input_sizes, dtype=dtypes.float32)
da = backprop.gradients_function(forward)(aa)
if not context.executing_eagerly():
tf_aa = constant_op.constant(x, shape=input_sizes, dtype=dtypes.float32)
tf_max = max_pooling3d(
tf_aa, pool_size=pool_size, strides=strides, padding='SAME')
tf_da = gradients.gradients(tf_max, [tf_aa])
self.assertAllEqual(da[0], tf_da[0].eval())
if __name__ == '__main__':
test.main()

View File

@ -1853,7 +1853,7 @@ bool OpGradientDoesntRequireOutputIndices(
{"Conv3DBackpropInputV2", {true, {}}},
{"AvgPool3D", {true, {}}},
{"AvgPool3DGrad", {true, {}}},
{"MaxPool3D", {true, {}}},
{"MaxPool3D", {false, {}}},
{"MaxPool3DGrad", {true, {}}},
{"MaxPool3DGradGrad", {true, {}}},
{"BiasAdd", {true, {}}},