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, \ 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 from cPickle import dump, load
...@@ -13,7 +13,7 @@ class Classifier: ...@@ -13,7 +13,7 @@ class Classifier:
f.close() f.close()
else: else:
self.param = svm_parameter() self.param = svm_parameter()
self.param.kernel_type = LINEAR self.param.kernel_type = 2
self.param.C = c self.param.C = c
self.character_map = {} self.character_map = {}
self.model = None self.model = None
......
...@@ -3,63 +3,63 @@ from LicensePlate import LicensePlate ...@@ -3,63 +3,63 @@ from LicensePlate import LicensePlate
from Classifier import Classifier from Classifier import Classifier
from cPickle import dump, load from cPickle import dump, load
#chars = [] chars = []
#
#for i in range(9): for i in range(9):
# for j in range(100): for j in range(100):
# try: try:
# filename = '%04d/00991_%04d%02d.info' % (i, i, j) filename = '%04d/00991_%04d%02d.info' % (i, i, j)
# print 'loading file "%s"' % filename print 'loading file "%s"' % filename
# plate = LicensePlate(i, j) plate = LicensePlate(i, j)
#
# if hasattr(plate, 'characters'): if hasattr(plate, 'characters'):
# chars.extend(plate.characters) chars.extend(plate.characters)
# except: except:
# print 'epic fail' print 'epic fail'
#
#print 'loaded %d chars' % len(chars) print 'loaded %d chars' % len(chars)
#
#dump(chars, file('chars', 'w+')) #dump(chars, file('chars', 'w+'))
#---------------------------------------------------------------- #----------------------------------------------------------------
#chars = load(file('chars', 'r')) chars = load(file('chars', 'r'))
#learned = [] learned = []
#learning_set = [] learning_set = []
#test_set = [] test_set = []
#
#for char in chars: for char in chars:
# if learned.count(char.value) > 80: if learned.count(char.value) > 80:
# test_set.append(char) test_set.append(char)
# else: else:
# learning_set.append(char) learning_set.append(char)
# learned.append(char.value) learned.append(char.value)
#
#dump(learning_set, file('learning_set', 'w+')) dump(learning_set, file('learning_set', 'w+'))
#dump(test_set, file('test_set', 'w+')) dump(test_set, file('test_set', 'w+'))
#---------------------------------------------------------------- #----------------------------------------------------------------
learning_set = load(file('learning_set', 'r')) learning_set = load(file('learning_set', 'r'))
# Train the classifier with the learning set # Train the classifier with the learning set
classifier = Classifier(c=3) classifier = Classifier(c=30)
classifier.train(learning_set) classifier.train(learning_set)
#classifier.save('classifier') classifier.save('classifier')
#---------------------------------------------------------------- #----------------------------------------------------------------
#classifier = Classifier(filename='classifier') classifier = Classifier(filename='classifier')
#test_set = load(file('test_set', 'r')) test_set = load(file('test_set', 'r'))
#l = len(test_set) l = len(test_set)
#matches = 0 matches = 0
#
#for i, char in enumerate(test_set): for i, char in enumerate(test_set):
# prediction = classifier.classify(char) prediction = classifier.classify(char)
#
# if char.value == prediction: if char.value == prediction:
# print ':) ------> Successfully recognized "%s"' % char.value print ':) ------> Successfully recognized "%s"' % char.value,
# matches += 1 matches += 1
# else: else:
# print ':( Expected character "%s", got "%s"' \ print ':( Expected character "%s", got "%s"' \
# % (char.value, prediction), % (char.value, prediction),
#
# print ' -- %d of %d (%d%% done)' % (i + 1, l, int(100 * (i + 1) / l)) print ' -- %d of %d (%d%% done)' % (i + 1, l, int(100 * (i + 1) / l))
#
#print '\n%d matches (%d%%), %d fails' % (matches, \ print '\n%d matches (%d%%), %d fails' % (matches, \
# int(100 * matches / len(test_set)), \ int(100 * matches / len(test_set)), \
# len(test_set) - matches) 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