I am trying to determine the operation for NN that I am implementing, but for this I need to iterate the dimension of the tensor. Below is a small working example.
X = tf.placeholder(tf.float32, shape=[None, 10])
idx = [[i] for i in tf.range(X.get_shape()[0])]
This results in a message error
ValueError: Cannot convert an unknown Dimension to a Tensor: ?
When using the same code, but using tf.shapeinstead, the resulting code
X = tf.placeholder(tf.float32, shape=[None, 10])
idx = [[i] for i in tf.range(tf.shape(X)[0])]
Gives the following error:
TypeError: 'Tensor' object is not iterable.
The way I implement this NN is batch_sizenot defined before the training function, which is at the end of the code. This is exactly where I create the schedule myself, therefore I am batch_sizenot known on this issue, and it cannot be fixed, because the training batch_sizeand test suite batch_sizes are different.
? , , batch_size, . API TensorFlow .
, , / ,
X = tf.placeholder(tf.float32, shape=[None, 10])
bs = tf.placeholder(tf.int32)
def My_Function(X):
idx = [[i] for i in tf.range(bs)]
A = tf.nn.relu(My_Function(X))
,
TypeError: 'Tensor' object is not iterable.