Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
licenseplates
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Taddeüs Kroes
licenseplates
Commits
51d98fd3
Commit
51d98fd3
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Debugged performance test script.
parent
b5f8ca8a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Classifier.py
+9
-3
9 additions, 3 deletions
src/Classifier.py
src/create_classifier.py
+4
-2
4 additions, 2 deletions
src/create_classifier.py
src/test_performance.py
+7
-2
7 additions, 2 deletions
src/test_performance.py
with
20 additions
and
7 deletions
src/Classifier.py
+
9
−
3
View file @
51d98fd3
...
...
@@ -4,8 +4,14 @@ from svmutil import svm_train, svm_problem, svm_parameter, svm_predict, \
class
Classifier
:
def
__init__
(
self
,
c
=
None
,
gamma
=
None
,
filename
=
None
,
neighbours
=
3
,
\
verbose
=
0
):
self
.
neighbours
=
neighbours
self
.
verbose
=
verbose
if
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
)
elif
c
==
None
or
gamma
==
None
:
raise
Exception
(
'
Please specify both C and gamma.
'
)
...
...
@@ -16,11 +22,11 @@ class Classifier:
self
.
param
.
gamma
=
gamma
# Parameter for radial kernel
self
.
model
=
None
self
.
neighbours
=
neighbours
self
.
verbose
=
verbose
def
save
(
self
,
filename
):
"""
Save the SVM model in the given filename.
"""
if
self
.
verbose
:
print
'
Saving classifier in
"
%s
"
...
'
%
filename
svm_save_model
(
filename
,
self
.
model
)
def
train
(
self
,
learning_set
):
...
...
This diff is collapsed.
Click to expand it.
src/create_classifier.py
+
4
−
2
View file @
51d98fd3
...
...
@@ -5,14 +5,15 @@ from data import exists, DATA_FOLDER
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
)
classifier_path
=
DATA_FOLDER
+
classifier_file
if
exists
(
classifier_file
):
if
verbose
:
print
'
Loading classifier...
'
classifier
=
Classifier
(
filename
=
classifier_
file
,
\
classifier
=
Classifier
(
filename
=
classifier_
path
,
\
neighbours
=
neighbours
,
verbose
=
verbose
)
elif
c
!=
None
and
gamma
!=
None
:
if
verbose
:
...
...
@@ -23,6 +24,7 @@ def load_classifier(neighbours, blur_scale, c=None, gamma=None, verbose=0):
learning_set
=
load_learning_set
(
neighbours
,
blur_scale
,
\
verbose
=
verbose
)
classifier
.
train
(
learning_set
)
classifier
.
save
(
classifier_path
)
else
:
raise
Exception
(
'
No soft margin and gamma specified.
'
)
...
...
This diff is collapsed.
Click to expand it.
src/test_performance.py
+
7
−
2
View file @
51d98fd3
...
...
@@ -22,7 +22,7 @@ chars = []
i
=
0
br
=
False
for
value
in
sorted
(
listdir
()):
for
value
in
sorted
(
listdir
(
IMAGES_FOLDER
)):
for
image
in
sorted
(
listdir
(
IMAGES_FOLDER
+
value
)):
f
=
IMAGES_FOLDER
+
value
+
'
/
'
+
image
image
=
GrayscaleImage
(
f
)
...
...
@@ -37,15 +37,20 @@ for value in sorted(listdir()):
if
br
:
break
# Load classifier
# Load classifier
(run create_classifier.py first)
classifier
=
load_classifier
(
neighbours
,
blur_scale
,
verbose
=
1
)
# Measure the time it takes to recognize <count> characters
start
=
time
()
for
char
in
chars
:
# Normalize the character image
char
.
image
=
NormalizedCharacterImage
(
image
,
blur
=
blur_scale
,
height
=
42
)
# Create the image's feature vector
char
.
get_single_cell_feature_vector
(
neighbours
)
# Feed the feature vector to the classifier
classifier
.
classify
(
char
)
elapsed
=
time
()
-
start
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment