问题描述
我目前正在使用 TensorFlow 中的一些神经网络 - 我决定尝试使用 CIFAR-10 数据集.我从网站下载了CIFAR-10 python"数据集:https://www.cs.toronto.edu/~kriz/cifar.html.
I'm currently playing around with some neural networks in TensorFlow - I decided to try working with the CIFAR-10 dataset. I downloaded the "CIFAR-10 python" dataset from the website: https://www.cs.toronto.edu/~kriz/cifar.html.
在 Python 中,我也尝试直接复制提供的用于加载数据的代码:
In Python, I also tried directly copying the code that is provided to load the data:
def unpickle(file):
import pickle
with open(file, 'rb') as fo:
dict = pickle.load(fo, encoding='bytes')
return dict
但是,当我运行它时,我最终得到以下错误:_pickle.UnpicklingError: invalid load key, 'x1f'.
我也尝试使用 gzip 模块打开文件(with gzip.open(file, 'rb') as fo:
),但这也不起作用.
However, when I run this, I end up with the following error: _pickle.UnpicklingError: invalid load key, 'x1f'.
I've also tried opening the file using the gzip module (with gzip.open(file, 'rb') as fo:
), but this didn't work either.
是数据集很糟糕,还是代码有问题?如果数据集不好,我在哪里可以获得适合 CIFAR-10 的数据集?
Is the dataset simply bad, or this an issue with code? If the dataset's bad, where can I obtain the proper dataset for CIFAR-10?
推荐答案
解压你的 *.gz 文件并使用这段代码
Extract your *.gz file and use this code
from six.moves import cPickle
f = open("path/data_batch_1", 'rb')
datadict = cPickle.load(f,encoding='latin1')
f.close()
X = datadict["data"]
Y = datadict['labels']
这篇关于无法加载 CIFAR-10 数据集:加载键“x1f"无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!