2

I have inputs to a tensorflow convnet as rank-4 tensors (32, 32, 3, 73257) (73257 comes from number of imgs) which are numpy arrays, but my placeholder variable for my x inputs is 2-d, (None, 3072). The 3072 comes from the img height x img width x channels. My question is, how do I reshape or use the images so that theyre compatible with the placeholder?

P.S. These images are from the SVHN cropped 32x32 dataset

images = np.array(features, dtype=np.float32)
...
x = tf.placeholder(tf.float32, shape=[None, 3072])
...
for _ in range(1000):
  batch = next_batch(50, images, labels)
  train_step.run(feed_dict={x: batch[0], y_: batch[1]})
...
with tf.Session() as sess:
  sess.run(tf.global_variables_initializer())
  for i in range(20000):
    batch = next_batch(50, images, labels)
    if i % 100 == 0:
      train_accuracy = accuracy.eval(feed_dict={
          x: batch[0], y_: batch[1], keep_prob: 1.0})
      print('step %d, training accuracy %g' % (i, train_accuracy))
    train_step.run(feed_dict={x: images, y_: labels, keep_prob: 0.5})

1 Answer 1

3

Assuming you have 73257 images 32 by 32 pixel holding 3 bands (e.g. rgb). You can do a

input = tf.transpose(input, [3, 0, 1, 2])

to bring the last dimension first. The tensor should then look like (73257, 32, 32, 3).

Then do

input = tf.reshape(input, [-1, 3072])

to reduce the dimension. The tensor should then look like (73257, 3072).

Sign up to request clarification or add additional context in comments.

1 Comment

Got it! Thanks for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.