Skip to content

Commit

Permalink
Merge pull request #52786 from pranve/cherrypick-d81b1351da3e8c884ff8…
Browse files Browse the repository at this point in the history
…36b64458d94e4a157c15-on-r2.5

Merge pull request #51717 from yongtang:46890-tf.image.pad_to_boundin…
  • Loading branch information
mihaimaruseac committed Oct 28, 2021
2 parents 37fe2c7 + 2ba8b7a commit 5a72489
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tensorflow/core/kernels/pad_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ class PadOp : public OpKernel {
OP_REQUIRES(context, before_d >= 0 && after_d >= 0,
errors::InvalidArgument("Paddings must be non-negative: ",
before_d, " ", after_d));
const int64 size_d = in0.dim_size(d);
output_shape.AddDim(before_d + size_d + after_d);
const int64_t size_d = in0.dim_size(d);
OP_REQUIRES_OK(
context, output_shape.AddDimWithStatus(before_d + size_d + after_d));

}

// If there is no padding to be done, forward the input to output.
Expand Down
15 changes: 15 additions & 0 deletions tensorflow/python/ops/image_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2254,6 +2254,21 @@ def testNameScope(self):
y = image_ops.pad_to_bounding_box(image, 0, 0, 55, 66)
self.assertTrue(y.op.name.startswith("pad_to_bounding_box"))

def testInvalidInput(self):
# Test case for GitHub issue 46890.
if test_util.is_xla_enabled():
# TODO(b/200850176): test fails with XLA.
return
with self.session():
with self.assertRaises(errors_impl.InternalError):
v = image_ops.pad_to_bounding_box(
image=np.ones((1, 1, 1)),
target_height=5191549470,
target_width=5191549470,
offset_height=1,
offset_width=1)
self.evaluate(v)


class SelectDistortedCropBoxTest(test_util.TensorFlowTestCase):

Expand Down

0 comments on commit 5a72489

Please sign in to comment.