Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
DAN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Automatic Text Recognition
DAN
Commits
bac1de3c
Verified
Commit
bac1de3c
authored
1 year ago
by
Mélodie Boillet
Browse files
Options
Downloads
Patches
Plain Diff
Apply
1956acc9
parent
ee994ff3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dan/predict/prediction.py
+10
-7
10 additions, 7 deletions
dan/predict/prediction.py
tests/test_prediction.py
+1
-1
1 addition, 1 deletion
tests/test_prediction.py
with
11 additions
and
8 deletions
dan/predict/prediction.py
+
10
−
7
View file @
bac1de3c
...
@@ -90,11 +90,12 @@ class DAN:
...
@@ -90,11 +90,12 @@ class DAN:
"""
"""
image
=
read_image
(
path
)
image
=
read_image
(
path
)
preprocessed_image
=
self
.
preprocessing_transforms
(
image
)
preprocessed_image
=
self
.
preprocessing_transforms
(
image
)
normalized_image
=
torch
.
zeros
(
preprocessed_image
.
shape
)
for
ch
in
range
(
preprocessed_image
.
shape
[
0
]):
for
ch
in
range
(
preprocessed_image
.
shape
[
0
]):
preprocess
ed_image
[
ch
,
:,
:]
=
(
normaliz
ed_image
[
ch
,
:,
:]
=
(
preprocessed_image
[
ch
,
:,
:]
-
self
.
mean
[
ch
]
preprocessed_image
[
ch
,
:,
:]
-
self
.
mean
[
ch
]
)
/
self
.
std
[
ch
]
)
/
self
.
std
[
ch
]
return
preprocessed_image
return
preprocessed_image
,
normalized_image
def
predict
(
def
predict
(
self
,
self
,
...
@@ -271,16 +272,18 @@ def process_batch(
...
@@ -271,16 +272,18 @@ def process_batch(
threshold_method
,
threshold_method
,
threshold_value
,
threshold_value
,
):
):
input_images
,
input_sizes
=
[],
[]
input_images
,
visu_images
,
input_sizes
=
[],
[]
,
[]
logger
.
info
(
"
Loading images...
"
)
logger
.
info
(
"
Loading images...
"
)
for
image_path
in
image_batch
:
for
image_path
in
image_batch
:
# Load image and pre-process it
# Load image and pre-process it
image
=
dan_model
.
preprocess
(
str
(
image_path
))
visu_image
,
input_image
=
dan_model
.
preprocess
(
str
(
image_path
))
input_images
.
append
(
image
)
input_images
.
append
(
input_image
)
input_sizes
.
append
(
image
.
shape
[
1
:])
visu_images
.
append
(
visu_image
)
input_sizes
.
append
(
input_image
.
shape
[
1
:])
# Convert to tensor of size (batch_size, channel, height, width) with batch_size=1
# Convert to tensor of size (batch_size, channel, height, width) with batch_size=1
input_tensor
=
pad_images
(
input_images
).
to
(
device
)
input_tensor
=
pad_images
(
input_images
).
to
(
device
)
visu_tensor
=
pad_images
(
visu_images
).
to
(
device
)
logger
.
info
(
"
Images preprocessed!
"
)
logger
.
info
(
"
Images preprocessed!
"
)
# Parse delimiters to regex
# Parse delimiters to regex
...
@@ -355,7 +358,7 @@ def process_batch(
...
@@ -355,7 +358,7 @@ def process_batch(
logger
.
info
(
f
"
Creating attention GIF in
{
gif_filename
}
"
)
logger
.
info
(
f
"
Creating attention GIF in
{
gif_filename
}
"
)
# this returns polygons but unused for now.
# this returns polygons but unused for now.
plot_attention
(
plot_attention
(
image
=
input
_tensor
[
idx
],
image
=
visu
_tensor
[
idx
],
text
=
predicted_text
,
text
=
predicted_text
,
weights
=
attentions
,
weights
=
attentions
,
level
=
attention_map_level
,
level
=
attention_map_level
,
...
...
This diff is collapsed.
Click to expand it.
tests/test_prediction.py
+
1
−
1
View file @
bac1de3c
...
@@ -46,7 +46,7 @@ def test_predict(
...
@@ -46,7 +46,7 @@ def test_predict(
)
)
image_path
=
prediction_data_path
/
"
images
"
/
image_name
image_path
=
prediction_data_path
/
"
images
"
/
image_name
image
=
dan_model
.
preprocess
(
str
(
image_path
))
_
,
image
=
dan_model
.
preprocess
(
str
(
image_path
))
input_tensor
=
image
.
unsqueeze
(
0
)
input_tensor
=
image
.
unsqueeze
(
0
)
input_tensor
=
input_tensor
.
to
(
device
)
input_tensor
=
input_tensor
.
to
(
device
)
...
...
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