2017-03-21 33 views
0

Tensorflowを使用して3Dで回転行列のパラメータを学習したいと考えています。したがって、私は今、二つの問題テンソルフローの3D回転行列

  1. 私はエラーメッセージが表示されます持って回転行列を次のよう

    g = tf.Graph() 
    with g.as_default(): 
        #rotations 
    
        thetax = tf.Variable(tf.zeros([1])) 
        thetax = tf.Variable(tf.zeros([1])) 
        thetay = tf.Variable(tf.zeros([1])) 
        p = tf.placeholder(tf.float32, [3]) 
        rotation_matrix_x = tf.pack([tf.constant(1.0),tf.constant(0.0),tf.constant(0.0), 
               tf.constant(0.0),tf.cos(thetax), -tf.sin(thetax), 
               tf.constant(0.0),tf.sin(thetax), tf.cos(thetax)]) 
        rotation_matrix_y = tf.pack([ 
              tf.cos(thetax),tf.constant(0.0), -tf.sin(thetax), 
              tf.constant(1.0),tf.constant(0.0),tf.constant(0.0), 
              tf.sin(thetax),0, tf.cos(thetax)]) 
    
    
    rotation_matrix_z = tf.pack([ 
               tf.cos(thetax), -tf.sin(thetax),tf.constant(0.0), 
               tf.sin(thetax), tf.cos(thetax),tf.constant(0.0), 
               tf.constant(1.0),tf.constant(0.0),tf.constant(0.0)]) 
    rotation_matrix_x = tf.reshape(rotation_matrix_x, (3,3)) 
    rotation_matrix_y = tf.reshape(rotation_matrix_y, (3,3)) 
    rotation_matrix_z = tf.reshape(rotation_matrix_z, (3,3)) 
    rotated = tf.mult(tf.mult(rotation_matrix_x,tf.mult(rotation_matrix_y,rotation_matrix_z) ,p) 
    

    定義:ValueError: Shapes TensorShape([]) and TensorShape([Dimension(1)]) must have the same rank

  2. を回転行列を定義するための よりエレガントな方法があります は余分な自由度を導入していないのですか?たとえば、法線ベクトル+角度は完全に許容可能です。

問題については、事前

答えて

1

のおかげで(1)—形状誤差—私は問題はあなたが単一要素ベクトルで(例えばtf.constant(0.0)など)スカラーを一緒にパックしようとしていることに起因すると考えます(すなわち、tf.Variable(tf.zeros([1])))。あなたはスカラーとして変数を再定義することによってこの問題を解決することができるはずです。

thetax = tf.Variable(tf.zeros([])) 
thetax = tf.Variable(tf.zeros([])) 
thetay = tf.Variable(tf.zeros([])) 

私はもっとエレガントな問題を再定義する方法についてはよく分からない...しかし、うまくいけば、これはあなたを剥がれ取得します!

+0

ありがとうございます。ありがとうございました。 – CAFEBABE

0

最近同じ問題が発生しました。このスニペットcos_rot_xで(バッチサイズ、1)あなたは、変換時にバッチ寸法を保つことができる形状であることが

one = tf.ones_like(cos_rot_x, dtype=tf.float32)  
zero = tf.zeros_like(cos_rot_x, dtype=tf.float32) 

rot_x = tf.stack([tf.concat([one,  zero,  zero],  axis=1), 
        tf.concat([zero,  cos_rot_x, sin_rot_x], axis=1), 
        tf.concat([zero,  -sin_rot_x, cos_rot_x], axis=1)], axis=1) 

rot_y = tf.stack([tf.concat([cos_rot_y, zero,  -sin_rot_y], axis=1), 
        tf.concat([zero,  one,  zero],  axis=1), 
        tf.concat([sin_rot_y, zero,  cos_rot_y], axis=1)], axis=1) 

rot_z = tf.stack([tf.concat([cos_rot_z, sin_rot_z, zero],  axis=1), 
        tf.concat([-sin_rot_z, cos_rot_z, zero],  axis=1), 
        tf.concat([zero,  zero,  one],  axis=1)], axis=1) 

rot_matrix = tf.matmul(rot_z, tf.matmul(rot_y, rot_x)) 

注意:これは私の現在のソリューションです。