Skip to content

Instantly share code, notes, and snippets.

@joeyism
Last active August 11, 2018 19:00
Show Gist options
  • Save joeyism/94c8c8be2f69676e0b56e8ac1cfb18b8 to your computer and use it in GitHub Desktop.
Save joeyism/94c8c8be2f69676e0b56e8ac1cfb18b8 to your computer and use it in GitHub Desktop.
import numpy as np
import pickle
def __extract_file__(fname):
with open(fname, 'rb') as fo:
d = pickle.load(fo, encoding='bytes')
return d
def __unflatten_image__(img_flat):
img_R = img_flat[0:1024].reshape((32, 32))
img_G = img_flat[1024:2048].reshape((32, 32))
img_B = img_flat[2048:3072].reshape((32, 32))
img = np.dstack((img_R, img_G, img_B))
return img
def __extract_reshape_file__(fname):
res = []
d = __extract_file__(fname)
images = d[b"data"]
labels = d[b"labels"]
for image, label in zip(images, labels):
res.append((__unflatten_image__(image), label))
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment