def test_split_merge_random(self, num_levels): """Tests that splitting and merging back can reproduce the input.""" tensor_shape = np.random.randint(1, 5, size=4).tolist() image_random = np.random.uniform(size=tensor_shape) split = pyramid.split(image_random, num_levels=num_levels) merge = pyramid.merge(split) self.assertAllClose(image_random, merge)
def test_split_jacobian_random(self): """Tests the Jacobian for random inputs.""" split = lambda image: pyramid.split(image, num_levels=_NUM_LEVELS) tensor_shape = np.random.randint(1, 5, size=4).tolist() image_random_init = np.random.uniform(size=tensor_shape) for level in range(4): # pylint: disable=unused-variable self.assert_jacobian_is_correct_fn( lambda x, level=level: split(x)[level], [image_random_init])
def test_split_jacobian_random(self): """Tests the Jacobian for random inputs.""" tensor_shape = np.random.randint(1, 5, size=(4)).tolist() image_random_init = np.random.uniform(size=tensor_shape) image_random = tf.convert_to_tensor(value=image_random_init) split_random = pyramid.split(image_random, num_levels=4) for level in split_random: self.assert_jacobian_is_correct(image_random, image_random_init, level)
def test_split_preset(self, image, image_high, image_low): """Tests that the split function splits the image as expected.""" split = lambda image: pyramid.split(image, num_levels=1) image = tf.expand_dims(tf.expand_dims(image, axis=-1), axis=0) image_high = tf.expand_dims(tf.expand_dims(image_high, axis=-1), axis=0) image_low = tf.expand_dims(tf.expand_dims(image_low, axis=-1), axis=0) pyramid_split = split(image) with self.subTest(name="image_high"): self.assertAllClose(image_high, pyramid_split[0]) with self.subTest(name="image_low"): self.assertAllClose(image_low, pyramid_split[1])
def test_split_exception_raised(self, error_msg, *shape): """Tests that the shape exceptions are properly raised.""" split = lambda image: pyramid.split(image, num_levels=_NUM_LEVELS) self.assert_exception_is_raised(split, error_msg, shape)
def test_split_exception_not_raised(self, *shape): """Tests that the shape exceptions are not raised.""" split = lambda image: pyramid.split(image, num_levels=_NUM_LEVELS) self.assert_exception_is_not_raised(split, shape)