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
1a203e67
Commit
1a203e67
authored
Dec 20, 2011
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merged test scripts into a single test file: find_svm_parameter.py.
parent
7a67ea01
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
46 deletions
+61
-46
src/load_characters.py
src/load_characters.py
+11
-6
src/load_learning_set.py
src/load_learning_set.py
+40
-0
src/test_classifier.py
src/test_classifier.py
+10
-40
No files found.
src/load_characters.py
View file @
1a203e67
#!/usr/bin/python
#!/usr/bin/python
from
os
import
listdir
from
os
import
listdir
from
cPickle
import
dump
from
cPickle
import
dump
from
pylab
import
imshow
,
show
from
sys
import
argv
,
exit
from
GrayscaleImage
import
GrayscaleImage
from
GrayscaleImage
import
GrayscaleImage
from
NormalizedCharacterImage
import
NormalizedCharacterImage
from
NormalizedCharacterImage
import
NormalizedCharacterImage
from
Character
import
Character
from
Character
import
Character
if
len
(
argv
)
<
4
:
print
'Usage: python %s FILE_SUFFIX BLUR_SCALE NEIGHBOURS'
%
argv
[
0
]
exit
(
1
)
c
=
[]
c
=
[]
for
char
in
sorted
(
listdir
(
'../images/LearningSet'
)):
for
char
in
sorted
(
listdir
(
'../images/LearningSet'
)):
for
image
in
sorted
(
listdir
(
'../images/LearningSet/'
+
char
)):
for
image
in
sorted
(
listdir
(
'../images/LearningSet/'
+
char
)):
f
=
'../images/LearningSet/'
+
char
+
'/'
+
image
f
=
'../images/LearningSet/'
+
char
+
'/'
+
image
image
=
GrayscaleImage
(
f
)
image
=
GrayscaleImage
(
f
)
norm
=
NormalizedCharacterImage
(
image
,
blur
=
1
,
size
=
(
48
,
36
)
)
norm
=
NormalizedCharacterImage
(
image
,
blur
=
float
(
argv
[
2
]),
height
=
42
)
#
imshow(norm.data, cmap='gray')
#
from pylab import imshow, show
#show()
#
imshow(norm.data, cmap='gray');
show()
character
=
Character
(
char
,
[],
norm
)
character
=
Character
(
char
,
[],
norm
)
character
.
get_single_cell_feature_vector
()
character
.
get_single_cell_feature_vector
(
int
(
argv
[
3
])
)
c
.
append
(
character
)
c
.
append
(
character
)
print
char
print
char
dump
(
c
,
open
(
'characters.dat'
,
'w+'
))
print
'Saving characters...'
dump
(
c
,
open
(
'characters%s.dat'
%
argv
[
1
],
'w+'
))
src/load_learning_set.py
0 → 100755
View file @
1a203e67
#!/usr/bin/python
from
cPickle
import
dump
,
load
from
sys
import
argv
,
exit
if
len
(
argv
)
<
2
:
print
'Usage: python %s FILE_SUFFIX'
%
argv
[
0
]
exit
(
1
)
print
'Loading characters...'
chars
=
load
(
file
(
'characters%s.dat'
%
argv
[
1
],
'r'
))
learning_set
=
[]
test_set
=
[]
#s = {}
#
#for char in chars:
# if char.value not in s:
# s[char.value] = [char]
# else:
# s[char.value].append(char)
#
#for value, chars in s.iteritems():
# learning_set += chars[::2]
# test_set += chars[1::2]
learned
=
[]
for
char
in
chars
:
if
learned
.
count
(
char
.
value
)
==
70
:
test_set
.
append
(
char
)
else
:
learning_set
.
append
(
char
)
learned
.
append
(
char
.
value
)
print
'Learning set:'
,
[
c
.
value
for
c
in
learning_set
]
print
'
\
n
Test set:'
,
[
c
.
value
for
c
in
test_set
]
print
'
\
n
Saving learning set...'
dump
(
learning_set
,
file
(
'learning_set%s.dat'
%
argv
[
1
],
'w+'
))
print
'Saving test set...'
dump
(
test_set
,
file
(
'test_set%s.dat'
%
argv
[
1
],
'w+'
))
src/test_classifier.py
View file @
1a203e67
#!/usr/bin/python
#!/usr/bin/python
from
xml_helper_functions
import
xml_to_LicensePlate
from
Classifier
import
Classifier
from
cPickle
import
dump
,
load
from
cPickle
import
dump
,
load
chars
=
load
(
file
(
'characters.dat'
,
'r'
))
from
Classifier
import
Classifier
learning_set
=
[]
test_set
=
[]
#s = {}
#
#for char in chars:
# if char.value not in s:
# s[char.value] = [char]
# else:
# s[char.value].append(char)
#
#for value, chars in s.iteritems():
# learning_set += chars[::2]
# test_set += chars[1::2]
learned
=
[]
for
char
in
chars
:
if
len
(
argv
)
<
5
:
if
learned
.
count
(
char
.
value
)
==
70
:
print
'Usage: python %s FILE_SUFFIX C GAMMA NEIGHBOURS'
%
argv
[
0
]
test_set
.
append
(
char
)
exit
(
1
)
else
:
learning_set
.
append
(
char
)
learned
.
append
(
char
.
value
)
print
'Learning set:'
,
[
c
.
value
for
c
in
learning_set
]
print
'Test set:'
,
[
c
.
value
for
c
in
test_set
]
print
'Saving learning set...'
dump
(
learning_set
,
file
(
'learning_set.dat'
,
'w+'
))
print
'Saving test set...'
dump
(
test_set
,
file
(
'test_set.dat'
,
'w+'
))
#----------------------------------------------------------------
print
'Loading learning set'
print
'Loading learning set'
learning_set
=
load
(
file
(
'learning_set
.dat'
,
'r'
))
learning_set
=
load
(
file
(
'learning_set
%s.dat'
%
argv
[
1
]
,
'r'
))
# Train the classifier with the learning set
# Train the classifier with the learning set
classifier
=
Classifier
(
c
=
512
,
gamma
=
.
125
,
cell_size
=
12
)
classifier
=
Classifier
(
c
=
float
(
argv
[
1
]),
\
gamma
=
float
(
argv
[
2
]),
\
neighbours
=
int
(
argv
[
3
]))
classifier
.
train
(
learning_set
)
classifier
.
train
(
learning_set
)
classifier
.
save
(
'classifier.dat'
)
print
'Saved classifier'
#----------------------------------------------------------------
print
'Loading classifier'
classifier
=
Classifier
(
filename
=
'classifier.dat'
)
print
'Loading test set'
print
'Loading test set'
test_set
=
load
(
file
(
'test_set
.dat'
,
'r'
))
test_set
=
load
(
file
(
'test_set
%s.dat'
%
argv
[
1
]
,
'r'
))
l
=
len
(
test_set
)
l
=
len
(
test_set
)
matches
=
0
matches
=
0
...
...
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