Skip to content
Permalink
Browse files Browse the repository at this point in the history
Merge pull request #51497 from yongtang:46914-image.resize
PiperOrigin-RevId: 391409572
Change-Id: I027c4901c9717ae7ee8266e5f57baba950b3e1e3
  • Loading branch information
tensorflower-gardener committed Aug 18, 2021
2 parents 1efc908 + 660ad5e commit e5272d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
14 changes: 9 additions & 5 deletions tensorflow/core/util/image_resizer_state.h
Expand Up @@ -143,11 +143,15 @@ struct ImageResizerState {
void ValidateAndCreateOutput(OpKernelContext* context) {
ValidateAndCalculateOutputSize(context);
if (!context->status().ok()) return;
OP_REQUIRES_OK(
context,
context->allocate_output(
0, TensorShape({batch_size, out_height, out_width, channels}),
&output));

TensorShape shape;
// Guard against shape overflow
OP_REQUIRES_OK(context, shape.AddDimWithStatus(batch_size));
OP_REQUIRES_OK(context, shape.AddDimWithStatus(out_height));
OP_REQUIRES_OK(context, shape.AddDimWithStatus(out_width));
OP_REQUIRES_OK(context, shape.AddDimWithStatus(channels));

OP_REQUIRES_OK(context, context->allocate_output(0, shape, &output));
}

int64_t batch_size;
Expand Down
8 changes: 8 additions & 0 deletions tensorflow/python/ops/image_ops_test.py
Expand Up @@ -3161,6 +3161,14 @@ def testPreserveAspectRatioSquare(self):

self._assertResizeCheckShape(x, x_shape, [320, 320], [320, 320, 3])

def testLargeDim(self):
with self.session():
with self.assertRaises(errors.InternalError):
x = np.ones((5, 1, 1, 2))
v = image_ops.resize_images_v2(x, [1610637938, 1610637938],
image_ops.ResizeMethod.BILINEAR)
_ = self.evaluate(v)


class ResizeImagesTest(test_util.TensorFlowTestCase,
parameterized.TestCase):
Expand Down

0 comments on commit e5272d4

Please sign in to comment.