In [9]:
from keras.models import Sequential
from keras.layers import Dense
from keras.models import model_from_json
import numpy as np
import os
import cv2
%matplotlib inline
In [5]:
testLoc = '../data/test1/'
data = [os.path.join(testLoc,f) for f in os.listdir(testLoc)]
In [7]:
def imageToFeatures(x,size=(32,32)):
return cv2.resize(x,size).flatten()
testX = [imageToFeatures(cv2.imread(x)) for x in data]
In [10]:
testX = np.array(testX)
In [11]:
testX = testX/255.0
In [12]:
json_file = open('model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
# load weights into new model
loaded_model.load_weights("model.h5")
print("Loaded model from disk")
In [20]:
output = loaded_model.predict_proba(batch_size=32,x=testX)
In [23]:
output.shape
Out[23]:
In [26]:
import csv
with open('keras_simple_nn.csv','w') as csvFile:
writer = csv.writer(csvFile)
writer.writerow(['id','label'])
for i,value in enumerate(output[:,1]):
writer.writerow([i+1,value])
In [27]:
#from matplotlib import pyplot as plt
#plt.imshow(plt.imread(data[2]))
In [ ]: