Example #1
0
    def test_invalid_padding(self):
        msg = ("padding should be one of \"REFLECT\", \"CONSTANT\", "
               "or \"SYMMETRIC\".")
        image = tf.ones(shape=(1, 28, 28, 1))

        with self.assertRaisesRegexp(ValueError, msg):
            mean_filter2d(image, padding="TEST")
Example #2
0
    def test_invalid_image(self):
        msg = "image should be either 3 or 4-dimensional."

        for image_shape in [(28, 28), (16, 28, 28, 1, 1)]:
            with self.subTest(dim=len(image_shape)):
                with self.assertRaisesRegexp(ValueError, msg):
                    mean_filter2d(tf.ones(shape=image_shape))
Example #3
0
    def test_invalid_filter_shape(self):
        msg = ("The `filter_shape` argument must be a tuple of 2 integers.")
        image = tf.ones(shape=(1, 28, 28, 1))

        for filter_shape in [(3, 3, 3), (3, None, 3), None]:
            with self.subTest(filter_shape=filter_shape):
                with self.assertRaisesRegexp(ValueError, msg):
                    mean_filter2d(image, filter_shape=filter_shape)
Example #4
0
def test_invalid_filter_shape_median(filter_shape):
    image = tf.ones(shape=(1, 28, 28, 1))

    with pytest.raises(ValueError):
        median_filter2d(image, filter_shape=filter_shape)

    filter_shape = None
    with pytest.raises(TypeError):
        mean_filter2d(image, filter_shape=filter_shape)
Example #5
0
 def test_invalid_image(self):
     msg = "`image` must be 2/3/4D tensor"
     errors = (ValueError, tf.errors.InvalidArgumentError)
     for image_shape in [(1, ), (16, 28, 28, 1, 1)]:
         with self.subTest(dim=len(image_shape)):
             with self.assertRaisesRegexp(errors, msg):
                 image = tf.ones(shape=image_shape)
                 self.evaluate(mean_filter2d(image))
Example #6
0
    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)
Example #7
0
def test_invalid_image_mean(image_shape):
    with pytest.raises((ValueError, tf.errors.InvalidArgumentError)):
        image = tf.ones(shape=image_shape)
        mean_filter2d(image)
Example #8
0
def test_invalid_padding_mean():
    image = tf.ones(shape=(1, 28, 28, 1))

    with pytest.raises(ValueError):
        mean_filter2d(image, padding="TEST")
Example #9
0
    def test_invalid_padding(self):
        msg = 'padding should be one of "REFLECT", "CONSTANT", ' 'or "SYMMETRIC".'
        image = tf.ones(shape=(1, 28, 28, 1))

        with self.assertRaisesRegexp(ValueError, msg):
            mean_filter2d(image, padding="TEST")
Example #10
0
 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)
Example #11
0
 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)
Example #12
0
    def test_filter_value(self):
        tf_img = tf.zeros([3, 4, 3], tf.int32)

        with self.assertRaises(ValueError):
            mean_filter2d(tf_img, (4, 3))
Example #13
0
 def _validate_mean_filter2d(self,
                             inputs,
                             expected_values,
                             filter_shape=(3, 3)):
     output = mean_filter2d(inputs, filter_shape)
     self.assertAllClose(output, expected_values)