def test_translate(self, dtype): image = tf.constant( [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1]], dtype=dtype) translations = [-1, -1] translated = augment.translate(image=image, translations=translations) expected = [[1, 0, 1, 1], [0, 1, 0, 0], [1, 0, 1, 1], [1, 0, 1, 1]] self.assertAllEqual(translated, expected)
def test_translate_invalid_translation(self, dtype): image = tf.zeros((1, 1), dtype=dtype) invalid_translation = [[[1, 1]]] with self.assertRaisesRegex(TypeError, 'rank 1 or 2'): _ = augment.translate(image, invalid_translation)
def test_translate_shapes(self, dtype): translation = [0, 0] for shape in [(3, 3), (5, 5), (224, 224, 3)]: image = tf.zeros(shape, dtype=dtype) self.assertAllEqual(image, augment.translate(image, translation))