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
6103bbdd
Commit
6103bbdd
authored
Dec 02, 2011
by
unknown
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/taddeus/licenseplates
parents
c55b28ee
76fe905f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
2 deletions
+56
-2
src/Character.py
src/Character.py
+5
-2
src/Classifier.py
src/Classifier.py
+51
-0
No files found.
src/Character.py
View file @
6103bbdd
...
@@ -11,7 +11,7 @@ class Character:
...
@@ -11,7 +11,7 @@ class Character:
def
set_corners
(
self
):
def
set_corners
(
self
):
corners
=
self
.
get_children
(
"quadrangle"
)
corners
=
self
.
get_children
(
"quadrangle"
)
self
.
corners
=
[]
self
.
corners
=
[]
for
corner
in
corners
:
for
corner
in
corners
:
...
@@ -25,4 +25,7 @@ class Character:
...
@@ -25,4 +25,7 @@ class Character:
return
dom
.
getElementsByTagName
(
node
)[
0
]
return
dom
.
getElementsByTagName
(
node
)[
0
]
def
get_children
(
self
,
node
,
dom
=
None
):
def
get_children
(
self
,
node
,
dom
=
None
):
return
self
.
get_node
(
node
,
dom
).
childNodes
return
self
.
get_node
(
node
,
dom
).
childNodes
\ No newline at end of file
def
get_feature_vector
(
self
):
pass
src/Classifier.py
0 → 100644
View file @
6103bbdd
from
svmutil
import
svm_model
,
svm_problem
,
svm_parameter
,
svm_predict
,
LINEAR
from
cPicle
import
dump
,
load
class
Classifier
:
def
__init__
(
self
,
c
=
None
,
filename
=
None
):
if
filename
:
# If a filename is given, load a modl from the fiven filename
f
=
file
(
filename
,
'r'
)
self
.
model
,
self
.
param
,
self
.
character_map
=
load
(
f
)
f
.
close
()
else
:
self
.
param
=
svm_parameter
()
self
.
param
.
kernel_type
=
LINEAR
self
.
param
.
C
=
c
self
.
character_map
=
{}
self
.
model
=
None
def
save
(
self
,
filename
):
"""Save the SVM model in the given filename."""
f
=
file
(
filename
,
'w+'
)
dump
((
self
.
model
,
self
.
param
,
self
.
character_map
),
f
)
f
.
close
()
def
train
(
self
,
learning_set
):
"""Train the classifier with a list of character objects that have
known values."""
classes
=
[]
features
=
[]
for
char
in
learning_set
:
# Map the character to an integer for use in the SVM model
if
char
.
value
not
in
self
.
character_map
:
self
.
character_map
[
char
.
value
]
=
len
(
self
.
character_map
)
classes
.
append
(
self
.
character_map
[
char
.
value
])
features
.
append
(
char
.
get_feature_vector
())
problem
=
svm_problem
(
self
.
c
,
features
)
self
.
model
=
svm_model
(
problem
,
self
.
param
)
# Add prediction function that returns a numeric class prediction
self
.
model
.
predict
=
lambda
self
,
x
:
svm_predict
([
0
],
[
x
],
self
)[
0
][
0
]
def
classify
(
self
,
character
):
"""Classify a character object and assign its value."""
prediction
=
self
.
model
.
predict
(
character
.
get_feature_vector
())
for
value
,
svm_class
in
self
.
character_map
.
iteritems
():
if
svm_class
==
prediction
:
return
value
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