我正在尝试在 python 中加载 CIFAR-10 数据集,但它显示的键名称完全不符合规范。 dict.keys()
给出以下输出:
dict_keys([b'labels', b'batch_label', b'data', b'filenames'])
按键名称外面的“b”是什么?
我使用数据集网站上给出的代码进行取消:
def unpickle(file):
import pickle
with open(file, 'rb') as fo:
dict = pickle.load(fo, encoding='bytes')
return dict
最佳答案
字符串开头前面的b
表示该字符串是用unicode编码的(它们的类型是byte)。您可以使用 decode
方法将它们转换回 str
。有关 python 和 unicode 的更多信息 here .
关于python - 为什么我的 CIFAR-10 字典键与应有的不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44851477/