From 15f6c30d7977c92ba452eb5c1873b8c9f0968a5f Mon Sep 17 00:00:00 2001 From: Martin Wicke Date: Wed, 26 Jun 2019 17:13:12 -0700 Subject: [PATCH] Change keras.layers.Upsampling2D to use new image resizing function (resize_images_v2). The old resizing function has various bugs (for instance, it was not reflection or translation invariant). Fixes #29856. PiperOrigin-RevId: 255296104 --- tensorflow/python/keras/backend.py | 6 ++++-- tensorflow/python/ops/image_ops_impl.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tensorflow/python/keras/backend.py b/tensorflow/python/keras/backend.py index 11c855aa070..6dc31a42a84 100644 --- a/tensorflow/python/keras/backend.py +++ b/tensorflow/python/keras/backend.py @@ -2610,9 +2610,11 @@ def resize_images(x, height_factor, width_factor, data_format, if data_format == 'channels_first': x = permute_dimensions(x, [0, 2, 3, 1]) if interpolation == 'nearest': - x = image_ops.resize_nearest_neighbor(x, new_shape) + x = image_ops.resize_images_v2( + x, new_shape, method=image_ops.ResizeMethod.NEAREST_NEIGHBOR) elif interpolation == 'bilinear': - x = image_ops.resize_bilinear(x, new_shape) + x = image_ops.resize_images_v2(x, new_shape, + method=image_ops.ResizeMethod.BILINEAR) else: raise ValueError('interpolation should be one ' 'of "nearest" or "bilinear".') diff --git a/tensorflow/python/ops/image_ops_impl.py b/tensorflow/python/ops/image_ops_impl.py index c6e11edb347..f1164d5adbd 100644 --- a/tensorflow/python/ops/image_ops_impl.py +++ b/tensorflow/python/ops/image_ops_impl.py @@ -1209,7 +1209,7 @@ def resize_images_v2(images, `tf.image.resize_with_pad`. When 'antialias' is true, the sampling filter will anti-alias the input image - as well as interpolate. When downsampling an image with [anti-aliasing]( + as well as interpolate. When downsampling an image with [anti-aliasing]( https://en.wikipedia.org/wiki/Spatial_anti-aliasing) the sampling filter kernel is scaled in order to properly anti-alias the input image signal. 'antialias' has no effect when upsampling an image.