Tensorflow ValueError: Too many vaues to unpack (expected 2)

允我心安 提交于 2019-12-06 13:52:56

You are yielding your results in an incorrect way:

yield(images[i:i+batch_size]) #,labels_list[i:i+batch_size])

which gives you one value that is yielded, but when you call you method you are expecting two values yielded:

images,labal = create_batches(10)

Either yield two values , like:

yield (images[i:i+batch_size] , labels_list[i:i+batch_size])

(uncomment) or just expect one.

Edit: You should use parentheses on both the yield and when receiving the results like this:

#when yielding, remember that yield returns a Generator, therefore the ()
yield (images[i:i+batch_size] , labels_list[i:i+batch_size])

#When receiving also, even though this is not correct
(images,labal) = create_batches(10)

However this is not the way I have used the yield option; one usually iterates over your method that returns the generator, in your case it should look something like this:

#do the training several times as you have
for i in range(10000):
    #now here you should iterate over your generator, in order to gain its benefits
    #that is you dont load the entire result set into memory
    #remember to receive with () as mentioned
    for (images, labal) in create_batches(10):
        #do whatever you want with that data
        sess.run(train_step, feed_dict={imgs:images, lbls: labal})

You can also check this question regarding the user of yield and generators.

You commented out the second return item.

        yield(images[i:i+batch_size])    #,labels_list[i:i+batch_size])

You yield a single list to assign to images, and there's nothing left for labal. Remove that comment mark, or yield a dummy value if you're in debugging mode.


UPDATE

Separate this line and check what you're trying to return:

result = (images[i:i+batch_size],
          labels_list[i:i+batch_size])
print len(result), result
return result
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!