def random_flipped_inputs(): flipped_outputs = inputs if self.horizontal: flipped_outputs = image_ops.random_flip_up_down(flipped_outputs, self.seed) if self.vertical: flipped_outputs = image_ops.random_flip_left_right( flipped_outputs, self.seed) return flipped_outputs
def testRandomLeftRight(self): x_np = np.array([0, 1], dtype=np.uint8).reshape([1, 2, 1]) num_iterations = 500 hist = [0, 0] with self.test_session(): x_tf = constant_op.constant(x_np, shape=x_np.shape) y = image_ops.random_flip_left_right(x_tf) for _ in xrange(num_iterations): y_np = y.eval().flatten()[0] hist[y_np] += 1 # Ensure that each entry is observed within 4 standard deviations. four_stddev = 4.0 * np.sqrt(num_iterations / 2.0) self.assertAllClose(hist, [num_iterations / 2.0] * 2, atol=four_stddev)