Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SimpleHTR
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fabian Mersch
SimpleHTR
Commits
50a4c6e7
Commit
50a4c6e7
authored
6 years ago
by
Harald Scheidl
Browse files
Options
Downloads
Patches
Plain Diff
py2 compatibility (print, div) via __future__
parent
a5336fea
No related branches found
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
src/DataLoader.py
+6
-0
6 additions, 0 deletions
src/DataLoader.py
src/Model.py
+3
-0
3 additions, 0 deletions
src/Model.py
src/SamplePreprocessor.py
+5
-2
5 additions, 2 deletions
src/SamplePreprocessor.py
src/main.py
+5
-2
5 additions, 2 deletions
src/main.py
with
20 additions
and
4 deletions
.gitignore
+
1
−
0
View file @
50a4c6e7
...
@@ -4,3 +4,4 @@ src/__pycache__/
...
@@ -4,3 +4,4 @@ src/__pycache__/
model/checkpoint
model/checkpoint
model/snapshot-*
model/snapshot-*
*.so
*.so
*.pyc
This diff is collapsed.
Click to expand it.
src/DataLoader.py
+
6
−
0
View file @
50a4c6e7
from
__future__
import
division
from
__future__
import
print_function
import
os
import
os
import
random
import
random
import
numpy
as
np
import
numpy
as
np
...
@@ -57,8 +60,11 @@ class DataLoader:
...
@@ -57,8 +60,11 @@ class DataLoader:
if
not
os
.
path
.
getsize
(
fileName
):
if
not
os
.
path
.
getsize
(
fileName
):
bad_samples
.
append
(
lineSplit
[
0
]
+
'
.png
'
)
bad_samples
.
append
(
lineSplit
[
0
]
+
'
.png
'
)
continue
continue
# put sample into list
# put sample into list
self
.
samples
.
append
(
Sample
(
gtText
,
fileName
))
self
.
samples
.
append
(
Sample
(
gtText
,
fileName
))
# some images in the IAM dataset are known to be damaged, don't show warning for them
if
set
(
bad_samples
)
!=
set
(
bad_samples_reference
):
if
set
(
bad_samples
)
!=
set
(
bad_samples_reference
):
print
(
"
Warning, damaged images found:
"
,
bad_samples
)
print
(
"
Warning, damaged images found:
"
,
bad_samples
)
print
(
"
Damaged images expected:
"
,
bad_samples_reference
)
print
(
"
Damaged images expected:
"
,
bad_samples_reference
)
...
...
This diff is collapsed.
Click to expand it.
src/Model.py
+
3
−
0
View file @
50a4c6e7
from
__future__
import
division
from
__future__
import
print_function
import
sys
import
sys
import
tensorflow
as
tf
import
tensorflow
as
tf
...
...
This diff is collapsed.
Click to expand it.
src/SamplePreprocessor.py
+
5
−
2
View file @
50a4c6e7
from
__future__
import
division
from
__future__
import
print_function
import
random
import
random
import
numpy
as
np
import
numpy
as
np
import
cv2
import
cv2
...
@@ -19,8 +22,8 @@ def preprocess(img, imgSize, dataAugmentation=False):
...
@@ -19,8 +22,8 @@ def preprocess(img, imgSize, dataAugmentation=False):
# create target image and copy sample image into it
# create target image and copy sample image into it
(
wt
,
ht
)
=
imgSize
(
wt
,
ht
)
=
imgSize
(
h
,
w
)
=
img
.
shape
(
h
,
w
)
=
img
.
shape
fx
=
float
(
w
)
/
wt
fx
=
w
/
wt
fy
=
float
(
h
)
/
ht
fy
=
h
/
ht
f
=
max
(
fx
,
fy
)
f
=
max
(
fx
,
fy
)
newSize
=
(
max
(
min
(
wt
,
int
(
w
/
f
)),
1
),
max
(
min
(
ht
,
int
(
h
/
f
)),
1
))
# scale according to f (result at least 1 and at most wt or ht)
newSize
=
(
max
(
min
(
wt
,
int
(
w
/
f
)),
1
),
max
(
min
(
ht
,
int
(
h
/
f
)),
1
))
# scale according to f (result at least 1 and at most wt or ht)
img
=
cv2
.
resize
(
img
,
newSize
)
img
=
cv2
.
resize
(
img
,
newSize
)
...
...
This diff is collapsed.
Click to expand it.
src/main.py
+
5
−
2
View file @
50a4c6e7
from
__future__
import
division
from
__future__
import
print_function
import
sys
import
sys
import
argparse
import
argparse
import
cv2
import
cv2
...
@@ -79,8 +82,8 @@ def validate(model, loader):
...
@@ -79,8 +82,8 @@ def validate(model, loader):
print
(
'
[OK]
'
if
dist
==
0
else
'
[ERR:%d]
'
%
dist
,
'"'
+
batch
.
gtTexts
[
i
]
+
'"'
,
'
->
'
,
'"'
+
recognized
[
i
]
+
'"'
)
print
(
'
[OK]
'
if
dist
==
0
else
'
[ERR:%d]
'
%
dist
,
'"'
+
batch
.
gtTexts
[
i
]
+
'"'
,
'
->
'
,
'"'
+
recognized
[
i
]
+
'"'
)
# print validation result
# print validation result
charErrorRate
=
float
(
numCharErr
)
/
numCharTotal
charErrorRate
=
numCharErr
/
numCharTotal
wordAccuracy
=
float
(
numWordOK
)
/
numWordTotal
wordAccuracy
=
numWordOK
/
numWordTotal
print
(
'
Character error rate: %f%%. Word accuracy: %f%%.
'
%
(
charErrorRate
*
100.0
,
wordAccuracy
*
100.0
))
print
(
'
Character error rate: %f%%. Word accuracy: %f%%.
'
%
(
charErrorRate
*
100.0
,
wordAccuracy
*
100.0
))
return
charErrorRate
return
charErrorRate
...
...
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