关于运行CIFAR-10数据集的cPickle库的问题

时间:2016-03-30 11:04:30

标签: python-2.7 deep-learning conv-neural-network

我目前正在关注CIFAR-10示例。下载http://www.cs.toronto.edu/~kriz/cifar.html上的数据集(CIFAR-10 python版本)。提取文件后,“cifar-10-batches-py”文件夹出来了。

使用此文件夹,我试图查看其数据集。我使用了下面显示的代码。

import cPickle
import os
import numpy as np

def unpickle(file):
    fo = open(file, 'rb')
    dict = cPickle.load(fo)
    fo.close()
    return dict

def conv_data2image(data):
    return np.rollaxis(data.reshape((3,32,32)),0,3)

def get_cifar10(folder):
    tr_data = np.empty((0,32*32*3))
    tr_labels = np.empty(1)
    '''
    32x32x3
    '''
    for i in range(1,6):
        fname = os.path.join(folder, "%s%d" % ("data_batch_", i))
        data_dict = unpickle(fname)
        if i == 1:
            tr_data = data_dict['data']
            tr_labels = data_dict['labels']
        else:
            tr_data = np.vstack((tr_data, data_dict['data']))
            tr_labels = np.hstack((tr_labels, data_dict['labels']))

    data_dict = unpickle(os.path.join(folder, 'test_batch'))
    te_data = data_dict['data']
    te_labels = np.array(data_dict['labels'])

    bm = unpickle(os.path.join(folder, 'batches.meta'))
    label_names = bm['label_names']

    return tr_data, tr_labels, te_data, te_labels, label_names


if __name__ == '__main__':
    datapath = '/Users/sungtegg/Documents/cifar-10-batch.py'

    tr_data10, tr_labels10, te_data10, te_labels10, label_names10 = get_cifar10(datapath)

编译此代码后,

"IOError: [Errno 2] No such file or directory: '/Users/sungtegg/Documents/cifar-10-batch.py/data_batch_1'

这个错误代码出来了。

代码的哪一部分出错了?

1 个答案:

答案 0 :(得分:1)

您的数据路径不正确,您可以从CIFAR10下载并解压缩到任何文件夹。确保指向正确的数据集目录。

datapath ='/ Users / sungtegg / Documents / cifar10-dataset'