teggme
teggme

Reputation: 37

Problems about cPickle library on running CIFAR-10 dataset

I am currently following CIFAR-10 example up. Downloaded dataset on http://www.cs.toronto.edu/~kriz/cifar.html (CIFAR-10 python version). After extracted file, "cifar-10-batches-py" folder came out.

With this folder, I tried to see its dataset. I used the code shown below.

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)

After compiling this code,

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

this error code came out.

What section of the code got wrong?

Upvotes: 0

Views: 2855

Answers (1)

Jack Goh
Jack Goh

Reputation: 36

Your datapath is incorrect, you can download from CIFAR10 and extract to any folder. Make sure you point to correct dataset directory.

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

Upvotes: 1

Related Questions