-
Notifications
You must be signed in to change notification settings - Fork 6
/
ndarr2img.py
44 lines (37 loc) · 1.7 KB
/
ndarr2img.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import time
import numpy as np
from scipy.misc import imsave
stime = time.time()
from idx2nparray_py3 import train_images_array,test_images_array,train_labels_array,test_labels_array
print("\nTime for loading numpy arrays from idx2ndarray :: "+str(time.time()-stime)+" seconds\n")
trainImgshape = train_images_array.shape
trainLabelshape = train_labels_array.shape
testImgshape = test_images_array.shape
testLabelshape = test_labels_array.shape
stime = time.time()
training_folderName = 'training_set_images/'
fileNameLen = len(str(trainImgshape[0]))
nIter = trainImgshape[0]+1
for n in xrange(1,nIter):
filename = '0'*(fileNameLen - len(str(n)))+str(n)+'.jpg'
#print filename
imsave(training_folderName+filename,train_images_array[n-1,:,:])
print("Time for converting training dataset array to images :: "+str(time.time()-stime)+" seconds\n")
stime = time.time()
test_folderName = 'test_set_images/'
fileNameLen = len(str(testImgshape[0]))
nIter = testImgshape[0]+1
for n in xrange(1,nIter):
filename = '0'*(fileNameLen - len(str(n)))+str(n)+'.jpg'
#print filename
imsave(test_folderName+filename,test_images_array[n-1,:,:])
print("Time for converting test dataset array to images :: "+str(time.time()-stime)+" seconds\n")
stime = time.time()
trainingLabelFileName = 'training_set_labels'
np.save(trainingLabelFileName,train_labels_array,allow_pickle=False,fix_imports=False)
print("Time for saving Training Labels array as .npy file :: "+str(time.time()-stime)+" seconds\n")
stime = time.time()
testLabelFileName = 'test_set_labels'
np.save(testLabelFileName,test_labels_array,allow_pickle=False,fix_imports=False)
print("Time for saving Test Labels array as .npy file :: "+str(time.time()-stime)+" seconds\n")
#saved as .npy