Tflearn: IndexError: list index out of range using the minimal example from README.md

Created on 5 Mar 2017  路  4Comments  路  Source: tflearn/tflearn

While using this code (to re-create):

  • I am using tf 1.0.0
  • Docker image: jupyter/datascience-notebook plus tf conda-installed
from sklearn.preprocessing import LabelEncoder
from keras.utils import np_utils
labels = ['Male', 'Female'] * 5 
encoder = LabelEncoder()
encoder.fit(labels)
labels = encoder.transform(labels)
labels = np_utils.to_categorical(labels)
labels.shape

results = np.ndarray(shape=(10,2623))

tflearn.init_graph(num_cores=8, gpu_memory_fraction=0.5)

net = tflearn.input_data(shape=[None, 2623])
net = tflearn.fully_connected(net, 2, activation='softmax')
net = tflearn.regression(net, optimizer='adam', loss='categorical_crossentropy')

model = tflearn.DNN(net)
model.fit(results, labels)

I got the following error:

IndexError                                Traceback (most recent call last)
<ipython-input-164-dc175f8e6993> in <module>()
     10 
     11 model = tflearn.DNN(net)
---> 12 model.fit(results, labels)

/opt/conda/lib/python3.5/site-packages/tflearn/models/dnn.py in fit(self, X_inputs, Y_targets, n_epoch, validation_set, show_metric, batch_size, shuffle, snapshot_epoch, snapshot_step, excl_trainops, validation_batch_size, run_id, callbacks)
    181         # TODO: check memory impact for large data and multiple optimizers
    182         feed_dict = feed_dict_builder(X_inputs, Y_targets, self.inputs,
--> 183                                       self.targets)
    184         feed_dicts = [feed_dict for i in self.train_ops]
    185         val_feed_dicts = None

/opt/conda/lib/python3.5/site-packages/tflearn/utils.py in feed_dict_builder(X, Y, net_inputs, net_targets)
    287                 X = [X]
    288             for i, x in enumerate(X):
--> 289                 feed_dict[net_inputs[i]] = x
    290         else:
    291             # If a dict is provided

IndexError: list index out of range

Most helpful comment

See this issue (link)

TLDR;
Restart the jupyter kernel or call tf.reset_default_graph() at the top of the cell.

All 4 comments

See this issue (link)

TLDR;
Restart the jupyter kernel or call tf.reset_default_graph() at the top of the cell.

Cheers, that worked! Might be good to add that to the README?

thank u @shark8me ! ur comment saved me!

annoying error, please fix it

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SebastianKlein picture SebastianKlein  路  3Comments

luoruisichuan picture luoruisichuan  路  5Comments

ruizhaogit picture ruizhaogit  路  4Comments

bnaul picture bnaul  路  3Comments

smithdir101 picture smithdir101  路  5Comments