WΔ_
WΔ_

Reputation: 1247

Feed Dict Error in Tensorflow

I am attempting to build a Multi Layer Perceptron (MLP) in Tensorflow. I am using a dataset generated using numpy. The dataset has just two variables, one of which is the label. The dataset contains 100 points normalised in the range [0-1].

print(trainX[0:3])

[ 0.2853112   0.2433195   0.56746888]

All values above 0.5, have the label 1, otherwise they have a label 2.

print(trainY[0:3])

  [2 2 1]

The problem occurs in the tf.Session() loop.

with tf.Session() as sess:

    sess.run(init)

    for epoch in range(training_epochs):
        #avg_cost = 0.

        for (xs, ys) in zip(trainX, trainY):
            sess.run(optimizer, feed_dict={X:xs, Y:ys})

The script terminates at that last line, with the following error:

InvalidArgumentError: Expected begin[0] == 0 (got -1) and size[0] == 0 (got 1)     when input.dim_size(0) == 0
 [[Node: Slice_132 = Slice[Index=DT_INT32, T=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"](Shape_134, Slice_132/begin, Slice_132/size)]]

Further up in the script, I declare the placeholders as follows:

X = tf.placeholder("float")
Y = tf.placeholder("float")

I am happy to post more code; in the interests of being succinct, I have not (so far) posted everything.

Upvotes: 0

Views: 344

Answers (1)

xiaoming-qxm
xiaoming-qxm

Reputation: 1828

Try to modify your label index which should be start from 0. In your case, trainY = np.array([1, 1, 0]). I think it would solve your problem.

Upvotes: 1

Related Questions