Unable to load CIFAR-10 dataset: Invalid load key #39;x1f#39;(无法加载 CIFAR-10 数据集:加载键“x1f无效)
问题描述
我目前正在使用 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"无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法加载 CIFAR-10 数据集:加载键“x1f"无效


基础教程推荐
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01