tflearn / tflearn

Deep learning library featuring a higher-level API for TensorFlow.
http://tflearn.org
Other
9.62k stars 2.41k forks source link

List index out of range #408

Open rajendraranabhat opened 8 years ago

rajendraranabhat commented 8 years ago

I am trying to run tflearn for simple mnist classification using MLP. I tried to other example and I am getting this error for almost all. I just started using TFlearn.

IndexError Traceback (most recent call last)

in () 48 max_checkpoints=10, tensorboard_verbose=0) 49 model.fit(X, Y, n_epoch=100, validation_set=(testX, testY), ---> 50 show_metric=True, batch_size=256, run_id='resnet_mnist') /usr/local/lib/python2.7/dist-packages/tflearn/models/dnn.pyc in fit(self, X_inputs, Y_targets, n_epoch, validation_set, show_metric, batch_size, shuffle, snapshot_epoch, snapshot_step, excl_trainops, run_id) 155 # TODO: check memory impact for large data and multiple optimizers 156 feed_dict = feed_dict_builder(X_inputs, Y_targets, self.inputs, --> 157 self.targets) 158 feed_dicts = [feed_dict for i in self.train_ops] 159 val_feed_dicts = None /usr/local/lib/python2.7/dist-packages/tflearn/utils.pyc in feed_dict_builder(X, Y, net_inputs, net_targets) 265 X = [X] 266 for i, x in enumerate(X): --> 267 feed_dict[net_inputs[i]] = x 268 else: 269 # If a dict is provided IndexError: list index out of range --- ## Code ``` python from __future__ import division, print_function, absolute_import import tflearn # Data loading and preprocessing import tflearn.datasets.mnist as mnist X, Y, testX, testY = mnist.load_data(one_hot=True) # Building deep neural network input_layer = tflearn.input_data(shape=[None, 784]) dense1 = tflearn.fully_connected(input_layer, 64, activation='tanh', regularizer='L2', weight_decay=0.001) dropout1 = tflearn.dropout(dense1, 0.8) dense2 = tflearn.fully_connected(dropout1, 64, activation='tanh', regularizer='L2', weight_decay=0.001) dropout2 = tflearn.dropout(dense2, 0.8) softmax = tflearn.fully_connected(dropout2, 10, activation='softmax') # Regression using SGD with learning rate decay and Top-3 accuracy sgd = tflearn.SGD(learning_rate=0.1, lr_decay=0.96, decay_step=1000) top_k = tflearn.metrics.Top_k(3) net = tflearn.regression(softmax, optimizer=sgd, metric=top_k, loss='categorical_crossentropy') # Training model = tflearn.DNN(net, tensorboard_verbose=1) model.fit(X, Y, n_epoch=5, validation_set=(testX, testY), show_metric=True, run_id="dense_model") ```
aymericdamien commented 8 years ago

This code is working perfectly fine for me. Can you try to re-install tflearn?

wgottschalk commented 8 years ago

I'm getting a similar error. Here's a link to the SO question I asked. http://stackoverflow.com/questions/40200311/tflearn-covnet-example-resulting-in-an-error-w-cifar-10

Are you using python notebooks?

cemysf commented 8 years ago

same error here, while running quickstart tutorial on ipython notebook

Edit: restarting kernel solved the problem

wgottschalk commented 8 years ago

Yeah. I've found when I run the session for the first time it works correctly but I get the index error when I tried to rerun the notebook cell. @cemysf I noticed that in ipython notebooks when using vanilla tensor flow that variables get namespaced to the number of iterations of the cell. My quick fix was to use tf.reset_default_graph() at the top of the cell to clear all of the variables.

Perhaps it's worth submitting a PR to address this issue?

ShivangiM commented 7 years ago

Restarting kernel solved my problem too.

llealgt commented 7 years ago

For me , adding this line before any code do the trick: tf.reset_default_graph()

chrisplyn commented 7 years ago

For me restarting kernel doesn't work, adding tf.reset_default_graph() does.

adhoc-research commented 7 years ago

Restarting the kernel worked. I don't know why this is a recurring problem in Jupyter Notebooks. Some bug I suppose.

annanurov commented 6 years ago

How do you restart a kernel? Also: is there a function in tflearn that replaces tf.reset_default_graph()?

Thank you

annanurov commented 6 years ago

I used:

from tensorflow import reset_default_graph
reset_default_graph()

but same error is there: ValueError: Index (16494) out of range (0-7127)

airportpeople commented 6 years ago

Worked for me! I ran

from tensorflow import reset_default_graph
reset_default_graph()

, then I reran the code that built the network. Then I ran the .fit method.

anandithaaa commented 6 years ago

I still get the same exact error, even with the from tensorflow import reset_default_graph & reset_default_graph().

I've restarted the kernel as well, no luck.

uzairali37 commented 6 years ago

Funzione per me. Grazie!

from tensorflow import reset_default_graph reset_default_graph()

ketan4373 commented 5 years ago

For me, it was working with jupyter-notebook and to tweak a model, I need to reset tensorflow graph by tf.reset_default_graph() every time.

XushaopengHNU commented 3 years ago

I got the same error when using jupyter notebook, and restarting kernel solved the problem.