Last active
July 20, 2016 00:37
-
-
Save bigsnarfdude/44625ea46099b4e953e7eaf272d8b9c3 to your computer and use it in GitHub Desktop.
rehydrate mnist using python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import numpy | |
import cv2 | |
import matplotlib.pyplot as plt | |
reader = csv.reader(open('train.csv','rb')) | |
header = reader.next() | |
read_data = [] | |
for row in reader: | |
read_data.append(row) | |
print("Working on:") | |
data = numpy.array(read_data) | |
ro = numpy.zeros((28,28,3)) | |
print(data.shape) | |
for image_number in range(data.shape[0]): | |
label = read_data[image_number][0] | |
for i in range(0,27): | |
for j in range(0,27): | |
ro[i,j,0] = data[image_number,j+i*28] | |
ro[i,j,1] = data[image_number,j+i*28] | |
ro[i,j,2] = data[image_number,j+i*28] | |
cv2.imwrite('image_' + label + '_' + str(image_number) + '_' + '.jpg', ro) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment