コード例 #1
0
ファイル: geometry_test.py プロジェクト: xueyongfu/lingvo
 def _MakeTransformTestRotationMatrices(self, batch_size):
   # Make a batch of 4x4 transformation matrices that only has rotation around
   # the z-axis (world rotation).
   rot_matrices = []
   for _ in range(batch_size):
     rot_matrix = geometry._MakeRotationMatrix(tf.random_uniform([]), 0., 0.)
     # Embed rotation matrix into a 4 x 4 matrix
     rot_matrix = tf.pad(rot_matrix, [[0, 1], [0, 1]]) + tf.diag([0, 0, 0, 1.])
     rot_matrices.append(rot_matrix)
   transforms = tf.stack(rot_matrices, axis=0)
   return transforms
コード例 #2
0
 def _MakeTransformTestTranslationMatrices(self, batch_size):
     # Make a batch of 4x4 transformation matrices that translate in all
     # directions.
     translation_matrices = []
     for _ in range(batch_size):
         translation_matrix = tf.random_uniform([3, 1])
         translation_matrix = tf.pad(translation_matrix, [[0, 1], [3, 0]])
         translation_matrix += tf.diag([1., 1., 1., 1.])
         translation_matrices.append(translation_matrix)
     transforms = tf.stack(translation_matrices, axis=0)
     return transforms
コード例 #3
0
 def inverse_pth_root(self, input_t, exponent, epsilon=1e-12):
     input_t_f64 = tf.cast(input_t, tf.float64)
     s, u, v = tf.svd(
         input_t_f64 +
         tf.eye(tf.shape(input_t_f64)[0], dtype=tf.float64) * epsilon,
         full_matrices=True)
     val = tf.matmul(
         tf.matmul(
             u,
             tf.diag(
                 tf.pow(tf.maximum(s, epsilon),
                        tf.cast(exponent, tf.float64)))), tf.transpose(v))
     return tf.cast(val, tf.float32), tf.reduce_max(tf.abs(u - v))