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
1c614c73
Commit
1c614c73
authored
1 year ago
by
merschie
Browse files
Options
Downloads
Patches
Plain Diff
add webserver
parent
87fe2ec0
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main.py
+2
-0
2 additions, 0 deletions
src/main.py
src/webserver.py
+40
-0
40 additions, 0 deletions
src/webserver.py
with
42 additions
and
0 deletions
src/main.py
+
2
−
0
View file @
1c614c73
...
@@ -10,6 +10,8 @@ from dataloader_iam import DataLoaderIAM, Batch
...
@@ -10,6 +10,8 @@ from dataloader_iam import DataLoaderIAM, Batch
from
model
import
Model
,
DecoderType
from
model
import
Model
,
DecoderType
from
preprocessor
import
Preprocessor
from
preprocessor
import
Preprocessor
import
os
os
.
environ
[
'
CUDA_VISIBLE_DEVICES
'
]
=
'
-1
'
class
FilePaths
:
class
FilePaths
:
"""
Filenames and paths to data.
"""
"""
Filenames and paths to data.
"""
...
...
This diff is collapsed.
Click to expand it.
src/webserver.py
0 → 100644
+
40
−
0
View file @
1c614c73
from
flask
import
Flask
,
request
,
jsonify
import
main
as
htr
import
model
as
htr_model
import
dataloader_iam
as
htr_data_loader
import
preprocessor
as
htr_preprocessor
import
numpy
as
np
app
=
Flask
(
__name__
)
image_size
=
32
model_name
=
htr_model
.
Model
(
htr
.
char_list_from_file
(),
htr_model
.
DecoderType
.
WordBeamSearch
,
must_restore
=
True
)
@app.route
(
'
/predict
'
,
methods
=
[
'
POST
'
])
def
predict
():
image_array
=
np
.
frombuffer
(
request
.
data
,
dtype
=
np
.
uint64
)
h
=
image_array
[
-
2
]
w
=
image_array
[
-
1
]
image_array
=
image_array
[:
-
2
]
image_array
=
image_array
.
reshape
((
h
,
w
))
print
(
image_array
)
preprocessor
=
htr_preprocessor
.
Preprocessor
(
htr
.
get_img_size
(),
dynamic_width
=
True
,
padding
=
16
)
processed_image
=
preprocessor
.
process_img
(
image_array
)
batch
=
htr_data_loader
.
Batch
([
processed_image
],
None
,
1
)
recognized
,
probability
=
htr_model
.
Model
.
infer_batch
(
model_name
,
batch
)
result
=
{
'
recognized
'
:
recognized
[
0
],
}
return
jsonify
(
result
)
if
__name__
==
'
__main__
'
:
app
.
run
(
debug
=
True
,
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