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
dd279dab
Commit
dd279dab
authored
1 year ago
by
Solene Tarride
Browse files
Options
Downloads
Patches
Plain Diff
Use CTCHypothesis.tokens instead og CTCHypothesis.words
parent
bf71ddcb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dan/ocr/decoder.py
+5
-5
5 additions, 5 deletions
dan/ocr/decoder.py
with
5 additions
and
5 deletions
dan/ocr/decoder.py
+
5
−
5
View file @
dd279dab
...
...
@@ -495,6 +495,7 @@ class CTCLanguageDecoder:
self
.
tokens_to_index
=
{
token
:
i
for
i
,
token
in
enumerate
(
read_txt
(
tokens_path
).
split
(
"
\n
"
))
}
self
.
index_to_token
=
{
i
:
token
for
token
,
i
in
self
.
tokens_to_index
.
items
()}
self
.
blank_token_id
=
self
.
tokens_to_index
[
self
.
mapping
.
ctc
.
encoded
]
self
.
decoder
=
ctc_decoder
(
lm
=
language_model_path
,
...
...
@@ -516,7 +517,6 @@ class CTCLanguageDecoder:
high_prob
=
batch_features
.
max
()
low_prob
=
batch_features
.
min
()
batch_size
,
n_frames
,
n_tokens
=
batch_features
.
shape
# Reset probabilities for the CTC token
batch_features
[:,
:,
-
1
]
=
(
torch
.
ones
((
batch_size
,
n_frames
),
dtype
=
torch
.
float32
)
*
low_prob
...
...
@@ -553,10 +553,10 @@ class CTCLanguageDecoder:
out
[
"
text
"
]
=
[
""
.
join
(
[
self
.
mapping
.
display
[
token
]
if
token
in
self
.
mapping
.
display
else
token
for
token
in
hypothesis
[
0
].
words
self
.
mapping
.
display
[
self
.
index_to_token
[
token
]
]
if
self
.
index_to_token
[
token
]
in
self
.
mapping
.
display
else
self
.
index_to_token
[
token
]
for
token
in
hypothesis
[
0
].
tokens
.
tolist
()
]
)
for
hypothesis
in
hypotheses
...
...
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