Skip to content

Instantly share code, notes, and snippets.

@housecricket
Created May 29, 2021 08:42
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 housecricket/9b524a8fa95f61e9e5421b225d827c46 to your computer and use it in GitHub Desktop.
Save housecricket/9b524a8fa95f61e9e5421b225d827c46 to your computer and use it in GitHub Desktop.
def load_az_dataset(dataset_path):
# initialize the list of data and labels
data = []
labels = []
# loop over the rows of the A-Z handwritten digit dataset
for row in open(dataset_path):
# parse the label and image from the row
row = row.split(",")
label = int(row[0])
image = np.array([int(x) for x in row[1:]], dtype="uint8")
# images are represented as single channel (grayscale) images
# that are 28x28=784 pixels -- we need to take this flattened
# 784-d list of numbers and reshape them into a 28x28 matrix
image = image.reshape((28, 28))
# update the list of data and labels
data.append(image)
labels.append(label)
# convert the data and labels to NumPy arrays
data = np.array(data, dtype="float32")
labels = np.array(labels, dtype="int")
# return a 2-tuple of the A-Z data and labels
return (data, labels)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment