I am trying to get the dimensions of a placeholder in Tensorflow. Function tf$shape
immediately came to my mind. I had no trouble using tf$shape
to get the shape of a placeholder with positive dimensions. However, I want my placeholder to be able to take in inputs of different sizes, so I left one dimension as NULL
. Now, according to my understanding, when it comes to dimensions, Tensorflow treats NULL
and -1
equivalently. However, when I run my code, I received this error:
W tensorflow/core/framework/op_kernel.cc:1148] Invalid argument: Shape [-1,2] has negative dimensions
Below is a reproducible example of my code:
a = tf$placeholder(tf$float32, shape = shape(NULL, 2L))
sess = tf$Session()
sess$run(tf$shape(a))
Is the error cited above caused by something in my code or by the fact that tf$shape
cannot take in a placeholder with negative dimensions? If the latter is true, is there any way for me to get the shape of a placeholder with negative dimensions without using tf$shape
?