Reputation: 41
I am trying to pass a list of 2d numpy arrays with different sizes to a convolutional neural network using feed_dict parameter.
x = tf.placeholder(tf.float32, [batch_size, None, None, None])
y = tf.placeholder(tf.float32, [batch_size, 1])
optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost)
optimizer.run(feed_dict={x: batch[0], y: batch[1], keep_prob: 0.5})
and I am getting the following error :
ValueError: setting an array element with a sequence.
I understood that batch[0] has to contain arrays with the same size. I am trying to find a way to apply the optimization using variable sized batch of arrays but all the suggested solutions ask to resize the arrays which is not possible in my case because these arrays are not images and contain DNA Fragments with different sizes (any modifications on any element of the array will cause a lost of important information)
Anyone has an idea ?
Upvotes: 2
Views: 1421
Reputation: 641
The matrix provided needs to have a consistent size across rows and columns. One row, or column, can not be a different size than any other.
Matrix #1 Matrix #2
1 2 3 1 2 3
None 4 5 6
None 7 8 9
No operations will work on Matrix #1, which is essentially what you have. If you want to feed in vairable size matrices (different sizes among matices, but size size with in rows and columns) this may solve your problem
Args:
shape: The shape of the tensor to be fed (optional). If the shape is not specified, you can feed a tensor of any shape.
Or you if you are looking for a sparse tensor (tf.sparse_placeholder()
-- undefined elements are set to zero), this question may help.
Upvotes: 1