دنبال کننده ها

۱۳۹۶ اسفند ۲۴, پنجشنبه

python - Converting sequence of 3D coordinates to sequence of matrices with tensorflow

[ad_1]



I'm trying to construct a tensforflow graph that translates a sequence of 3D coordinates to a sequence of matrixes. The first layer should take each 3D input vector and multiply it component-wise with each row of weight matrix. I used the following code to the job:



import tensorflow as tf

P = tf.placeholder(tf.float32, [None, 3])
W = tf.Variable(tf.random_uniform([5, 3], 0, 1, dtype=tf.float32))
Z = tf.stack([ tf.multiply(p, W) for p in tf.unstack(P)])
print(Z.shape)


But the above code resulted in the following error message:



...
ValueError: Cannot infer num from shape (?, 3)


It seems that tf.unstack() doesn't accept tensor with unknown dimension. The above code would work, if I replace the value None by an integer in the definition of the placeholder P. However, that integer is the length of the sequence and it is not known at design time.



Thus, my question is how can I do such 'dynamical' unstack/stack? Is there another way to do my translation?



Notice that most operations in tensorflow work fine with tensors of unknown dimension by taking input vectors one-by-one, but the operation multiply() and unstack() do not work in this manner.



thanks in adavnce




[ad_2]

لینک منبع