我正在尝试读取 CIFAR10 数据集,这些数据集是从 https://www.cs.toronto.edu/~kriz/cifar.html > 分批提供的。我正在尝试使用 pickle 将其放入数据框中并读取其中的“数据”部分。但我收到这个错误。
KeyError Traceback (most recent call last)
<ipython-input-24-8758b7a31925> in <module>()
----> 1 unpickle('datasets/cifar-10-batches-py/test_batch')
<ipython-input-23-04002b89d842> in unpickle(file)
3 fo = open(file, 'rb')
4 dict = pickle.load(fo, encoding ='bytes')
----> 5 X = dict['data']
6 fo.close()
7 return dict
键错误:“数据”。
我正在使用 ipython,这是我的代码:
def unpickle(file):
fo = open(file, 'rb')
dict = pickle.load(fo, encoding ='bytes')
X = dict['data']
fo.close()
return dict
unpickle('datasets/cifar-10-batches-py/test_batch')
原文由 decipher 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以通过下面给出的代码读取 cifar 10 数据集,只需确保您提供了放置批次的写入目录