Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
licenseplates
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
licenseplates
Commits
51d98fd3
Commit
51d98fd3
authored
Dec 21, 2011
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Debugged performance test script.
parent
b5f8ca8a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
7 deletions
+20
-7
src/Classifier.py
src/Classifier.py
+9
-3
src/create_classifier.py
src/create_classifier.py
+4
-2
src/test_performance.py
src/test_performance.py
+7
-2
No files found.
src/Classifier.py
View file @
51d98fd3
...
@@ -4,8 +4,14 @@ from svmutil import svm_train, svm_problem, svm_parameter, svm_predict, \
...
@@ -4,8 +4,14 @@ from svmutil import svm_train, svm_problem, svm_parameter, svm_predict, \
class
Classifier
:
class
Classifier
:
def
__init__
(
self
,
c
=
None
,
gamma
=
None
,
filename
=
None
,
neighbours
=
3
,
\
def
__init__
(
self
,
c
=
None
,
gamma
=
None
,
filename
=
None
,
neighbours
=
3
,
\
verbose
=
0
):
verbose
=
0
):
self
.
neighbours
=
neighbours
self
.
verbose
=
verbose
if
filename
:
if
filename
:
# If a filename is given, load a model from the given filename
# If a filename is given, load a model from the given filename
if
verbose
:
print
'Loading classifier from "%s"...'
%
filename
self
.
model
=
svm_load_model
(
filename
)
self
.
model
=
svm_load_model
(
filename
)
elif
c
==
None
or
gamma
==
None
:
elif
c
==
None
or
gamma
==
None
:
raise
Exception
(
'Please specify both C and gamma.'
)
raise
Exception
(
'Please specify both C and gamma.'
)
...
@@ -16,11 +22,11 @@ class Classifier:
...
@@ -16,11 +22,11 @@ class Classifier:
self
.
param
.
gamma
=
gamma
# Parameter for radial kernel
self
.
param
.
gamma
=
gamma
# Parameter for radial kernel
self
.
model
=
None
self
.
model
=
None
self
.
neighbours
=
neighbours
self
.
verbose
=
verbose
def
save
(
self
,
filename
):
def
save
(
self
,
filename
):
"""Save the SVM model in the given filename."""
"""Save the SVM model in the given filename."""
if
self
.
verbose
:
print
'Saving classifier in "%s"...'
%
filename
svm_save_model
(
filename
,
self
.
model
)
svm_save_model
(
filename
,
self
.
model
)
def
train
(
self
,
learning_set
):
def
train
(
self
,
learning_set
):
...
...
src/create_classifier.py
View file @
51d98fd3
...
@@ -5,14 +5,15 @@ from data import exists, DATA_FOLDER
...
@@ -5,14 +5,15 @@ from data import exists, DATA_FOLDER
def
load_classifier
(
neighbours
,
blur_scale
,
c
=
None
,
gamma
=
None
,
verbose
=
0
):
def
load_classifier
(
neighbours
,
blur_scale
,
c
=
None
,
gamma
=
None
,
verbose
=
0
):
classifier_file
=
DATA_FOLDER
+
'classifier_%s_%s.dat'
\
classifier_file
=
'classifier_%s_%s.dat'
\
%
(
blur_scale
,
neighbours
)
%
(
blur_scale
,
neighbours
)
classifier_path
=
DATA_FOLDER
+
classifier_file
if
exists
(
classifier_file
):
if
exists
(
classifier_file
):
if
verbose
:
if
verbose
:
print
'Loading classifier...'
print
'Loading classifier...'
classifier
=
Classifier
(
filename
=
classifier_
file
,
\
classifier
=
Classifier
(
filename
=
classifier_
path
,
\
neighbours
=
neighbours
,
verbose
=
verbose
)
neighbours
=
neighbours
,
verbose
=
verbose
)
elif
c
!=
None
and
gamma
!=
None
:
elif
c
!=
None
and
gamma
!=
None
:
if
verbose
:
if
verbose
:
...
@@ -23,6 +24,7 @@ def load_classifier(neighbours, blur_scale, c=None, gamma=None, verbose=0):
...
@@ -23,6 +24,7 @@ def load_classifier(neighbours, blur_scale, c=None, gamma=None, verbose=0):
learning_set
=
load_learning_set
(
neighbours
,
blur_scale
,
\
learning_set
=
load_learning_set
(
neighbours
,
blur_scale
,
\
verbose
=
verbose
)
verbose
=
verbose
)
classifier
.
train
(
learning_set
)
classifier
.
train
(
learning_set
)
classifier
.
save
(
classifier_path
)
else
:
else
:
raise
Exception
(
'No soft margin and gamma specified.'
)
raise
Exception
(
'No soft margin and gamma specified.'
)
...
...
src/test_performance.py
View file @
51d98fd3
...
@@ -22,7 +22,7 @@ chars = []
...
@@ -22,7 +22,7 @@ chars = []
i
=
0
i
=
0
br
=
False
br
=
False
for
value
in
sorted
(
listdir
()):
for
value
in
sorted
(
listdir
(
IMAGES_FOLDER
)):
for
image
in
sorted
(
listdir
(
IMAGES_FOLDER
+
value
)):
for
image
in
sorted
(
listdir
(
IMAGES_FOLDER
+
value
)):
f
=
IMAGES_FOLDER
+
value
+
'/'
+
image
f
=
IMAGES_FOLDER
+
value
+
'/'
+
image
image
=
GrayscaleImage
(
f
)
image
=
GrayscaleImage
(
f
)
...
@@ -37,15 +37,20 @@ for value in sorted(listdir()):
...
@@ -37,15 +37,20 @@ for value in sorted(listdir()):
if
br
:
if
br
:
break
break
# Load classifier
# Load classifier
(run create_classifier.py first)
classifier
=
load_classifier
(
neighbours
,
blur_scale
,
verbose
=
1
)
classifier
=
load_classifier
(
neighbours
,
blur_scale
,
verbose
=
1
)
# Measure the time it takes to recognize <count> characters
# Measure the time it takes to recognize <count> characters
start
=
time
()
start
=
time
()
for
char
in
chars
:
for
char
in
chars
:
# Normalize the character image
char
.
image
=
NormalizedCharacterImage
(
image
,
blur
=
blur_scale
,
height
=
42
)
char
.
image
=
NormalizedCharacterImage
(
image
,
blur
=
blur_scale
,
height
=
42
)
# Create the image's feature vector
char
.
get_single_cell_feature_vector
(
neighbours
)
char
.
get_single_cell_feature_vector
(
neighbours
)
# Feed the feature vector to the classifier
classifier
.
classify
(
char
)
classifier
.
classify
(
char
)
elapsed
=
time
()
-
start
elapsed
=
time
()
-
start
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment