gpt4 book ai didi

python - 出现错误 : ValueError: too many values to unpack (expected 2)

转载 作者:行者123 更新时间:2023-12-01 06:52:40 31 4
gpt4 key购买 nike

我正在练习 CNN 的“英特尔图像分类”,我编写了一个函数来从不同文件夹加载数据。但是当我调用该函数时,我收到一个 ValueError ,上面写着“太多值无法解压”。..知道如何解决这个问题吗?

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)

最佳答案

就这么做

x,y=data_load()

然后访问 x[0],x[1] 或以您的方式

关于python - 出现错误 : ValueError: too many values to unpack (expected 2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58928481/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com