Getting an error: ValueError: too many values to unpack (expected 2)

valueerror: too many values to unpack (expected 2) pandas
valueerror too many values to unpack (expected 2) opencv
valueerror: too many values to unpack (expected 2) list
valueerror too many values to unpack (expected 2) for loop
valueerror too many values to unpack (expected 2) dictionary
valueerror too many values to unpack (expected 2) collocations
too many values to unpack (expected 2) python for loop
valueerror: too many values to unpack (expected 2) django

I was practicing CNN on 'intel image Classification' and I wrote a function to load the data from different folders. But when I call the function, I'am getting a ValueError which says 'Too many values to unpack'..Any idea on how to fix this ?

def data_load():
datasets = ['seg_train\seg_train', 'seg_test\seg_test']
size = (150, 150)
output = []
for dataset in datasets:
    directory = os.getcwd() + '/' + dataset
    images = []
    labels = []
    for folder in os.listdir(directory):
        curr_label = class_labels[folder]
        for file in os.listdir(directory + '/' + folder):
            img_path = directory + '/' + folder + '/' + file
            curr_image = cv2.imread(img_path)
            curr_image = cv2.resize(curr_image, size)
            images.append(curr_image)
            labels.append(curr_label)
            images, labels = shuffle(images, labels)

            output.append((images, labels))
return output

(X_train, y_train), (X_test, y_test) = data_load()

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-36-ec0ae2384d47> in <module>
----> 1 (X_train, y_train), (X_test, y_test) = data_load()

ValueError: too many values to unpack (expected 2)

just do

x,y=data_load()

then access x[0],x[1] or in your way

'too many values to unpack', iterating over a dict , python. I am getting the 'too many values to unpack' error. Any idea Since Python 3 iteritems() is no longer supported. Use items() This returns an iterator over the dictionary, which gives you a tuple(key, value) You could also do it other way, where you get values using keys in the dictionary. for key in� while writing featuresets function, I am getting the below error: ValueError: too many values to unpack (expected 2) I know the above logic works for any kind of list or dictionary, but I wanted to use similar kind of logic for Dataframe.

Snehal R Ghungurde answered correctly. I thought I would elaborate.

Your output.append((images, labels)) is producing a list of tuples, where each tuple consists of two lists. However you are trying to unpack this list into two separate tuples.

Your current approach is to load both the training and the testing data sets at once. I would write a general function that does the following: Provided with a path, this function will read all images and return tuples with the images and labels.

It is also instructive to place variables as parameters (path, size).

def data_load(path, size=(150, 150)):
    """
    Provided with a path, this function will read 
    all images and return tuples with the images and labels
    """
    output = []
    images = []
    labels = []
    for folder in os.listdir(directory):
        curr_label = class_labels[folder]
        for file in os.listdir(directory + '/' + folder):
            img_path = directory + '/' + folder + '/' + file
            curr_image = cv2.imread(img_path)
            curr_image = cv2.resize(curr_image, size)
            images.append(curr_image)
            labels.append(curr_label)
            images, labels = shuffle(images, labels)
            output.append((images, labels))
    return output

training_set = 'seg_train\seg_train'
testing_set = 'seg_test\seg_test'

x_train, y_train = data_load(training_set)
x_test, y_test = data_load(testing_set)

ValueError: Too many values to unpack in Python, PythonValueError: Too many values to unpack in Python, This error occurs when we assign more number of values and less number of� Too Many Values to Unpack. Sometimes, you might need to unpack the elements or values from a list. You can assign the extracted values into variables or another new list. But, if the number of list elements is more than the number of variables, an error will be raised during the assignment. The error ValueError Too many values to unpack in Python will be thrown by Python.

This error is raised because data_load is returning more than two variables, and you are trying to assign it to two. If you add the line print(len(output)) before the return statement, you'll see that it's length is more than two.

"Too many values to unpack" error?!, you are iterating over (text, vowels) , that is a tuple of 2 values, your loop will iterate twice and for each of those values you are asking python to unpack 2 values,� ValueError: too many values to unpack (expected 2) This means that either app_label or model_name has a dot (.) in it. My money is on the former as model names are automatically generated

valueError too many values to unpack, It looks like you're using Python 3, and I'll imagine an input like so last): File "< stdin>", line 1, in <module> ValueError: too many values to unpack (expected 2) What you could do is get the string from input(), use str.split (based on whether you want to Error: ValueError Traceback (most recent call last)� Python ValueError: too many values to unpack, occurs during a multiple-assignment where you either don't have enough objects to assign to the variables or you have more objects to assign than variables.

What means "Too many values to unpack" message?, python. Can any one give me the cause of the above error message. Comment a, b = (1, 2, 3) # There is too many value to unpack ;) a, b = (1, 2) # That will work a, ValueError is a standard Exception raised by various methods that perform� ValueError: too many values to unpack (expected 2) I'm trying to loop with two variables a set with 20 objects. But I keep getting a "ValueError: too many values to unpack (expected 2)" response.

Python: Solving ValueError: Too many values to unpack, This Python tutorial video covers the "ValueError: too many values to unpack." This error is Duration: 3:08 Posted: Jan 9, 2014 Also, please understand that many of the models included in this repository are experimental and research-style code. If you open a GitHub issue, here is our policy: It must be a bug, a feature request, or a significant problem with documentation (for small docs fixes please send a PR instead).