IndexError: list index out of range in TensorFlow












1














I got an error ,IndexError: list index out of range.Traceback says



Run id: P0W5X0
Log directory: /tmp/tflearn_logs/
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/Users/xxx/anaconda/xxx/lib/python2.7/site-packages/tflearn/data_flow.py", line 201, in fill_batch_ids_queue
ids = self.next_batch_ids()
File "/Users/xxx/anaconda/xxx/lib/python2.7/site-packages/tflearn/data_flow.py", line 215, in next_batch_ids
batch_start, batch_end = self.batches[self.batch_index]
IndexError: list index out of range


I wrote codes,



# coding: utf-8
import tensorflow as tf
import tflearn

from tflearn.layers.core import input_data,dropout,fully_connected
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.normalization import local_response_normalization
from tflearn.layers.estimator import regression

tf.reset_default_graph()
net = input_data(shape=[None,20000, 4, 42])
net = conv_2d(net, 4, 16, activation='relu')
net = max_pool_2d(net, 1)
net = tflearn.activations.relu(net)
net = dropout(net, 0.5)
net = tflearn.fully_connected(net, 2, activation='softmax')
net = tflearn.regression(net, optimizer='adam', learning_rate=0.5, loss='categorical_crossentropy')

model = tflearn.DNN(net)

model.fit(np.array(trainDataSet).reshape(1,20000, 4, 42), np.array(trainLabel), n_epoch=400, batch_size=32, validation_set=0.1, show_metric=True)


pred = np.array(model.predict(np.array(testDataSet).reshape(1,20000, 4, 42)).argmax(axis=1))

label = np.array(testLabel).argmax(axis=0)
accuracy = np.mean(pred == label, axis=0)

print(accuracy)


I really cannot understand why such an error happens.I tried to rewrite into



model.fit(np.array(trainDataSet).reshape(1,20000, 4, 42), np.array(trainLabel), n_epoch=400, batch_size=1, validation_set=0.1, show_metric=True) 


because bach causes this error,but same error happens.I rewrite another number in this part but same error happens.What is wrong in my codes?How should I fix this?










share|improve this question






















  • tell me about the training data set. What is it and why is it shaped the way it is? it appears from input_data(shape=[None,20000, 4, 42]) that you are expecting some number of batches of shape 20000x4x42 but you are feeding it 1 sample of 20000x4x42 in your model.fit.
    – Panchishin
    Nov 21 '18 at 19:30










  • I cannot understand what you are saying little bit.np.array(trainDataSet).shape is (20000, 4, 42).
    – user10492592
    Nov 22 '18 at 11:47
















1














I got an error ,IndexError: list index out of range.Traceback says



Run id: P0W5X0
Log directory: /tmp/tflearn_logs/
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/Users/xxx/anaconda/xxx/lib/python2.7/site-packages/tflearn/data_flow.py", line 201, in fill_batch_ids_queue
ids = self.next_batch_ids()
File "/Users/xxx/anaconda/xxx/lib/python2.7/site-packages/tflearn/data_flow.py", line 215, in next_batch_ids
batch_start, batch_end = self.batches[self.batch_index]
IndexError: list index out of range


I wrote codes,



# coding: utf-8
import tensorflow as tf
import tflearn

from tflearn.layers.core import input_data,dropout,fully_connected
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.normalization import local_response_normalization
from tflearn.layers.estimator import regression

tf.reset_default_graph()
net = input_data(shape=[None,20000, 4, 42])
net = conv_2d(net, 4, 16, activation='relu')
net = max_pool_2d(net, 1)
net = tflearn.activations.relu(net)
net = dropout(net, 0.5)
net = tflearn.fully_connected(net, 2, activation='softmax')
net = tflearn.regression(net, optimizer='adam', learning_rate=0.5, loss='categorical_crossentropy')

model = tflearn.DNN(net)

model.fit(np.array(trainDataSet).reshape(1,20000, 4, 42), np.array(trainLabel), n_epoch=400, batch_size=32, validation_set=0.1, show_metric=True)


pred = np.array(model.predict(np.array(testDataSet).reshape(1,20000, 4, 42)).argmax(axis=1))

label = np.array(testLabel).argmax(axis=0)
accuracy = np.mean(pred == label, axis=0)

print(accuracy)


I really cannot understand why such an error happens.I tried to rewrite into



model.fit(np.array(trainDataSet).reshape(1,20000, 4, 42), np.array(trainLabel), n_epoch=400, batch_size=1, validation_set=0.1, show_metric=True) 


because bach causes this error,but same error happens.I rewrite another number in this part but same error happens.What is wrong in my codes?How should I fix this?










share|improve this question






















  • tell me about the training data set. What is it and why is it shaped the way it is? it appears from input_data(shape=[None,20000, 4, 42]) that you are expecting some number of batches of shape 20000x4x42 but you are feeding it 1 sample of 20000x4x42 in your model.fit.
    – Panchishin
    Nov 21 '18 at 19:30










  • I cannot understand what you are saying little bit.np.array(trainDataSet).shape is (20000, 4, 42).
    – user10492592
    Nov 22 '18 at 11:47














1












1








1







I got an error ,IndexError: list index out of range.Traceback says



Run id: P0W5X0
Log directory: /tmp/tflearn_logs/
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/Users/xxx/anaconda/xxx/lib/python2.7/site-packages/tflearn/data_flow.py", line 201, in fill_batch_ids_queue
ids = self.next_batch_ids()
File "/Users/xxx/anaconda/xxx/lib/python2.7/site-packages/tflearn/data_flow.py", line 215, in next_batch_ids
batch_start, batch_end = self.batches[self.batch_index]
IndexError: list index out of range


I wrote codes,



# coding: utf-8
import tensorflow as tf
import tflearn

from tflearn.layers.core import input_data,dropout,fully_connected
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.normalization import local_response_normalization
from tflearn.layers.estimator import regression

tf.reset_default_graph()
net = input_data(shape=[None,20000, 4, 42])
net = conv_2d(net, 4, 16, activation='relu')
net = max_pool_2d(net, 1)
net = tflearn.activations.relu(net)
net = dropout(net, 0.5)
net = tflearn.fully_connected(net, 2, activation='softmax')
net = tflearn.regression(net, optimizer='adam', learning_rate=0.5, loss='categorical_crossentropy')

model = tflearn.DNN(net)

model.fit(np.array(trainDataSet).reshape(1,20000, 4, 42), np.array(trainLabel), n_epoch=400, batch_size=32, validation_set=0.1, show_metric=True)


pred = np.array(model.predict(np.array(testDataSet).reshape(1,20000, 4, 42)).argmax(axis=1))

label = np.array(testLabel).argmax(axis=0)
accuracy = np.mean(pred == label, axis=0)

print(accuracy)


I really cannot understand why such an error happens.I tried to rewrite into



model.fit(np.array(trainDataSet).reshape(1,20000, 4, 42), np.array(trainLabel), n_epoch=400, batch_size=1, validation_set=0.1, show_metric=True) 


because bach causes this error,but same error happens.I rewrite another number in this part but same error happens.What is wrong in my codes?How should I fix this?










share|improve this question













I got an error ,IndexError: list index out of range.Traceback says



Run id: P0W5X0
Log directory: /tmp/tflearn_logs/
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/Users/xxx/anaconda/xxx/lib/python2.7/site-packages/tflearn/data_flow.py", line 201, in fill_batch_ids_queue
ids = self.next_batch_ids()
File "/Users/xxx/anaconda/xxx/lib/python2.7/site-packages/tflearn/data_flow.py", line 215, in next_batch_ids
batch_start, batch_end = self.batches[self.batch_index]
IndexError: list index out of range


I wrote codes,



# coding: utf-8
import tensorflow as tf
import tflearn

from tflearn.layers.core import input_data,dropout,fully_connected
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.normalization import local_response_normalization
from tflearn.layers.estimator import regression

tf.reset_default_graph()
net = input_data(shape=[None,20000, 4, 42])
net = conv_2d(net, 4, 16, activation='relu')
net = max_pool_2d(net, 1)
net = tflearn.activations.relu(net)
net = dropout(net, 0.5)
net = tflearn.fully_connected(net, 2, activation='softmax')
net = tflearn.regression(net, optimizer='adam', learning_rate=0.5, loss='categorical_crossentropy')

model = tflearn.DNN(net)

model.fit(np.array(trainDataSet).reshape(1,20000, 4, 42), np.array(trainLabel), n_epoch=400, batch_size=32, validation_set=0.1, show_metric=True)


pred = np.array(model.predict(np.array(testDataSet).reshape(1,20000, 4, 42)).argmax(axis=1))

label = np.array(testLabel).argmax(axis=0)
accuracy = np.mean(pred == label, axis=0)

print(accuracy)


I really cannot understand why such an error happens.I tried to rewrite into



model.fit(np.array(trainDataSet).reshape(1,20000, 4, 42), np.array(trainLabel), n_epoch=400, batch_size=1, validation_set=0.1, show_metric=True) 


because bach causes this error,but same error happens.I rewrite another number in this part but same error happens.What is wrong in my codes?How should I fix this?







python tensorflow tflearn






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 13:46









user10492592

184




184












  • tell me about the training data set. What is it and why is it shaped the way it is? it appears from input_data(shape=[None,20000, 4, 42]) that you are expecting some number of batches of shape 20000x4x42 but you are feeding it 1 sample of 20000x4x42 in your model.fit.
    – Panchishin
    Nov 21 '18 at 19:30










  • I cannot understand what you are saying little bit.np.array(trainDataSet).shape is (20000, 4, 42).
    – user10492592
    Nov 22 '18 at 11:47


















  • tell me about the training data set. What is it and why is it shaped the way it is? it appears from input_data(shape=[None,20000, 4, 42]) that you are expecting some number of batches of shape 20000x4x42 but you are feeding it 1 sample of 20000x4x42 in your model.fit.
    – Panchishin
    Nov 21 '18 at 19:30










  • I cannot understand what you are saying little bit.np.array(trainDataSet).shape is (20000, 4, 42).
    – user10492592
    Nov 22 '18 at 11:47
















tell me about the training data set. What is it and why is it shaped the way it is? it appears from input_data(shape=[None,20000, 4, 42]) that you are expecting some number of batches of shape 20000x4x42 but you are feeding it 1 sample of 20000x4x42 in your model.fit.
– Panchishin
Nov 21 '18 at 19:30




tell me about the training data set. What is it and why is it shaped the way it is? it appears from input_data(shape=[None,20000, 4, 42]) that you are expecting some number of batches of shape 20000x4x42 but you are feeding it 1 sample of 20000x4x42 in your model.fit.
– Panchishin
Nov 21 '18 at 19:30












I cannot understand what you are saying little bit.np.array(trainDataSet).shape is (20000, 4, 42).
– user10492592
Nov 22 '18 at 11:47




I cannot understand what you are saying little bit.np.array(trainDataSet).shape is (20000, 4, 42).
– user10492592
Nov 22 '18 at 11:47












1 Answer
1






active

oldest

votes


















0














I also had the same problem with you. My solution is making the number of n_epoch equal to your row's number of the dataset. For example, my array's shape is 461*5, the value of the n_epoch is 461. you can also make the value a little bit bigger or shorter than your row's number. In my code, 500 or 400 is also useful.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413490%2findexerror-list-index-out-of-range-in-tensorflow%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I also had the same problem with you. My solution is making the number of n_epoch equal to your row's number of the dataset. For example, my array's shape is 461*5, the value of the n_epoch is 461. you can also make the value a little bit bigger or shorter than your row's number. In my code, 500 or 400 is also useful.






    share|improve this answer


























      0














      I also had the same problem with you. My solution is making the number of n_epoch equal to your row's number of the dataset. For example, my array's shape is 461*5, the value of the n_epoch is 461. you can also make the value a little bit bigger or shorter than your row's number. In my code, 500 or 400 is also useful.






      share|improve this answer
























        0












        0








        0






        I also had the same problem with you. My solution is making the number of n_epoch equal to your row's number of the dataset. For example, my array's shape is 461*5, the value of the n_epoch is 461. you can also make the value a little bit bigger or shorter than your row's number. In my code, 500 or 400 is also useful.






        share|improve this answer












        I also had the same problem with you. My solution is making the number of n_epoch equal to your row's number of the dataset. For example, my array's shape is 461*5, the value of the n_epoch is 461. you can also make the value a little bit bigger or shorter than your row's number. In my code, 500 or 400 is also useful.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 24 '18 at 11:50









        taylor

        150211




        150211






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413490%2findexerror-list-index-out-of-range-in-tensorflow%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'