Commit d98cdc83 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Changed linear to radial blur in SVM.

parent e2507c65
from svmutil import svm_train, svm_problem, svm_parameter, svm_predict, \
LINEAR, svm_save_model, svm_load_model
svm_save_model, svm_load_model
from cPickle import dump, load
......@@ -13,7 +13,7 @@ class Classifier:
f.close()
else:
self.param = svm_parameter()
self.param.kernel_type = LINEAR
self.param.kernel_type = 2
self.param.C = c
self.character_map = {}
self.model = None
......
......@@ -3,63 +3,63 @@ from LicensePlate import LicensePlate
from Classifier import Classifier
from cPickle import dump, load
#chars = []
#
#for i in range(9):
# for j in range(100):
# try:
# filename = '%04d/00991_%04d%02d.info' % (i, i, j)
# print 'loading file "%s"' % filename
# plate = LicensePlate(i, j)
#
# if hasattr(plate, 'characters'):
# chars.extend(plate.characters)
# except:
# print 'epic fail'
#
#print 'loaded %d chars' % len(chars)
#
chars = []
for i in range(9):
for j in range(100):
try:
filename = '%04d/00991_%04d%02d.info' % (i, i, j)
print 'loading file "%s"' % filename
plate = LicensePlate(i, j)
if hasattr(plate, 'characters'):
chars.extend(plate.characters)
except:
print 'epic fail'
print 'loaded %d chars' % len(chars)
#dump(chars, file('chars', 'w+'))
#----------------------------------------------------------------
#chars = load(file('chars', 'r'))
#learned = []
#learning_set = []
#test_set = []
#
#for char in chars:
# if learned.count(char.value) > 80:
# test_set.append(char)
# else:
# learning_set.append(char)
# learned.append(char.value)
#
#dump(learning_set, file('learning_set', 'w+'))
#dump(test_set, file('test_set', 'w+'))
chars = load(file('chars', 'r'))
learned = []
learning_set = []
test_set = []
for char in chars:
if learned.count(char.value) > 80:
test_set.append(char)
else:
learning_set.append(char)
learned.append(char.value)
dump(learning_set, file('learning_set', 'w+'))
dump(test_set, file('test_set', 'w+'))
#----------------------------------------------------------------
learning_set = load(file('learning_set', 'r'))
# Train the classifier with the learning set
classifier = Classifier(c=3)
classifier = Classifier(c=30)
classifier.train(learning_set)
#classifier.save('classifier')
classifier.save('classifier')
#----------------------------------------------------------------
#classifier = Classifier(filename='classifier')
#test_set = load(file('test_set', 'r'))
#l = len(test_set)
#matches = 0
#
#for i, char in enumerate(test_set):
# prediction = classifier.classify(char)
#
# if char.value == prediction:
# print ':) ------> Successfully recognized "%s"' % char.value
# matches += 1
# else:
# print ':( Expected character "%s", got "%s"' \
# % (char.value, prediction),
#
# print ' -- %d of %d (%d%% done)' % (i + 1, l, int(100 * (i + 1) / l))
#
#print '\n%d matches (%d%%), %d fails' % (matches, \
# int(100 * matches / len(test_set)), \
# len(test_set) - matches)
classifier = Classifier(filename='classifier')
test_set = load(file('test_set', 'r'))
l = len(test_set)
matches = 0
for i, char in enumerate(test_set):
prediction = classifier.classify(char)
if char.value == prediction:
print ':) ------> Successfully recognized "%s"' % char.value,
matches += 1
else:
print ':( Expected character "%s", got "%s"' \
% (char.value, prediction),
print ' -- %d of %d (%d%% done)' % (i + 1, l, int(100 * (i + 1) / l))
print '\n%d matches (%d%%), %d fails' % (matches, \
int(100 * matches / len(test_set)), \
len(test_set) - matches)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment