|
@@ -1,11 +1,10 @@
|
|
|
#!/usr/bin/python
|
|
#!/usr/bin/python
|
|
|
-from cPickle import load
|
|
|
|
|
from sys import argv, exit
|
|
from sys import argv, exit
|
|
|
-from pylab import imsave, plot, subplot, imshow, show, axis, title
|
|
|
|
|
|
|
+from pylab import subplot, imshow, show, axis, title
|
|
|
from math import sqrt, ceil
|
|
from math import sqrt, ceil
|
|
|
-import os
|
|
|
|
|
|
|
|
|
|
-from Classifier import Classifier
|
|
|
|
|
|
|
+from create_characters import load_test_set
|
|
|
|
|
+from create_classifier import load_classifier
|
|
|
|
|
|
|
|
if len(argv) < 3:
|
|
if len(argv) < 3:
|
|
|
print 'Usage: python %s NEIGHBOURS BLUR_SCALE' % argv[0]
|
|
print 'Usage: python %s NEIGHBOURS BLUR_SCALE' % argv[0]
|
|
@@ -13,20 +12,17 @@ if len(argv) < 3:
|
|
|
|
|
|
|
|
neighbours = int(argv[1])
|
|
neighbours = int(argv[1])
|
|
|
blur_scale = float(argv[2])
|
|
blur_scale = float(argv[2])
|
|
|
-suffix = '_%s_%s' % (blur_scale, neighbours)
|
|
|
|
|
|
|
|
|
|
-test_set_file = 'test_set%s.dat' % suffix
|
|
|
|
|
-classifier_file = 'classifier%s.dat' % suffix
|
|
|
|
|
|
|
+# Load classifier
|
|
|
|
|
+classifier = load_classifier(neighbours, blur_scale, verbose=1)
|
|
|
|
|
|
|
|
-print 'Loading classifier...'
|
|
|
|
|
-classifier = Classifier(filename=classifier_file)
|
|
|
|
|
-classifier.neighbours = neighbours
|
|
|
|
|
|
|
+# Load test set
|
|
|
|
|
+test_set = load_test_set(neighbours, blur_scale, verbose=1)
|
|
|
|
|
|
|
|
-print 'Loading test set...'
|
|
|
|
|
-test_set = load(file(test_set_file, 'r'))
|
|
|
|
|
|
|
+# Classify each character in the test set, remembering all faulty
|
|
|
|
|
+# classified characters
|
|
|
l = len(test_set)
|
|
l = len(test_set)
|
|
|
matches = 0
|
|
matches = 0
|
|
|
-#classified = {}
|
|
|
|
|
classified = []
|
|
classified = []
|
|
|
|
|
|
|
|
for i, char in enumerate(test_set):
|
|
for i, char in enumerate(test_set):
|
|
@@ -35,13 +31,6 @@ for i, char in enumerate(test_set):
|
|
|
if char.value != prediction:
|
|
if char.value != prediction:
|
|
|
classified.append((char, prediction))
|
|
classified.append((char, prediction))
|
|
|
|
|
|
|
|
- #key = '%s_as_%s' % (char.value, prediction)
|
|
|
|
|
-
|
|
|
|
|
- #if key not in classified:
|
|
|
|
|
- # classified[key] = [char]
|
|
|
|
|
- #else:
|
|
|
|
|
- # classified[key].append(char)
|
|
|
|
|
-
|
|
|
|
|
print '"%s" was classified as "%s"' \
|
|
print '"%s" was classified as "%s"' \
|
|
|
% (char.value, prediction)
|
|
% (char.value, prediction)
|
|
|
else:
|
|
else:
|
|
@@ -50,8 +39,7 @@ for i, char in enumerate(test_set):
|
|
|
print '%d of %d (%d%% done)' % (i + 1, l, round(100 * (i + 1) / l))
|
|
print '%d of %d (%d%% done)' % (i + 1, l, round(100 * (i + 1) / l))
|
|
|
|
|
|
|
|
print '\n%d matches (%d%%), %d fails' % (matches, \
|
|
print '\n%d matches (%d%%), %d fails' % (matches, \
|
|
|
- round(100 * matches / l), \
|
|
|
|
|
- len(test_set) - matches)
|
|
|
|
|
|
|
+ round(100 * matches / l), len(test_set) - matches)
|
|
|
|
|
|
|
|
# Show a grid plot of all faulty classified characters
|
|
# Show a grid plot of all faulty classified characters
|
|
|
print 'Plotting faulty classified characters...'
|
|
print 'Plotting faulty classified characters...'
|
|
@@ -66,16 +54,3 @@ for i, pair in enumerate(classified):
|
|
|
axis('off')
|
|
axis('off')
|
|
|
|
|
|
|
|
show()
|
|
show()
|
|
|
-
|
|
|
|
|
-#print 'Saving faulty classified characters...'
|
|
|
|
|
-#folder = '../images/faulty/'
|
|
|
|
|
-#
|
|
|
|
|
-#if not os.path.exists(folder):
|
|
|
|
|
-# os.mkdir(folder)
|
|
|
|
|
-#
|
|
|
|
|
-#for filename, chars in classified.iteritems():
|
|
|
|
|
-# if len(chars) == 1:
|
|
|
|
|
-# imsave('%s%s' % (folder, filename), char.image.data, cmap='gray')
|
|
|
|
|
-# else:
|
|
|
|
|
-# for i, char in enumerate(chars):
|
|
|
|
|
-# imsave('%s%s_%d' % (folder, filename, i), char.image.data, cmap='gray')
|
|
|