How to feed input with changing size in Tensorflow

Viewed 9629

I want to train a network with planar curves, which I represent as numpy arrays with shape (L,2). The number 2 stands for x,y coordinates and L is the number of points which is changing in my dataset. I treat x,y as 2 different "channels".

I implemented a function, next_batch(batch_size), that provides the next batch as a 1D numpy array with shape (batch_size,), containing elements which are 2D arrays with shape: (L,2). These are my curves, and as mentioned before, L is different between the elements. (I didn't want to confine to fixed number of points in the curve).

My question:

How can I manipulate the output from next_batch() so I will able to feed the network with the input curves, using a scheme similar to what appears in Tensorflow tutorial: https://www.tensorflow.org/get_started/mnist/pros

i.e, using the feed_dict mechanism. In the given turorial the input size was fixed, in the tutorial's code line:

train_step.run(feed_dict={x: batch[0], y_: batch[1], keep_prob: 0.5})

batch[0] has a fixed shape: (50,784) (50 = #samples,784 = #pixels)

I cannot transform my input into numpy array with shape (batch_size,L,2) since the array should have fixed size in every dimension. So what can I do?

I already defined a placeholder (that can have unknown size):

#first dimension is the sample dim, second is curve length, third:x,y coordinates    
x = tf.placeholder(tf.float32, [None, None,2]) 

but how can I feed it properly?

4 Answers
Related