提交 717ca98d 编写于 作者: J Jeremy Meredith 提交者: TensorFlower Gardener

Adding missing requirement on inputs for MirrorPadGrad op and updating...

Adding missing requirement on inputs for MirrorPadGrad op and updating arithmetic to account for int32 padding values.

PiperOrigin-RevId: 480691952
上级 f82f6ca6
......@@ -297,13 +297,21 @@ class MirrorPadGradOp : public OpKernel {
TensorShape output_shape;
typename TTypes<Tpaddings>::ConstMatrix paddings = in1.matrix<Tpaddings>();
for (int d = 0; d < dims; ++d) {
const Tpaddings before = paddings(d, 0); // Pad before existing elements.
const Tpaddings after = paddings(d, 1); // Pad after existing elements.
const int64_t before = paddings(d, 0); // Pad before existing elements.
const int64_t after = paddings(d, 1); // Pad after existing elements.
OP_REQUIRES(context, before >= 0 && after >= 0,
errors::InvalidArgument(
"Paddings must be non-negative: ", before, ", ", after));
const int64_t out_size = in0.dim_size(d) - (before + after);
const int64_t in_size = in0.dim_size(d);
const int64_t total_padding = before + after;
OP_REQUIRES(
context, total_padding < in_size && total_padding >= 0,
errors::InvalidArgument(
"Total paddings must be less than the input dimension size: ",
total_padding, " was not less than ", in_size));
const int64_t out_size = in_size - total_padding;
if (offset_ == 0) { // SYMMETRIC mode.
OP_REQUIRES(context, before <= out_size && after <= out_size,
errors::InvalidArgument("paddings must be no greater "
......
......@@ -1617,6 +1617,21 @@ class PadTest(test_util.TensorFlowTestCase):
[[0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 2, 3, 0, 0],
[0, 0, 4, 5, 6, 0, 0], [0, 0, 0, 0, 0, 0, 0]])
# b/246325518: Bad shape size. Explicitly testing different execution paths.
def testInvalidMirrorPadGradEagerMode(self):
with context.eager_mode():
with self.assertRaises(Exception):
gen_array_ops.MirrorPadGrad(
input=[1], paddings=[[0x77f00000, 0xa000000]], mode="REFLECT")
# b/246325518: Bad shape size. Explicitly testing different execution paths.
def testInvalidMirrorPadGradGraphMode(self):
with context.graph_mode():
with self.assertRaises(Exception):
result = gen_array_ops.MirrorPadGrad(
input=[1], paddings=[[0x77f00000, 0xa000000]], mode="REFLECT")
self.evaluate(result)
def testSymmetricMirrorPadGrad(self):
t = np.broadcast_to(np.arange(0, 7), (3, 2, 1, 7))
paddings = constant_op.constant([
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册