From 3fc2c309eaaae9440ecbe01762e6ddc0fe52c5b6 Mon Sep 17 00:00:00 2001 From: Mainak Dutta <35796546+Mainak431@users.noreply.github.com> Date: Wed, 17 Apr 2019 19:07:44 +0530 Subject: [PATCH 01/19] Adding Mean_filter_2D after restructuring --- tensorflow_addons/image/filters.py | 87 ++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/tensorflow_addons/image/filters.py b/tensorflow_addons/image/filters.py index 2017dd1f35..34122db793 100644 --- a/tensorflow_addons/image/filters.py +++ b/tensorflow_addons/image/filters.py @@ -109,3 +109,90 @@ def func2(): y = tf.cast(y, tf.int32) return y + + +@tf.function +def mean_filter_2D(image, filter_shape=(3, 3)): + """This method performs Mean Filtering on image. Filter shape can be user + given. + + This method takes both kind of images where pixel values lie between 0 to + 255 and where it lies between 0.0 and 1.0 + Args: + image: A 3D `Tensor` of type `float32` or 'int32' or 'float64' or + 'int64 and of shape`[rows, columns, channels]` + + filter_shape: Optional Argument. A tuple of 2 integers (R,C). + R is the first value is the number of rows in the filter and + C is the second value in the filter is the number of columns + in the filter. This creates a filter of shape (R,C) or RxC + filter. Default value = (3,3) + + Returns: + A 3D mean filtered image tensor of shape [rows,columns,channels] and + type 'int32'. Pixel value of returned tensor ranges between 0 to 255 + """ + + def _normalize(li): + one = tf.convert_to_tensor(1.0) + two = tf.convert_to_tensor(255.0) + + def func1(): + return li + + def func2(): + return tf.math.truediv(li, two) + + return tf.cond(tf.math.greater(ma, one), func2, func1) + + if not isinstance(filter_shape, tuple): + raise TypeError('Filter shape must be a tuple') + if len(filter_shape) != 2: + raise ValueError('Filter shape must be a tuple of 2 integers. ' + 'Got %s values in tuple' % len(filter_shape)) + filter_shapex = filter_shape[0] + filter_shapey = filter_shape[1] + if not isinstance(filter_shapex, int) or not isinstance( + filter_shapey, int): + raise TypeError('Size of the filter must be Integers') + (row, col, ch) = (image.shape[0], image.shape[1], image.shape[2]) + if row != None and col != None and ch != None: + (row, col, ch) = (int(row), int(col), int(ch)) + else: + raise TypeError( + 'All the Dimensions of the input image tensor must be Integers.') + if row < filter_shapex or col < filter_shapey: + raise ValueError( + 'No of Pixels in each dimension of the image should be more \ + than the filter size. Got filter_shape (%sx' % filter_shape[0] + + '%s).' % filter_shape[1] + ' Image Shape (%s)' % image.shape) + if filter_shapex % 2 == 0 or filter_shapey % 2 == 0: + raise ValueError('Filter size should be odd. Got filter_shape (%sx' % + filter_shape[0] + '%s)' % filter_shape[1]) + image = tf.cast(image, tf.float32) + tf_i = tf.reshape(image, [row * col * ch]) + ma = tf.math.reduce_max(tf_i) + image = _normalize(image) + + # k and l is the Zero-padding size + + listi = [] + for a in range(ch): + img = image[:, :, a:a + 1] + img = tf.reshape(img, [1, row, col, 1]) + slic = tf.image.extract_image_patches( + img, [1, filter_shapex, filter_shapey, 1], [1, 1, 1, 1], + [1, 1, 1, 1], + padding='SAME') + li = tf.reduce_mean(slic, axis=-1) + li = tf.reshape(li, [row, col, 1]) + listi.append(li) + y = tf.concat(listi[0], 2) + + for i in range(len(listi) - 1): + y = tf.concat([y, listi[i + 1]], 2) + + y *= 255 + y = tf.cast(y, tf.int32) + + return y From e5bb858f13700b10223ef3e754ccdc2273a1cfc6 Mon Sep 17 00:00:00 2001 From: Mainak Dutta <35796546+Mainak431@users.noreply.github.com> Date: Wed, 17 Apr 2019 19:10:34 +0530 Subject: [PATCH 02/19] Update filters.py --- tensorflow_addons/image/filters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_addons/image/filters.py b/tensorflow_addons/image/filters.py index 34122db793..e9825fa15c 100644 --- a/tensorflow_addons/image/filters.py +++ b/tensorflow_addons/image/filters.py @@ -112,7 +112,7 @@ def func2(): @tf.function -def mean_filter_2D(image, filter_shape=(3, 3)): +def mean_filter2d(image, filter_shape=(3, 3)): """This method performs Mean Filtering on image. Filter shape can be user given. From df155df4dca617a8a907b09156232f4d77e097a4 Mon Sep 17 00:00:00 2001 From: Mainak Dutta <35796546+Mainak431@users.noreply.github.com> Date: Wed, 17 Apr 2019 19:15:17 +0530 Subject: [PATCH 03/19] restructured version --- tensorflow_addons/image/filters_test.py | 87 +++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/tensorflow_addons/image/filters_test.py b/tensorflow_addons/image/filters_test.py index 7d4ac8a925..698144cfb8 100644 --- a/tensorflow_addons/image/filters_test.py +++ b/tensorflow_addons/image/filters_test.py @@ -19,6 +19,7 @@ import tensorflow as tf from tensorflow_addons.image import median_filter2d +from tensorflow_addons.image import mean_filter2d from tensorflow_addons.utils import test_utils @@ -109,3 +110,89 @@ def test_three_channels(self): if __name__ == "__main__": tf.test.main() + + +@test_utils.run_all_in_graph_and_eager_modes +class MeanFilter2dTest(tf.test.TestCase): + def _validateMean_2d(self, inputs, expected_values, filter_shape=(3, 3)): + + values_op = mean_filter2d(inputs) + with self.test_session(use_gpu=False) as sess: + if tf.executing_eagerly(): + expected_values = expected_values.numpy() + values = values_op.numpy() + else: + expected_values = expected_values.eval() + values = values_op.eval() + self.assertShapeEqual(values, inputs) + self.assertShapeEqual(expected_values, values_op) + self.assertAllClose(expected_values, values) + + def testfiltertuple(self): + tf_img = tf.zeros([3, 4, 3], tf.int32) + + with self.assertRaisesRegexp(TypeError, + 'Filter shape must be a tuple'): + mean_filter2d(tf_img, 3) + mean_filter2d(tf_img, 3.5) + mean_filter2d(tf_img, 'dt') + mean_filter2d(tf_img, None) + + filter_shape = (3, 3, 3) + msg = 'Filter shape must be a tuple of 2 integers. ' \ + 'Got %s values in tuple' % len(filter_shape) + with self.assertRaisesRegexp(ValueError, msg): + mean_filter2d(tf_img, filter_shape) + + with self.assertRaisesRegexp(TypeError, + 'Size of the filter must be Integers'): + mean_filter2d(tf_img, (3.5, 3)) + mean_filter2d(tf_img, (None, 3)) + + def testfiltervalue(self): + tf_img = tf.zeros([3, 4, 3], tf.int32) + + with self.assertRaises(ValueError): + mean_filter2d(tf_img, (4, 3)) + + def testDimension(self): + tf.compat.v1.disable_eager_execution() + tf_img = tf.compat.v1.placeholder(tf.int32, shape=[3, 4, None]) + tf_img1 = tf.compat.v1.placeholder(tf.int32, shape=[3, None, 4]) + tf_img2 = tf.compat.v1.placeholder(tf.int32, shape=[None, 3, 4]) + + with self.assertRaises(TypeError): + mean_filter2d(tf_img) + mean_filter2d(tf_img1) + mean_filter2d(tf_img2) + + def test_imagevsfilter(self): + tf_img = tf.zeros([3, 4, 3], tf.int32) + m = tf_img.shape[0] + no = tf_img.shape[1] + ch = tf_img.shape[2] + filter_shape = (3, 5) + with self.assertRaises(ValueError): + mean_filter2d(tf_img, filter_shape) + + def testcase(self): + tf_img = [[[0.32801723, 0.08863795, 0.79119259], + [0.35526001, 0.79388736, 0.55435993], + [0.11607035, 0.55673079, 0.99473371]], + [[0.53240645, 0.74684819, 0.33700031], + [0.01760473, 0.28181609, 0.9751476], + [0.01605137, 0.8292904, 0.56405609]], + [[0.57215374, 0.10155051, 0.64836128], + [0.36533048, 0.91401874, 0.02524159], + [0.56379134, 0.9028874, 0.19505117]]] + + tf_img = tf.convert_to_tensor(value=tf_img) + expt = [[[34, 54, 75], [38, 93, 119], [14, 69, 87]], + [[61, 82, 94], [81, 147, 144], [40, 121, 93]], + [[42, 57, 56], [58, 106, 77], [27, 82, 49]]] + expt = tf.convert_to_tensor(value=expt) + self._validateMean_2d(tf_img, expt) + + +if __name__ == "__main__": + tf.test.main() From dac45fa5189ed4eea2e8bb2c0bfeb310abf1086f Mon Sep 17 00:00:00 2001 From: Mainak Dutta <35796546+Mainak431@users.noreply.github.com> Date: Wed, 17 Apr 2019 19:20:43 +0530 Subject: [PATCH 04/19] Update README.md --- tensorflow_addons/image/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/tensorflow_addons/image/README.md b/tensorflow_addons/image/README.md index 973c53e7cd..1c262a3fad 100644 --- a/tensorflow_addons/image/README.md +++ b/tensorflow_addons/image/README.md @@ -18,6 +18,7 @@ | distort_image_ops | adjust_hsv_in_yiq | | | distort_image_ops | random_hsv_in_yiq | | | filters | median_filter2d | | +| filters | mean_filter2d | | | transform_ops | angles_to_projective_transforms | | | transform_ops | matrices_to_flat_transforms | | | transform_ops | rotate | | From f62f43320fb1c2dff01167546cecbc9962b3c8e0 Mon Sep 17 00:00:00 2001 From: Mainak Dutta <35796546+Mainak431@users.noreply.github.com> Date: Wed, 17 Apr 2019 19:24:46 +0530 Subject: [PATCH 05/19] Update __init__.py --- tensorflow_addons/image/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tensorflow_addons/image/__init__.py b/tensorflow_addons/image/__init__.py index d72aae2fea..f09631ba6d 100644 --- a/tensorflow_addons/image/__init__.py +++ b/tensorflow_addons/image/__init__.py @@ -23,5 +23,6 @@ from tensorflow_addons.image.distort_image_ops import adjust_hsv_in_yiq from tensorflow_addons.image.distort_image_ops import random_hsv_in_yiq from tensorflow_addons.image.filters import median_filter2d +from tensorflow_addons.image.filters import mean_filter2d from tensorflow_addons.image.transform_ops import rotate from tensorflow_addons.image.transform_ops import transform From f5cd352c128dbd2e2843ff8c63ee7626eceb77d9 Mon Sep 17 00:00:00 2001 From: Mainak Dutta <35796546+Mainak431@users.noreply.github.com> Date: Fri, 19 Apr 2019 20:13:16 +0530 Subject: [PATCH 06/19] update according to #192 --- tensorflow_addons/image/filters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_addons/image/filters.py b/tensorflow_addons/image/filters.py index e9825fa15c..02803abfbd 100644 --- a/tensorflow_addons/image/filters.py +++ b/tensorflow_addons/image/filters.py @@ -180,7 +180,7 @@ def func2(): for a in range(ch): img = image[:, :, a:a + 1] img = tf.reshape(img, [1, row, col, 1]) - slic = tf.image.extract_image_patches( + slic = tf.image.extract_patches( img, [1, filter_shapex, filter_shapey, 1], [1, 1, 1, 1], [1, 1, 1, 1], padding='SAME') From 409d523a8029863b3d4bd84a9816dfaef93fef1b Mon Sep 17 00:00:00 2001 From: Mainak Dutta <35796546+Mainak431@users.noreply.github.com> Date: Mon, 22 Apr 2019 20:07:12 +0530 Subject: [PATCH 07/19] Update README.md --- tensorflow_addons/image/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_addons/image/README.md b/tensorflow_addons/image/README.md index 1c262a3fad..1db80c1a47 100644 --- a/tensorflow_addons/image/README.md +++ b/tensorflow_addons/image/README.md @@ -17,8 +17,8 @@ | distance_transform_ops | euclidean_distance_transform | | | distort_image_ops | adjust_hsv_in_yiq | | | distort_image_ops | random_hsv_in_yiq | | -| filters | median_filter2d | | | filters | mean_filter2d | | +| filters | median_filter2d | | | transform_ops | angles_to_projective_transforms | | | transform_ops | matrices_to_flat_transforms | | | transform_ops | rotate | | From 9e4d3c1f70b209dd461f91fa46e20b5a7db41454 Mon Sep 17 00:00:00 2001 From: Mainak Dutta <35796546+Mainak431@users.noreply.github.com> Date: Mon, 22 Apr 2019 20:09:59 +0530 Subject: [PATCH 08/19] Update __init__.py --- tensorflow_addons/image/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_addons/image/__init__.py b/tensorflow_addons/image/__init__.py index f09631ba6d..15028405f8 100644 --- a/tensorflow_addons/image/__init__.py +++ b/tensorflow_addons/image/__init__.py @@ -22,7 +22,7 @@ from tensorflow_addons.image.distance_transform import euclidean_dist_transform from tensorflow_addons.image.distort_image_ops import adjust_hsv_in_yiq from tensorflow_addons.image.distort_image_ops import random_hsv_in_yiq -from tensorflow_addons.image.filters import median_filter2d from tensorflow_addons.image.filters import mean_filter2d +from tensorflow_addons.image.filters import median_filter2d from tensorflow_addons.image.transform_ops import rotate from tensorflow_addons.image.transform_ops import transform From 93ec7b76213df09f7b375364c834aa837c272880 Mon Sep 17 00:00:00 2001 From: Mainak Dutta <35796546+Mainak431@users.noreply.github.com> Date: Mon, 22 Apr 2019 20:22:51 +0530 Subject: [PATCH 09/19] Update filters.py --- tensorflow_addons/image/filters.py | 143 ++++++++++++++--------------- 1 file changed, 67 insertions(+), 76 deletions(-) diff --git a/tensorflow_addons/image/filters.py b/tensorflow_addons/image/filters.py index 02803abfbd..f1f1ff86fa 100644 --- a/tensorflow_addons/image/filters.py +++ b/tensorflow_addons/image/filters.py @@ -20,6 +20,20 @@ import tensorflow as tf +@tf.function +def _normalize(li): + one = tf.convert_to_tensor(1.0) + two = tf.convert_to_tensor(255.0) + + def func1(): + return li + + def func2(): + return tf.math.truediv(li, two) + + return tf.cond(tf.math.greater(ma, one), func2, func1) + + @tf.function def median_filter2d(image, filter_shape=(3, 3), name=None): """This method performs Median Filtering on image. Filter shape can be user @@ -43,18 +57,6 @@ def median_filter2d(image, filter_shape=(3, 3), name=None): type 'int32'. Pixel value of returned tensor ranges between 0 to 255 """ - def _normalize(li): - one = tf.convert_to_tensor(1.0) - two = tf.convert_to_tensor(255.0) - - def func1(): - return li - - def func2(): - return tf.math.truediv(li, two) - - return tf.cond(tf.math.greater(ma, one), func2, func1) - with tf.name_scope(name or "median_filter2d"): if not isinstance(filter_shape, tuple): raise TypeError('Filter shape must be a tuple') @@ -74,7 +76,7 @@ def func2(): 'tensor must be Integers.') if row < filter_shapex or col < filter_shapey: raise ValueError( - 'No of Pixels in each dimension of the image should be more \ + 'Number of Pixels in each dimension of the image should be more \ than the filter size. Got filter_shape (%sx' % filter_shape[0] + '%s).' % filter_shape[1] + ' Image Shape (%s)' % image.shape) if filter_shapex % 2 == 0 or filter_shapey % 2 == 0: @@ -133,66 +135,55 @@ def mean_filter2d(image, filter_shape=(3, 3)): type 'int32'. Pixel value of returned tensor ranges between 0 to 255 """ - def _normalize(li): - one = tf.convert_to_tensor(1.0) - two = tf.convert_to_tensor(255.0) - - def func1(): - return li - - def func2(): - return tf.math.truediv(li, two) - - return tf.cond(tf.math.greater(ma, one), func2, func1) - - if not isinstance(filter_shape, tuple): - raise TypeError('Filter shape must be a tuple') - if len(filter_shape) != 2: - raise ValueError('Filter shape must be a tuple of 2 integers. ' - 'Got %s values in tuple' % len(filter_shape)) - filter_shapex = filter_shape[0] - filter_shapey = filter_shape[1] - if not isinstance(filter_shapex, int) or not isinstance( - filter_shapey, int): - raise TypeError('Size of the filter must be Integers') - (row, col, ch) = (image.shape[0], image.shape[1], image.shape[2]) - if row != None and col != None and ch != None: - (row, col, ch) = (int(row), int(col), int(ch)) - else: - raise TypeError( - 'All the Dimensions of the input image tensor must be Integers.') - if row < filter_shapex or col < filter_shapey: - raise ValueError( - 'No of Pixels in each dimension of the image should be more \ - than the filter size. Got filter_shape (%sx' % filter_shape[0] + - '%s).' % filter_shape[1] + ' Image Shape (%s)' % image.shape) - if filter_shapex % 2 == 0 or filter_shapey % 2 == 0: - raise ValueError('Filter size should be odd. Got filter_shape (%sx' % - filter_shape[0] + '%s)' % filter_shape[1]) - image = tf.cast(image, tf.float32) - tf_i = tf.reshape(image, [row * col * ch]) - ma = tf.math.reduce_max(tf_i) - image = _normalize(image) - - # k and l is the Zero-padding size - - listi = [] - for a in range(ch): - img = image[:, :, a:a + 1] - img = tf.reshape(img, [1, row, col, 1]) - slic = tf.image.extract_patches( - img, [1, filter_shapex, filter_shapey, 1], [1, 1, 1, 1], - [1, 1, 1, 1], - padding='SAME') - li = tf.reduce_mean(slic, axis=-1) - li = tf.reshape(li, [row, col, 1]) - listi.append(li) - y = tf.concat(listi[0], 2) - - for i in range(len(listi) - 1): - y = tf.concat([y, listi[i + 1]], 2) - - y *= 255 - y = tf.cast(y, tf.int32) - - return y + with tf.name_scope(name or "mean_filter2d"): + if not isinstance(filter_shape, tuple): + raise TypeError('Filter shape must be a tuple') + if len(filter_shape) != 2: + raise ValueError('Filter shape must be a tuple of 2 integers. ' + 'Got %s values in tuple' % len(filter_shape)) + filter_shapex = filter_shape[0] + filter_shapey = filter_shape[1] + if not isinstance(filter_shapex, int) or not isinstance( + filter_shapey, int): + raise TypeError('Size of the filter must be Integers') + (row, col, ch) = (image.shape[0], image.shape[1], image.shape[2]) + if row != None and col != None and ch != None: + (row, col, ch) = (int(row), int(col), int(ch)) + else: + raise TypeError( + 'All the Dimensions of the input image tensor must be Integers.') + if row < filter_shapex or col < filter_shapey: + raise ValueError( + 'Number of Pixels in each dimension of the image should be more \ + than the filter size. Got filter_shape (%sx' % filter_shape[0] + + '%s).' % filter_shape[1] + ' Image Shape (%s)' % image.shape) + if filter_shapex % 2 == 0 or filter_shapey % 2 == 0: + raise ValueError('Filter size should be odd. Got filter_shape (%sx' % + filter_shape[0] + '%s)' % filter_shape[1]) + image = tf.cast(image, tf.float32) + tf_i = tf.reshape(image, [row * col * ch]) + ma = tf.math.reduce_max(tf_i) + image = _normalize(image) + + # k and l is the Zero-padding size + + listi = [] + for a in range(ch): + img = image[:, :, a:a + 1] + img = tf.reshape(img, [1, row, col, 1]) + slic = tf.image.extract_patches( + img, [1, filter_shapex, filter_shapey, 1], [1, 1, 1, 1], + [1, 1, 1, 1], + padding='SAME') + li = tf.reduce_mean(slic, axis=-1) + li = tf.reshape(li, [row, col, 1]) + listi.append(li) + y = tf.concat(listi[0], 2) + + for i in range(len(listi) - 1): + y = tf.concat([y, listi[i + 1]], 2) + + y *= 255 + y = tf.cast(y, tf.int32) + + return y From ec3e3604fc74e8d2f4f1b5d7d098b54dca545b69 Mon Sep 17 00:00:00 2001 From: Mainak Dutta <35796546+Mainak431@users.noreply.github.com> Date: Mon, 22 Apr 2019 20:27:22 +0530 Subject: [PATCH 10/19] Update filters_test.py --- tensorflow_addons/image/filters_test.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tensorflow_addons/image/filters_test.py b/tensorflow_addons/image/filters_test.py index 698144cfb8..60682eabac 100644 --- a/tensorflow_addons/image/filters_test.py +++ b/tensorflow_addons/image/filters_test.py @@ -18,8 +18,8 @@ from __future__ import print_function import tensorflow as tf -from tensorflow_addons.image import median_filter2d from tensorflow_addons.image import mean_filter2d +from tensorflow_addons.image import median_filter2d from tensorflow_addons.utils import test_utils @@ -108,10 +108,6 @@ def test_three_channels(self): self._validate_median_filter2d(tf_img, expt) -if __name__ == "__main__": - tf.test.main() - - @test_utils.run_all_in_graph_and_eager_modes class MeanFilter2dTest(tf.test.TestCase): def _validateMean_2d(self, inputs, expected_values, filter_shape=(3, 3)): From 1b5642b6cee098ffb1af7bdbfebb4622a8724324 Mon Sep 17 00:00:00 2001 From: Mainak Dutta <35796546+Mainak431@users.noreply.github.com> Date: Sun, 28 Apr 2019 19:11:46 +0530 Subject: [PATCH 11/19] according to #202 --- tensorflow_addons/image/filters_test.py | 167 ++++++++++-------------- 1 file changed, 69 insertions(+), 98 deletions(-) diff --git a/tensorflow_addons/image/filters_test.py b/tensorflow_addons/image/filters_test.py index 60682eabac..bac38fa1fd 100644 --- a/tensorflow_addons/image/filters_test.py +++ b/tensorflow_addons/image/filters_test.py @@ -23,72 +23,56 @@ from tensorflow_addons.utils import test_utils -@test_utils.run_all_in_graph_and_eager_modes -class MedianFilter2dTest(tf.test.TestCase): - def _validate_median_filter2d(self, +class MeanFilter2dTest(tf.test.TestCase): + def _validate_mean_filter2d(self, inputs, expected_values, filter_shape=(3, 3)): + output = mean_filter2d(inputs, filter_shape) + self.assertAllClose(output, expected_values) - values_op = median_filter2d(inputs) - with self.test_session(use_gpu=False) as sess: - if tf.executing_eagerly(): - expected_values = expected_values.numpy() - values = values_op.numpy() - else: - expected_values = expected_values.eval() - values = values_op.eval() - self.assertShapeEqual(values, inputs) - self.assertShapeEqual(expected_values, values_op) - self.assertAllClose(expected_values, values) - + @test_utils.run_in_graph_and_eager_modes def test_filter_tuple(self): tf_img = tf.zeros([3, 4, 3], tf.int32) - with self.assertRaisesRegexp(TypeError, - 'Filter shape must be a tuple'): - median_filter2d(tf_img, 3) - median_filter2d(tf_img, 3.5) - median_filter2d(tf_img, 'dt') - median_filter2d(tf_img, None) + for filter_shape in [3, 3.5, 'dt', None]: + with self.assertRaisesRegexp(TypeError, + 'Filter shape must be a tuple'): + mean_filter2d(tf_img, filter_shape) filter_shape = (3, 3, 3) - msg = 'Filter shape must be a tuple of 2 integers. ' \ - 'Got %s values in tuple' % len(filter_shape) + msg = ('Filter shape must be a tuple of 2 integers. ' + 'Got %s values in tuple' % len(filter_shape)) with self.assertRaisesRegexp(ValueError, msg): - median_filter2d(tf_img, filter_shape) + mean_filter2d(tf_img, filter_shape) - with self.assertRaisesRegexp(TypeError, - 'Size of the filter must be Integers'): - median_filter2d(tf_img, (3.5, 3)) - median_filter2d(tf_img, (None, 3)) + msg = 'Size of the filter must be Integers' + for filter_shape in [(3.5, 3), (None, 3)]: + with self.assertRaisesRegexp(TypeError, msg): + mean_filter2d(tf_img, filter_shape) + @test_utils.run_in_graph_and_eager_modes def test_filter_value(self): tf_img = tf.zeros([3, 4, 3], tf.int32) with self.assertRaises(ValueError): - median_filter2d(tf_img, (4, 3)) + mean_filter2d(tf_img, (4, 3)) + @test_utils.run_deprecated_v1 def test_dimension(self): - tf.compat.v1.disable_eager_execution() - tf_img = tf.compat.v1.placeholder(tf.int32, shape=[3, 4, None]) - tf_img1 = tf.compat.v1.placeholder(tf.int32, shape=[3, None, 4]) - tf_img2 = tf.compat.v1.placeholder(tf.int32, shape=[None, 3, 4]) - - with self.assertRaises(TypeError): - median_filter2d(tf_img) - median_filter2d(tf_img1) - median_filter2d(tf_img2) + for image_shape in [(3, 4, None), (3, None, 4), (None, 3, 4)]: + with self.assertRaises(TypeError): + tf_img = tf.compat.v1.placeholder(tf.int32, shape=image_shape) + mean_filter2d(tf_img) + @test_utils.run_in_graph_and_eager_modes def test_image_vs_filter(self): tf_img = tf.zeros([3, 4, 3], tf.int32) - m = tf_img.shape[0] - no = tf_img.shape[1] - ch = tf_img.shape[2] filter_shape = (3, 5) with self.assertRaises(ValueError): - median_filter2d(tf_img, filter_shape) + mean_filter2d(tf_img, filter_shape) + @test_utils.run_in_graph_and_eager_modes def test_three_channels(self): tf_img = [[[0.32801723, 0.08863795, 0.79119259], [0.35526001, 0.79388736, 0.55435993], @@ -101,77 +85,64 @@ def test_three_channels(self): [0.56379134, 0.9028874, 0.19505117]]] tf_img = tf.convert_to_tensor(value=tf_img) - expt = [[[0, 0, 0], [4, 71, 141], [0, 0, 0]], - [[83, 25, 85], [90, 190, 143], [4, 141, 49]], - [[0, 0, 0], [4, 71, 49], [0, 0, 0]]] + expt = [[[34, 54, 75], [38, 93, 119], [14, 69, 87]], + [[61, 82, 94], [81, 147, 144], [40, 121, 93]], + [[42, 57, 56], [58, 106, 77], [27, 82, 49]]] expt = tf.convert_to_tensor(value=expt) - self._validate_median_filter2d(tf_img, expt) + self._validate_mean_filter2d(tf_img, expt) + +class MedianFilter2dTest(tf.test.TestCase): + def _validate_median_filter2d(self, + inputs, + expected_values, + filter_shape=(3, 3)): + output = median_filter2d(inputs, filter_shape) + self.assertAllClose(output, expected_values) -@test_utils.run_all_in_graph_and_eager_modes -class MeanFilter2dTest(tf.test.TestCase): - def _validateMean_2d(self, inputs, expected_values, filter_shape=(3, 3)): - - values_op = mean_filter2d(inputs) - with self.test_session(use_gpu=False) as sess: - if tf.executing_eagerly(): - expected_values = expected_values.numpy() - values = values_op.numpy() - else: - expected_values = expected_values.eval() - values = values_op.eval() - self.assertShapeEqual(values, inputs) - self.assertShapeEqual(expected_values, values_op) - self.assertAllClose(expected_values, values) - - def testfiltertuple(self): + @test_utils.run_in_graph_and_eager_modes + def test_filter_tuple(self): tf_img = tf.zeros([3, 4, 3], tf.int32) - with self.assertRaisesRegexp(TypeError, - 'Filter shape must be a tuple'): - mean_filter2d(tf_img, 3) - mean_filter2d(tf_img, 3.5) - mean_filter2d(tf_img, 'dt') - mean_filter2d(tf_img, None) + for filter_shape in [3, 3.5, 'dt', None]: + with self.assertRaisesRegexp(TypeError, + 'Filter shape must be a tuple'): + median_filter2d(tf_img, filter_shape) filter_shape = (3, 3, 3) - msg = 'Filter shape must be a tuple of 2 integers. ' \ - 'Got %s values in tuple' % len(filter_shape) + msg = ('Filter shape must be a tuple of 2 integers. ' + 'Got %s values in tuple' % len(filter_shape)) with self.assertRaisesRegexp(ValueError, msg): - mean_filter2d(tf_img, filter_shape) + median_filter2d(tf_img, filter_shape) - with self.assertRaisesRegexp(TypeError, - 'Size of the filter must be Integers'): - mean_filter2d(tf_img, (3.5, 3)) - mean_filter2d(tf_img, (None, 3)) + msg = 'Size of the filter must be Integers' + for filter_shape in [(3.5, 3), (None, 3)]: + with self.assertRaisesRegexp(TypeError, msg): + median_filter2d(tf_img, filter_shape) - def testfiltervalue(self): + @test_utils.run_in_graph_and_eager_modes + def test_filter_value(self): tf_img = tf.zeros([3, 4, 3], tf.int32) with self.assertRaises(ValueError): - mean_filter2d(tf_img, (4, 3)) - - def testDimension(self): - tf.compat.v1.disable_eager_execution() - tf_img = tf.compat.v1.placeholder(tf.int32, shape=[3, 4, None]) - tf_img1 = tf.compat.v1.placeholder(tf.int32, shape=[3, None, 4]) - tf_img2 = tf.compat.v1.placeholder(tf.int32, shape=[None, 3, 4]) + median_filter2d(tf_img, (4, 3)) - with self.assertRaises(TypeError): - mean_filter2d(tf_img) - mean_filter2d(tf_img1) - mean_filter2d(tf_img2) + @test_utils.run_deprecated_v1 + def test_dimension(self): + for image_shape in [(3, 4, None), (3, None, 4), (None, 3, 4)]: + with self.assertRaises(TypeError): + tf_img = tf.compat.v1.placeholder(tf.int32, shape=image_shape) + median_filter2d(tf_img) - def test_imagevsfilter(self): + @test_utils.run_in_graph_and_eager_modes + def test_image_vs_filter(self): tf_img = tf.zeros([3, 4, 3], tf.int32) - m = tf_img.shape[0] - no = tf_img.shape[1] - ch = tf_img.shape[2] filter_shape = (3, 5) with self.assertRaises(ValueError): - mean_filter2d(tf_img, filter_shape) + median_filter2d(tf_img, filter_shape) - def testcase(self): + @test_utils.run_in_graph_and_eager_modes + def test_three_channels(self): tf_img = [[[0.32801723, 0.08863795, 0.79119259], [0.35526001, 0.79388736, 0.55435993], [0.11607035, 0.55673079, 0.99473371]], @@ -183,11 +154,11 @@ def testcase(self): [0.56379134, 0.9028874, 0.19505117]]] tf_img = tf.convert_to_tensor(value=tf_img) - expt = [[[34, 54, 75], [38, 93, 119], [14, 69, 87]], - [[61, 82, 94], [81, 147, 144], [40, 121, 93]], - [[42, 57, 56], [58, 106, 77], [27, 82, 49]]] + expt = [[[0, 0, 0], [4, 71, 141], [0, 0, 0]], + [[83, 25, 85], [90, 190, 143], [4, 141, 49]], + [[0, 0, 0], [4, 71, 49], [0, 0, 0]]] expt = tf.convert_to_tensor(value=expt) - self._validateMean_2d(tf_img, expt) + self._validate_median_filter2d(tf_img, expt) if __name__ == "__main__": From 3a15261a610a478ee8a11cf87aee06d28dcf4cc1 Mon Sep 17 00:00:00 2001 From: Mainak Dutta <35796546+Mainak431@users.noreply.github.com> Date: Sun, 28 Apr 2019 19:23:03 +0530 Subject: [PATCH 12/19] Update filters_test.py --- tensorflow_addons/image/filters_test.py | 69 +++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tensorflow_addons/image/filters_test.py b/tensorflow_addons/image/filters_test.py index 4ae3db223e..c09604a226 100644 --- a/tensorflow_addons/image/filters_test.py +++ b/tensorflow_addons/image/filters_test.py @@ -23,6 +23,75 @@ from tensorflow_addons.utils import test_utils +class MeanFilter2dTest(tf.test.TestCase): + def _validate_mean_filter2d(self, + inputs, + expected_values, + filter_shape=(3, 3)): + output = mean_filter2d(inputs, filter_shape) + self.assertAllClose(output, expected_values) + + @test_utils.run_in_graph_and_eager_modes + def test_filter_tuple(self): + tf_img = tf.zeros([3, 4, 3], tf.int32) + + for filter_shape in [3, 3.5, 'dt', None]: + with self.assertRaisesRegexp(TypeError, + 'Filter shape must be a tuple'): + mean_filter2d(tf_img, filter_shape) + + filter_shape = (3, 3, 3) + msg = ('Filter shape must be a tuple of 2 integers. ' + 'Got %s values in tuple' % len(filter_shape)) + with self.assertRaisesRegexp(ValueError, msg): + mean_filter2d(tf_img, filter_shape) + + msg = 'Size of the filter must be Integers' + for filter_shape in [(3.5, 3), (None, 3)]: + with self.assertRaisesRegexp(TypeError, msg): + mean_filter2d(tf_img, filter_shape) + + @test_utils.run_in_graph_and_eager_modes + def test_filter_value(self): + tf_img = tf.zeros([3, 4, 3], tf.int32) + + with self.assertRaises(ValueError): + mean_filter2d(tf_img, (4, 3)) + + @test_utils.run_deprecated_v1 + def test_dimension(self): + for image_shape in [(3, 4, None), (3, None, 4), (None, 3, 4)]: + with self.assertRaises(TypeError): + tf_img = tf.compat.v1.placeholder(tf.int32, shape=image_shape) + mean_filter2d(tf_img) + + @test_utils.run_in_graph_and_eager_modes + def test_image_vs_filter(self): + tf_img = tf.zeros([3, 4, 3], tf.int32) + filter_shape = (3, 5) + with self.assertRaises(ValueError): + mean_filter2d(tf_img, filter_shape) + + @test_utils.run_in_graph_and_eager_modes + def test_three_channels(self): + tf_img = [[[0.32801723, 0.08863795, 0.79119259], + [0.35526001, 0.79388736, 0.55435993], + [0.11607035, 0.55673079, 0.99473371]], + [[0.53240645, 0.74684819, 0.33700031], + [0.01760473, 0.28181609, 0.9751476], + [0.01605137, 0.8292904, 0.56405609]], + [[0.57215374, 0.10155051, 0.64836128], + [0.36533048, 0.91401874, 0.02524159], + [0.56379134, 0.9028874, 0.19505117]]] + + tf_img = tf.convert_to_tensor(value=tf_img) + expt = [[[34, 54, 75], [38, 93, 119], [14, 69, 87]], + [[61, 82, 94], [81, 147, 144], [40, 121, 93]], + [[42, 57, 56], [58, 106, 77], [27, 82, 49]]] + expt = tf.convert_to_tensor(value=expt) + self._validate_mean_filter2d(tf_img, expt) + + class MedianFilter2dTest(tf.test.TestCase): def _validate_median_filter2d(self, inputs, From 5b7c819368bf90ee360a0a250c74141423e097b7 Mon Sep 17 00:00:00 2001 From: Mainak Dutta <35796546+Mainak431@users.noreply.github.com> Date: Tue, 30 Apr 2019 12:49:04 +0530 Subject: [PATCH 13/19] Update filters.py fixing tests --- tensorflow_addons/image/filters.py | 60 +++++++++++++++--------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/tensorflow_addons/image/filters.py b/tensorflow_addons/image/filters.py index 11be67fcc4..583d0b06b5 100644 --- a/tensorflow_addons/image/filters.py +++ b/tensorflow_addons/image/filters.py @@ -21,7 +21,7 @@ @tf.function -def _normalize(li): +def _normalize(li, ma): one = tf.convert_to_tensor(1.0) two = tf.convert_to_tensor(255.0) @@ -35,8 +35,8 @@ def func2(): @tf.function -def median_filter2d(image, filter_shape=(3, 3), name=None): - """This method performs Median Filtering on image. Filter shape can be user +def mean_filter2d(image, filter_shape=(3, 3), name=None): + """This method performs Mean Filtering on image. Filter shape can be user given. This method takes both kind of images where pixel values lie between 0 to @@ -50,14 +50,13 @@ def median_filter2d(image, filter_shape=(3, 3), name=None): C is the second value in the filter is the number of columns in the filter. This creates a filter of shape (R,C) or RxC filter. Default value = (3,3) - name: The name of the op. Returns: - A 3D median filtered image tensor of shape [rows,columns,channels] and + A 3D mean filtered image tensor of shape [rows,columns,channels] and type 'int32'. Pixel value of returned tensor ranges between 0 to 255 """ - with tf.name_scope(name or "median_filter2d"): + with tf.name_scope(name or "mean_filter2d"): if not isinstance(filter_shape, tuple): raise TypeError('Filter shape must be a tuple') if len(filter_shape) != 2: @@ -72,20 +71,20 @@ def median_filter2d(image, filter_shape=(3, 3), name=None): if row != None and col != None and ch != None: (row, col, ch) = (int(row), int(col), int(ch)) else: - raise TypeError('All the Dimensions of the input image ' - 'tensor must be Integers.') + raise TypeError( + 'All the Dimensions of the input image tensor must be Integers.') if row < filter_shapex or col < filter_shapey: raise ValueError( 'Number of Pixels in each dimension of the image should be more \ - than the filter size. Got filter_shape (%sx' % filter_shape[0] - + '%s).' % filter_shape[1] + ' Image Shape (%s)' % image.shape) + than the filter size. Got filter_shape (%sx' % filter_shape[0] + + '%s).' % filter_shape[1] + ' Image Shape (%s)' % image.shape) if filter_shapex % 2 == 0 or filter_shapey % 2 == 0: - raise ValueError('Filter size should be odd. Got filter_shape ' - '(%sx%s)' % (filter_shape[0], filter_shape[1])) + raise ValueError('Filter size should be odd. Got filter_shape (%sx' % + filter_shape[0] + '%s)' % filter_shape[1]) image = tf.cast(image, tf.float32) tf_i = tf.reshape(image, [row * col * ch]) ma = tf.math.reduce_max(tf_i) - image = _normalize(image) + image = _normalize(image, ma) # k and l is the Zero-padding size @@ -93,13 +92,11 @@ def median_filter2d(image, filter_shape=(3, 3), name=None): for a in range(ch): img = image[:, :, a:a + 1] img = tf.reshape(img, [1, row, col, 1]) - slic = tf.image.extract_patches( + slic = tf.image.extract_image_patches( img, [1, filter_shapex, filter_shapey, 1], [1, 1, 1, 1], [1, 1, 1, 1], padding='SAME') - mid = int(filter_shapex * filter_shapey / 2 + 1) - top = tf.nn.top_k(slic, mid, sorted=True) - li = tf.slice(top[0], [0, 0, 0, mid - 1], [-1, -1, -1, 1]) + li = tf.reduce_mean(slic, axis=-1) li = tf.reshape(li, [row, col, 1]) listi.append(li) y = tf.concat(listi[0], 2) @@ -114,8 +111,8 @@ def median_filter2d(image, filter_shape=(3, 3), name=None): @tf.function -def mean_filter2d(image, filter_shape=(3, 3)): - """This method performs Mean Filtering on image. Filter shape can be user +def median_filter2d(image, filter_shape=(3, 3), name=None): + """This method performs Median Filtering on image. Filter shape can be user given. This method takes both kind of images where pixel values lie between 0 to @@ -129,13 +126,14 @@ def mean_filter2d(image, filter_shape=(3, 3)): C is the second value in the filter is the number of columns in the filter. This creates a filter of shape (R,C) or RxC filter. Default value = (3,3) + name: The name of the op. Returns: - A 3D mean filtered image tensor of shape [rows,columns,channels] and + A 3D median filtered image tensor of shape [rows,columns,channels] and type 'int32'. Pixel value of returned tensor ranges between 0 to 255 """ - with tf.name_scope(name or "mean_filter2d"): + with tf.name_scope(name or "median_filter2d"): if not isinstance(filter_shape, tuple): raise TypeError('Filter shape must be a tuple') if len(filter_shape) != 2: @@ -150,20 +148,20 @@ def mean_filter2d(image, filter_shape=(3, 3)): if row != None and col != None and ch != None: (row, col, ch) = (int(row), int(col), int(ch)) else: - raise TypeError( - 'All the Dimensions of the input image tensor must be Integers.') + raise TypeError('All the Dimensions of the input image ' + 'tensor must be Integers.') if row < filter_shapex or col < filter_shapey: raise ValueError( 'Number of Pixels in each dimension of the image should be more \ - than the filter size. Got filter_shape (%sx' % filter_shape[0] + - '%s).' % filter_shape[1] + ' Image Shape (%s)' % image.shape) + than the filter size. Got filter_shape (%sx' % filter_shape[0] + + '%s).' % filter_shape[1] + ' Image Shape (%s)' % image.shape) if filter_shapex % 2 == 0 or filter_shapey % 2 == 0: - raise ValueError('Filter size should be odd. Got filter_shape (%sx' % - filter_shape[0] + '%s)' % filter_shape[1]) + raise ValueError('Filter size should be odd. Got filter_shape ' + '(%sx%s)' % (filter_shape[0], filter_shape[1])) image = tf.cast(image, tf.float32) tf_i = tf.reshape(image, [row * col * ch]) ma = tf.math.reduce_max(tf_i) - image = _normalize(image) + image = _normalize(image, ma) # k and l is the Zero-padding size @@ -171,11 +169,13 @@ def mean_filter2d(image, filter_shape=(3, 3)): for a in range(ch): img = image[:, :, a:a + 1] img = tf.reshape(img, [1, row, col, 1]) - slic = tf.image.extract_patches( + slic = tf.image.extract_image_patches( img, [1, filter_shapex, filter_shapey, 1], [1, 1, 1, 1], [1, 1, 1, 1], padding='SAME') - li = tf.reduce_mean(slic, axis=-1) + mid = int(filter_shapex * filter_shapey / 2 + 1) + top = tf.nn.top_k(slic, mid, sorted=True) + li = tf.slice(top[0], [0, 0, 0, mid - 1], [-1, -1, -1, 1]) li = tf.reshape(li, [row, col, 1]) listi.append(li) y = tf.concat(listi[0], 2) From f3437a9b6045dda3145610fe5d2f39dcef3bee77 Mon Sep 17 00:00:00 2001 From: Mainak Dutta <35796546+Mainak431@users.noreply.github.com> Date: Tue, 30 Apr 2019 12:51:46 +0530 Subject: [PATCH 14/19] Update filters_test.py fixing tests From 51e74a1a86e8f496b20c4f9787c8e7a14bddd648 Mon Sep 17 00:00:00 2001 From: Mainak Dutta <35796546+Mainak431@users.noreply.github.com> Date: Tue, 30 Apr 2019 16:26:28 +0530 Subject: [PATCH 15/19] Update filters.py --- tensorflow_addons/image/filters.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tensorflow_addons/image/filters.py b/tensorflow_addons/image/filters.py index 583d0b06b5..b124e83b9a 100644 --- a/tensorflow_addons/image/filters.py +++ b/tensorflow_addons/image/filters.py @@ -92,7 +92,7 @@ def mean_filter2d(image, filter_shape=(3, 3), name=None): for a in range(ch): img = image[:, :, a:a + 1] img = tf.reshape(img, [1, row, col, 1]) - slic = tf.image.extract_image_patches( + slic = tf.image.extract_patches( img, [1, filter_shapex, filter_shapey, 1], [1, 1, 1, 1], [1, 1, 1, 1], padding='SAME') @@ -169,7 +169,7 @@ def median_filter2d(image, filter_shape=(3, 3), name=None): for a in range(ch): img = image[:, :, a:a + 1] img = tf.reshape(img, [1, row, col, 1]) - slic = tf.image.extract_image_patches( + slic = tf.image.extract_patches( img, [1, filter_shapex, filter_shapey, 1], [1, 1, 1, 1], [1, 1, 1, 1], padding='SAME') From 0422735fc2291bf2f7020be63490971aa022eade Mon Sep 17 00:00:00 2001 From: Sean Morgan Date: Wed, 1 May 2019 16:28:49 -0400 Subject: [PATCH 16/19] Fix lint --- tensorflow_addons/image/filters.py | 11 ++++++----- tensorflow_addons/image/filters_test.py | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/tensorflow_addons/image/filters.py b/tensorflow_addons/image/filters.py index b124e83b9a..b258b77e28 100644 --- a/tensorflow_addons/image/filters.py +++ b/tensorflow_addons/image/filters.py @@ -72,15 +72,16 @@ def mean_filter2d(image, filter_shape=(3, 3), name=None): (row, col, ch) = (int(row), int(col), int(ch)) else: raise TypeError( - 'All the Dimensions of the input image tensor must be Integers.') + 'All the Dimensions of the input image tensor must be Integers.' + ) if row < filter_shapex or col < filter_shapey: raise ValueError( 'Number of Pixels in each dimension of the image should be more \ - than the filter size. Got filter_shape (%sx' % filter_shape[0] + - '%s).' % filter_shape[1] + ' Image Shape (%s)' % image.shape) + than the filter size. Got filter_shape (%sx' % filter_shape[0] + + '%s).' % filter_shape[1] + ' Image Shape (%s)' % image.shape) if filter_shapex % 2 == 0 or filter_shapey % 2 == 0: - raise ValueError('Filter size should be odd. Got filter_shape (%sx' % - filter_shape[0] + '%s)' % filter_shape[1]) + raise ValueError('Filter size should be odd. Got filter_shape (%sx' + % filter_shape[0] + '%s)' % filter_shape[1]) image = tf.cast(image, tf.float32) tf_i = tf.reshape(image, [row * col * ch]) ma = tf.math.reduce_max(tf_i) diff --git a/tensorflow_addons/image/filters_test.py b/tensorflow_addons/image/filters_test.py index c09604a226..c4a3bb4bab 100644 --- a/tensorflow_addons/image/filters_test.py +++ b/tensorflow_addons/image/filters_test.py @@ -25,9 +25,9 @@ class MeanFilter2dTest(tf.test.TestCase): def _validate_mean_filter2d(self, - inputs, - expected_values, - filter_shape=(3, 3)): + inputs, + expected_values, + filter_shape=(3, 3)): output = mean_filter2d(inputs, filter_shape) self.assertAllClose(output, expected_values) From 6d318c741e20ea82f7002359b67eeee4bbaef85b Mon Sep 17 00:00:00 2001 From: Sean Morgan Date: Wed, 1 May 2019 16:47:29 -0400 Subject: [PATCH 17/19] Lint fix --- tensorflow_addons/image/filters.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tensorflow_addons/image/filters.py b/tensorflow_addons/image/filters.py index b258b77e28..19aaf489c5 100644 --- a/tensorflow_addons/image/filters.py +++ b/tensorflow_addons/image/filters.py @@ -76,9 +76,10 @@ def mean_filter2d(image, filter_shape=(3, 3), name=None): ) if row < filter_shapex or col < filter_shapey: raise ValueError( - 'Number of Pixels in each dimension of the image should be more \ - than the filter size. Got filter_shape (%sx' % filter_shape[0] - + '%s).' % filter_shape[1] + ' Image Shape (%s)' % image.shape) + 'Number of Pixels in each dimension of the image should be \ + more than the filter size. Got filter_shape (%sx' % + filter_shape[0] + '%s).' % filter_shape[1] + + ' Image Shape (%s)' % image.shape) if filter_shapex % 2 == 0 or filter_shapey % 2 == 0: raise ValueError('Filter size should be odd. Got filter_shape (%sx' % filter_shape[0] + '%s)' % filter_shape[1]) @@ -153,9 +154,10 @@ def median_filter2d(image, filter_shape=(3, 3), name=None): 'tensor must be Integers.') if row < filter_shapex or col < filter_shapey: raise ValueError( - 'Number of Pixels in each dimension of the image should be more \ - than the filter size. Got filter_shape (%sx' % filter_shape[0] - + '%s).' % filter_shape[1] + ' Image Shape (%s)' % image.shape) + 'Number of Pixels in each dimension of the image should be \ + more than the filter size. Got filter_shape (%sx' % + filter_shape[0] + '%s).' % filter_shape[1] + + ' Image Shape (%s)' % image.shape) if filter_shapex % 2 == 0 or filter_shapey % 2 == 0: raise ValueError('Filter size should be odd. Got filter_shape ' '(%sx%s)' % (filter_shape[0], filter_shape[1])) From a48028100bacd09d6e6d75a62755b08b13975f12 Mon Sep 17 00:00:00 2001 From: Sean Morgan Date: Wed, 1 May 2019 16:47:45 -0400 Subject: [PATCH 18/19] linting --- tensorflow_addons/image/filters.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tensorflow_addons/image/filters.py b/tensorflow_addons/image/filters.py index 19aaf489c5..3598f2c5eb 100644 --- a/tensorflow_addons/image/filters.py +++ b/tensorflow_addons/image/filters.py @@ -72,7 +72,8 @@ def mean_filter2d(image, filter_shape=(3, 3), name=None): (row, col, ch) = (int(row), int(col), int(ch)) else: raise TypeError( - 'All the Dimensions of the input image tensor must be Integers.' + 'All the Dimensions of the input image tensor must be \ + Integers.' ) if row < filter_shapex or col < filter_shapey: raise ValueError( From cdf1c4f640ead364cc0ed28ea936379f58682934 Mon Sep 17 00:00:00 2001 From: Sean Morgan Date: Wed, 1 May 2019 17:06:58 -0400 Subject: [PATCH 19/19] Lint --- tensorflow_addons/image/filters.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tensorflow_addons/image/filters.py b/tensorflow_addons/image/filters.py index 3598f2c5eb..61b5334496 100644 --- a/tensorflow_addons/image/filters.py +++ b/tensorflow_addons/image/filters.py @@ -73,8 +73,7 @@ def mean_filter2d(image, filter_shape=(3, 3), name=None): else: raise TypeError( 'All the Dimensions of the input image tensor must be \ - Integers.' - ) + Integers.') if row < filter_shapex or col < filter_shapey: raise ValueError( 'Number of Pixels in each dimension of the image should be \