2

In feeding batch_xs to x, I reshaped batch_xs, for BATCH_SIZE is 1. Here is my source. I'm not sure what is making the ValueError.

with tf.name_scope("input") as scope:
    x = tf.placeholder(tf.float32, shape=[1, 784])

BATCH_SIZE = 1
DROP_OUT_RATE = 0.4
EPOCH = 1
MEMORIZE = 10
accuracy_array = []
loss = tf.nn.l2_loss(y - x) / BATCH_SIZE
train_step = tf.train.AdamOptimizer(1e-4).minimize(loss)

mnist = input_data.read_data_sets('MNIST_data', one_hot=True)
mnist_list = make_mnist_train_list(55000, 10)
test_list = make_mnist_test_list(5000, 10)
sess = tf.Session()
sess.run(tf.initialize_all_variables())

for i in range(EPOCH):
    for j in range(5500/BATCH_SIZE):
        batch_xs = tf.reshape(mnist_list[0][j*BATCH_SIZE:j*BATCH_SIZE+1], [1, 784])
        sess.run(train_step, feed_dict={x: batch_xs, keep_prob: (1.0 - DROP_OUT_RATE), r_keep_prob: (1.0 - DROP_OUT_RATE)})
        if (i +1)% MEMORIZE == 0:
            accuracy_array.append(loss.eval(session=sess, feed_dict={x: batch_xs, keep_prob: 1.0, r_keep_prob: 1.0}))
            print(accuracy_array[ int(math.floor((i+1)/MEMORIZE -1))])

This gives me the Value error, which doesn't make sense to me.

ValueError: Argument must be a dense tensor

1
  • Your code mentions "tf.nn.l2_loss(y - x) / BATCH_SIZE" but doesn't define y anywhere. Is this the complete example? Also please include the full text of the error, which hopefully indicates the line causing the problem. Commented Feb 3, 2016 at 20:03

1 Answer 1

2

From the documentation here :

Each key in feed_dict can be one of the following types:

  • If the key is a Tensor, the value may be a Python scalar, string, list, or numpy ndarray that can be converted to the same dtype as that tensor. Additionally, if the key is a placeholder, the shape of the value will be checked for compatibility with the placeholder.

  • If the key is a SparseTensor, the value should be a SparseTensorValue.

The types that you can use as the "value" for a key in feed_dict should be Python primitive types or numpy arrays. You are using the result of tf.reshape, which is a TensorFlow Tensor type. You can simply use np.reshape if you want to feed a reshaped array.

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

Comments

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.