Exemplo n.º 1
0
 def POST(self):
     i = web.input()
     uri = i['img']
     data_to_64 = re.search(r'base64,(.*)', uri).group(1)
     data = StringIO.StringIO()
     # data.write(base64.decodestring(data_to_64))
     data.write(data_to_64.decode('base64'))
     data.seek(0)
     im = resize_image(data)
     print np.asarray(im)
     X = np.asarray(im).flatten()
     label = classifier.predict(normalize_features(X))
     print label
     return label[0]
Exemplo n.º 2
0
import numpy as np
import mnist

from helper import normalize_features, random_sampling
from sklearn import datasets, svm, metrics
from sklearn.externals import joblib

training = mnist.DataReader('train')
testing = mnist.DataReader('t10k')

data, target = random_sampling(training.data, training.target, 3000)

# Gaussian Kernel, so far the best
classifier = svm.SVC(gamma=0.03)
classifier.fit(normalize_features(data), target.ravel())

joblib.dump(classifier, 'model.pkl')

print 'Training done, modek.pkl saved.'

predicted = classifier.predict(normalize_features(testing.data))
expected = testing.target.ravel()

print("Classification report for classifier %s:\n%s\n"
      % (classifier, metrics.classification_report(expected, predicted)))
print("Confusion matrix:\n%s" % metrics.confusion_matrix(expected, predicted))