我正在Windows的Jupyter Notebook上使用Python 3和OpenCV进行编程。 我正在关注本教程:http://machinelearninguru.com/deep_learning/data_preparation/hdf5/hdf5.html
但是我得到这个错误:
ValueError:没有足够的值可解包(预期2,得到0)
发件人:
---> 15个地址,标签= zip(* c)
此代码应列出我的图像并为它们添加标签,但它将无法正常工作。这是代码:
from random import shuffle
import glob
shuffle_data = True # shuffle the addresses before saving
hdf5_path = 'my path/PetImages/dataset.hdf5' # address to where you want to save the hdf5 file
cat_dog_train_path = 'my path/PetImages/Train/*.jpg'
addrs = glob.glob(cat_dog_train_path)
labels = [0 if 'cat' in addr else 1 for addr in addrs] # 0 = Cat, 1 = Dog
# to shuffle data
if shuffle_data:
c = list(zip(addrs, labels))
shuffle(c)
addrs, labels = zip(*c)
# Divide the hata into 60% train, 20% validation, and 20% test
train_addrs = addrs[0:int(0.6*len(addrs))]
train_labels = labels[0:int(0.6*len(labels))]
val_addrs = addrs[int(0.6*len(addrs)):int(0.8*len(addrs))]
val_labels = labels[int(0.6*len(addrs)):int(0.8*len(addrs))]
test_addrs = addrs[int(0.8*len(addrs)):]
test_labels = labels[int(0.8*len(labels)):]```