Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List index out of range #408

Open
rajendraranabhat opened this issue Oct 19, 2016 · 15 comments
Open

List index out of range #408

rajendraranabhat opened this issue Oct 19, 2016 · 15 comments

Comments

@rajendraranabhat
Copy link

rajendraranabhat commented Oct 19, 2016

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

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
Copy link
Member

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

@wgottschalk
Copy link

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
Copy link

cemysf commented Oct 23, 2016

same error here, while running quickstart tutorial on ipython notebook

Edit: restarting kernel solved the problem

@wgottschalk
Copy link

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
Copy link

Restarting kernel solved my problem too.

@llealgt
Copy link

llealgt commented Apr 1, 2017

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

@chrisplyn
Copy link

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

@rushatrai
Copy link

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

@annanurov
Copy link

annanurov commented Feb 7, 2018

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

Thank you

@annanurov
Copy link

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
Copy link

airportpeople commented Mar 13, 2018

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
Copy link

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
Copy link

Funzione per me. Grazie!

from tensorflow import reset_default_graph
reset_default_graph()

@ketan4373
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests