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
8ced0010
Commit
8ced0010
authored
2 years ago
by
Solene Tarride
Browse files
Options
Downloads
Patches
Plain Diff
fix lint
parent
828a5db1
No related branches found
No related tags found
1 merge request
!66
Compute confidence scores by char, word or line
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dan/predict/prediction.py
+19
-6
19 additions, 6 deletions
dan/predict/prediction.py
with
19 additions
and
6 deletions
dan/predict/prediction.py
+
19
−
6
View file @
8ced0010
...
...
@@ -109,7 +109,14 @@ class DAN:
input_image
=
(
input_image
-
self
.
mean
)
/
self
.
std
return
input_image
def
predict
(
self
,
input_tensor
,
input_sizes
,
confidences
=
False
,
attentions
=
False
,
confidences_sep
=
None
):
def
predict
(
self
,
input_tensor
,
input_sizes
,
confidences
=
False
,
attentions
=
False
,
confidences_sep
=
None
,
):
"""
Run prediction on an input image.
:param input_tensor: A batch of images to predict.
...
...
@@ -188,7 +195,7 @@ class DAN:
if
torch
.
all
(
reached_end
):
break
# Concatenate tensors for each token
confidence_scores
=
(
torch
.
cat
(
confidence_scores
,
dim
=
1
).
cpu
().
detach
().
numpy
()
...
...
@@ -270,13 +277,19 @@ def run(
if
"
word
"
in
confidence_score_levels
:
word_probs
=
compute_prob_by_separator
(
text
,
char_confidences
,
[
"
\n
"
,
"
"
])
result
[
"
confidences
"
].
update
({
"
word
"
:
[
np
.
around
(
c
,
2
)
for
c
in
word_probs
]})
result
[
"
confidences
"
].
update
(
{
"
word
"
:
[
np
.
around
(
c
,
2
)
for
c
in
word_probs
]}
)
if
"
line
"
in
confidence_score_levels
:
line_probs
=
compute_prob_by_separator
(
text
,
char_confidences
,
[
"
\n
"
])
result
[
"
confidences
"
].
update
({
"
line
"
:
[
np
.
around
(
c
,
2
)
for
c
in
line_probs
]})
result
[
"
confidences
"
].
update
(
{
"
line
"
:
[
np
.
around
(
c
,
2
)
for
c
in
line_probs
]}
)
if
"
char
"
in
confidence_score_levels
:
result
[
"
confidences
"
].
update
({
"
char
"
:
[
np
.
around
(
c
,
2
)
for
c
in
char_confidences
]})
result
[
"
confidences
"
].
update
(
{
"
char
"
:
[
np
.
around
(
c
,
2
)
for
c
in
char_confidences
]}
)
# Save gif with attention map
if
attention_map
:
gif_filename
=
f
"
{
output
}
/
{
image
.
stem
}
_
{
attention_map_level
}
.gif
"
...
...
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