import _pickle as cPickle
f=open('文件名.pkl', 'rb')
data = cPickle.load(f, encoding='bytes')
print(data)
print(data.keys())
dataset = data['dataset']
labels = data['labels']
print('shape:',dataset.shape,labels.shape)
环境是python3.5
在print(data)后数据可以显示出来,如下所示。但是执行第二段的时候,会报错,KeyError: 'dataset',可是这个数据集中(如下)是有'dataset'的,求解。
{b'labels': array([[0],
[0],
....
[1]], dtype=int64), b'dataset': array([[[-4.00000000e-02, -3.90000000e-02, 9.00000000e-03, ...,
-7.88950492e-01, -1.50975928e+00, -1.99603159e+00],
...,
[-4.90000000e-02, -2.00000000e-02, 1.60000000e-02, ...,
-7.86839409e-01, -1.50889891e+00, -1.42230309e+00]],
[[ 4.20000000e-02, -3.20000000e-02, -6.40000000e-02, ...,
-7.01993713e-01, -5.70277292e-01, -3.32443958e+00]]])}
data.keys()的打印结果如下
dict_keys([b'labels', b'dataset'])