def _test_random_rotation(self, dtype): aa = np.random.rand(4, 3).astype(dtype) aa_tensor = tf.constant(aa) R_tensor = ops.angle_axis_to_rotation_matrix(aa_tensor) aa2_tensor = ops.rotation_matrix_to_angle_axis(R_tensor) aa2 = aa2_tensor.eval() err = np.sum(np.abs(aa - aa2)) print('error', err, flush=True) self.assertLess(err, 1e-5)
def _test_zero_rotation(self, dtype): aa = np.zeros(3).astype(dtype) aa_tensor = tf.constant(aa) R_tensor = ops.angle_axis_to_rotation_matrix(aa_tensor) R = R_tensor.eval() I = np.eye(3) err = np.sum(np.abs(R - I)) print('error', err, flush=True) self.assertLess(err, 1e-5)
def test_shape(self): with self.test_session(use_gpu=False, force_gpu=False, **session_params): input1 = np.empty((8, 3)) input2 = np.empty((2, 4, 3)) input3 = np.empty((2, 2, 2, 3)) inputs = (input1, input2, input3) expected_shape = [8, 3, 3] for i in inputs: output_tensor = ops.angle_axis_to_rotation_matrix(i) out_shape = output_tensor.get_shape().as_list() self.assertAllEqual(out_shape, expected_shape)
def _test_grad(self, dtype): aa = np.random.rand(5, 3).astype(dtype) shape = aa.shape data = tf.constant(aa) output = ops.angle_axis_to_rotation_matrix(data) err = tf.test.compute_gradient_error(data, shape, output, output.get_shape().as_list(), x_init_value=aa) print('error', err, flush=True) self.assertLess(err, 1e-4) grad = tf.test.compute_gradient(data, shape, output, output.get_shape().as_list(), x_init_value=aa, delta=0.0001) diff = np.abs(grad[0] - grad[1])