Yield Valueerror: Too Many Vaues To Unpack (expected 2) In Python
I have an issue trying to implement the regression solution proposed in this thread. Using Keras ImageDataGenerator in a regression model Another stack question had a similar issu
Solution 1:
The error has nothing to do with np.asarray
. The function regression_flow_from_directory
contains a yield statement. Therefore when you call it you get, not a tuple of yielded values, but a generator object. That's just one object, which you are trying to unpack into a two-element tuple. That's the reason for the error message.
Solution 2:
(x_train,y_train) = regression_flow_from_directory(
train_datagen.flow_from_directory(
'figs/train', # thisis the target directory
batch_size=batch_size,
class_mode='sparse'),
np.asarray(list_of_values))
The problem appears to be that your routine regression_flow_from_directory
returns more than two values. You have a pair on the left of that assignment, so you must have exactly two values on the right. Try printing your actual return value, rather than the components. For instance:
result= regression_flow_from_directory(...)
print (result)
(x,y) =result
You'll see the problem: you have to iterate through regression_flow_from_directory
with those arguments.
Trivial example of the principal:
>>>(x, y) = 1, 2>>>x
1
>>>y
2
>>>(x, y) = 1, 2, 3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: too many values to unpack
Post a Comment for "Yield Valueerror: Too Many Vaues To Unpack (expected 2) In Python"