Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TFlearn IndexError out of bounds

I have some data which looks like this:

X = [[1,2,3,4],[01010],[-1.6]]
y = [[4,2]]

I am trying to train a neural net on this data using tflearn. I'm using the same example given on the TFlearn github homepage (https://github.com/tflearn/tflearn) except that I have changed the shape of the data.

tflearn.init_graph(num_cores=1)

net = tflearn.input_data(shape=[None, 2,2,1])
net = tflearn.fully_connected(net, 64)
net = tflearn.dropout(net, 0.5)
net = tflearn.fully_connected(net, 10, activation='softmax')
net = tflearn.regression(net, optimizer='adam', loss='categorical_crossentropy')

model = tflearn.DNN(net)
model.fit(X,y)

I keep getting this error:

"IndexError: index 2 is out of bounds for axis 0 with size 1."

I think this is either due to the shape of the data being specified is incorrect or something to do with the fully_connected layer.

What does this error mean? Is it due to the shape being wrong? What do I need to change in the code above to prevent this error?

Any help would be greatly appreciated.

like image 387
HS1300 Avatar asked Nov 01 '25 12:11

HS1300


1 Answers

The issue has been discussed in detail in the following thread.

List index out of......

Apparently a simple addition of the following code on top fixed the issue:

tf.reset_default_graph()

tf here means tensorflow, so don't forget to import tensorflow

I hope this helps

like image 50
Inder Avatar answered Nov 04 '25 04:11

Inder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!