def test_AllEvenError(self): with self.session(): all_even = augmentation_ops.cubic_interpolation1d( np.ndarray([2, 1]), 2, output_length=2) with self.assertRaisesWithPredicateMatch( tf.errors.InvalidArgumentError, "factor must be odd as input and output size is even"): all_even.eval()
def test_EvenOddError(self): with self.session(): even_odd = augmentation_ops.cubic_interpolation1d( np.ndarray([2, 1]), 2, output_length=1) with self.assertRaisesWithPredicateMatch( tf.errors.InvalidArgumentError, "output size and input size must both be odd or both be even"): even_odd.eval()
def test_1DInterpolation(self): with self.session(): grid = np.ndarray([5, 2], dtype=np.float32) for x0 in range(grid.shape[0]): for channel in range(grid.shape[1]): grid[x0, channel] = x0 * grid.shape[1] + channel dense = augmentation_ops.cubic_interpolation1d( input=grid, factor=10, output_length=21).eval() precision = 5 self.assertAlmostEqual(grid[1, 0], dense[0, 0], precision) self.assertAlmostEqual(grid[2, 0], dense[10, 0], precision) self.assertAlmostEqual(grid[3, 0], dense[20, 0], precision) self.assertAlmostEqual(grid[1, 1], dense[0, 1], precision) self.assertAlmostEqual(grid[2, 1], dense[10, 1], precision) self.assertAlmostEqual(grid[3, 1], dense[20, 1], precision)
def test_1DInterpolationFull(self): with self.session(): grid = np.ndarray([5, 2], dtype=np.float32) for x0 in range(grid.shape[0]): for channel in range(grid.shape[1]): grid[x0, channel] = x0 * grid.shape[1] + channel dense_op = augmentation_ops.cubic_interpolation1d(grid, 10) self.assertAllEqual([41, 2], dense_op.get_shape().as_list()) dense = dense_op.eval() precision = 5 self.assertAlmostEqual(grid[0, 0], dense[0, 0], precision) self.assertAlmostEqual(grid[1, 0], dense[10, 0], precision) self.assertAlmostEqual(grid[2, 0], dense[20, 0], precision) self.assertAlmostEqual(grid[3, 0], dense[30, 0], precision) self.assertAlmostEqual(grid[4, 0], dense[40, 0], precision) self.assertAlmostEqual(grid[3, 1], dense[30, 1], precision) self.assertAlmostEqual(grid[2, 1], dense[20, 1], precision) self.assertAlmostEqual(grid[0, 1], dense[0, 1], precision)