Skip to content

Instantly share code, notes, and snippets.

@leogout
Created August 21, 2017 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leogout/b3f5ab92243d89a96017e3038bd24acc to your computer and use it in GitHub Desktop.
Save leogout/b3f5ab92243d89a96017e3038bd24acc to your computer and use it in GitHub Desktop.
Converts cifar-10 numpy lists to python lists
import pickle
def unpickle(file):
with open(file, 'rb') as fo:
dic = pickle.load(fo, encoding='bytes')
fo.close()
return dic
def repickle(file, data):
with open(file, 'wb') as f:
pickle.dump(data, f)
def convert_cifar10(from_folder, to_folder):
test_data = unpickle('%s/test_batch' % from_folder)
test_data[b'data'] = test_data[b'data'].tolist()
repickle('%s/test_batch' % to_folder, test_data)
for i in range(1, 6):
training_data = unpickle('%s/data_batch_%d' % (from_folder, i))
training_data[b'data'] = training_data[b'data'].tolist()
repickle('%s/data_batch_%d' % (to_folder, i), training_data)
# Make sure you have the './cifar10_list' created first
convert_cifar10('./cifar10', './cifar10_list')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment