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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fabian Mersch
SimpleHTR
Commits
8eeba10a
Commit
8eeba10a
authored
1 year ago
by
fabian
Browse files
Options
Downloads
Patches
Plain Diff
Umlaute beachten
parent
2e6282f0
No related branches found
No related tags found
Loading
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/webserver.py
+35
-46
35 additions, 46 deletions
src/webserver.py
with
35 additions
and
46 deletions
src/webserver.py
+
35
−
46
View file @
8eeba10a
...
...
@@ -5,9 +5,8 @@ import model as htr_model
import
dataloader_iam
as
htr_data_loader
import
preprocessor
as
htr_preprocessor
import
numpy
as
np
from
word_beam_search
import
WordBeamSearch
import
base64
import
t
ensorflow
as
tf
import
t
ime
app
=
Flask
(
__name__
)
...
...
@@ -41,26 +40,13 @@ def predictNach():
batch
=
htr_data_loader
.
Batch
([
processed_image
],
None
,
1
)
#change corpus for name
model_name
.
corpus
=
open
(
'
../data/Nachname.txt
'
).
read
().
split
()
#model_name.decoder = WordBeamSearch(50, 'Words', 0.0, corpus.encode('utf8'), chars.encode('utf8'),word_chars.encode('utf8'))
recognized
,
probability
=
htr_model
.
Model
.
infer_batch
(
model_name
,
batch
)
"""
#convert corpus to list, split at space
corpus = model_name.corpus
result_list=[]
print(recognized)
for name in recognized:
indecies = []
for i in range(len(corpus)):
if name == corpus[i]:
indecies.append(i)
if len(indecies) == 0:
indecies.append(-1)
else:
result_list.append((name, indecies))
if len(result_list) == 0:
result_list.append((-1, -1))
"""
model_name
.
corpus
=
open
(
'
../data/Nachname.txt
'
).
read
().
split
()[:
200
]
#check time of infer_batch
start
=
time
.
time
()
recognized
,
probability
=
htr_model
.
Model
.
infer_batch
(
model_name
,
batch
)
end
=
time
.
time
()
print
(
"
infer_batch time:
"
,
end
-
start
)
processed_image
=
processed_image
+
0.5
...
...
@@ -101,31 +87,10 @@ def predictVor():
#change corpus for name
model_name
.
corpus
=
open
(
'
../data/Vorname.txt
'
).
read
().
split
()
#model_name.decoder = WordBeamSearch(50, 'Words', 0.0, corpus.encode('utf8'), chars.encode('utf8'),word_chars.encode('utf8'))
model_name
.
corpus
=
open
(
'
../data/Vorname.txt
'
).
read
().
split
()[:
200
]
recognized
,
probability
=
htr_model
.
Model
.
infer_batch
(
model_name
,
batch
)
"""
corpus = model_name.corpus
result_list=[]
for name in recognized:
indecies = []
for i in range(len(corpus)):
if name == corpus[i]:
indecies.append(i)
if len(indecies) == 0:
indecies.append(-1)
else:
result_list.append((name, indecies))
if len(result_list) == 0:
result_list.append((
'
KeinName
'
, -1))
"""
processed_image
=
processed_image
+
0.5
processed_image
=
processed_image
*
255
...
...
@@ -142,14 +107,36 @@ def predictVor():
image_base64
=
base64
.
b64encode
(
array_bytes
).
decode
(
'
utf-8
'
)
result
=
{
'
recognized
'
:
recognized
,
'
image
'
:
image_base64
}
return
jsonify
(
result
)
def
replace_umlauts
(
text
):
text
=
text
.
replace
(
'
ä
'
,
'
a
'
)
text
=
text
.
replace
(
'
ö
'
,
'
o
'
)
text
=
text
.
replace
(
'
ü
'
,
'
u
'
)
text
=
text
.
replace
(
'
Ä
'
,
'
A
'
)
text
=
text
.
replace
(
'
Ö
'
,
'
O
'
)
text
=
text
.
replace
(
'
Ü
'
,
'
U
'
)
text
=
text
.
replace
(
'
ß
'
,
'
s
'
)
text
=
text
.
replace
(
'
é
'
,
'
e
'
)
text
=
text
.
replace
(
'
è
'
,
'
e
'
)
text
=
text
.
replace
(
'
ê
'
,
'
e
'
)
text
=
text
.
replace
(
'
à
'
,
'
a
'
)
text
=
text
.
replace
(
'
â
'
,
'
a
'
)
text
=
text
.
replace
(
'
á
'
,
'
a
'
)
text
=
text
.
replace
(
'
ô
'
,
'
o
'
)
text
=
text
.
replace
(
'
û
'
,
'
u
'
)
text
=
text
.
replace
(
'
ç
'
,
'
c
'
)
text
=
text
.
replace
(
'
î
'
,
'
i
'
)
text
=
text
.
replace
(
'
ï
'
,
'
i
'
)
text
=
text
.
replace
(
'
ë
'
,
'
e
'
)
text
=
text
.
replace
(
'
ù
'
,
'
u
'
)
text
=
text
.
replace
(
'
'
,
'
-
'
)
return
text
def
split_Student_Names
():
#csv looks like: Vorname;Nachname;Matrikelnummer
...
...
@@ -165,7 +152,9 @@ def split_Student_Names():
for
line
in
lines
[
1
:]:
line
=
line
.
split
(
'
,
'
)
vorname
=
line
[
2
][:
-
1
]
vorname
=
replace_umlauts
(
vorname
)
nachname
=
line
[
1
]
nachname
=
replace_umlauts
(
nachname
)
matrikelnummer
=
line
[
0
]
print
(
vorname
,
nachname
,
matrikelnummer
)
vorname_file
.
write
(
vorname
+
"
"
)
...
...
@@ -180,4 +169,4 @@ if __name__ == '__main__':
#split csv file into Vorname, Nachname and Matrikelnummer
matrikel_numbers
=
split_Student_Names
()
app
.
run
(
debug
=
Tru
e
,
port
=
8000
)
app
.
run
(
debug
=
Fals
e
,
port
=
8000
)
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