Skip to content

Instantly share code, notes, and snippets.

@andfoy
Last active September 12, 2015 16:36
Show Gist options
  • Select an option

  • Save andfoy/1baa3e2188b397cc8ae6 to your computer and use it in GitHub Desktop.

Select an option

Save andfoy/1baa3e2188b397cc8ae6 to your computer and use it in GitHub Desktop.
def applyGCN(save_image=False,doTrain=False,doTest=False):
data = np.loadtxt("../inputData/train.csv", dtype=np.float32, delimiter=',', skiprows=1)
test_data = np.loadtxt("../inputData/test.csv", dtype=np.float32, delimiter=',', skiprows=1)
trainingFolder = "../inputData/converted_training/GCN/"
testingFolder = "../inputData/converted_testing/GCN/"
if(doTrain):
aux_data = data.copy()
#############TRAIN_DATA############################
data_to_gcn = data[:, 1:]
labels = data[:, 0]
img_gcn = global_contrast_normalize(data_to_gcn)
print "Saving training images"
with open(trainingFolder + "GCN_traindata.csv", 'wb') as fp:
for x in xrange(0, len(data[:, 1])):
#for x in xrange(0, 1):
image_aux = img_gcn[x, :].copy()
print "size ",image_aux.size
print "np.max ",np.max(image_aux)
print "np.min ",np.min(image_aux)
#aux_data[x, 1:] = image_aux.tolist()
image = np.reshape(image_aux, (28,28))
if save_image is True:
mpimg.imsave(trainingFolder + "GCN_Gray_TrainImage_" + str(x), image, cmap=plt.get_cmap('gray'))
line = image_aux.tolist()
line = reduce(lambda x,y:str(x)+','+str(y), line)+'\n'
line = str(labels[x])+line
fp.write(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment