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
6e78a28d
Commit
6e78a28d
authored
1 year ago
by
Solene Tarride
Committed by
Solene Tarride
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Improve documentation
parent
ee9c8ad8
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
+9
-7
9 additions, 7 deletions
dan/ocr/decoder.py
with
9 additions
and
7 deletions
dan/ocr/decoder.py
+
9
−
7
View file @
6e78a28d
...
...
@@ -503,10 +503,9 @@ class CTCLanguageDecoder:
nbest
=
1
,
)
self
.
temperature
=
temperature
self
.
tokens_to_idx
=
read_txt
(
tokens_path
).
split
(
"
\n
"
)
self
.
ctc_id
=
self
.
tokens_to_idx
.
index
(
blank_token
)
self
.
space_token
=
sil_token
self
.
tokens_to_idx
=
read_txt
(
tokens_path
).
split
(
"
\n
"
)
self
.
blank_id
=
self
.
tokens_to_idx
.
index
(
blank_token
)
def
add_ctc_frames
(
self
,
batch_features
):
"""
...
...
@@ -514,16 +513,19 @@ class CTCLanguageDecoder:
"""
batch_size
,
n_frames
,
n_tokens
=
batch_features
.
shape
# column with 1 probability on CTC token
# Create tensor with high probability CTC token
high_prob
=
0.99
low_prob
=
0.01
ctc_probs
=
(
torch
.
ones
((
batch_size
,
1
,
n_tokens
),
dtype
=
torch
.
float32
)
*
0.01
*
low_prob
/
(
n_tokens
-
1
)
)
ctc_probs
[:,
:,
self
.
ctc
_id
]
=
0.99
ctc_probs
[:,
:,
self
.
blank
_id
]
=
high_prob
ctc_probs
=
ctc_probs
.
log
()
for
i
in
range
(
n_frames
-
1
):
# Insert CTC tensor between frames
for
i
in
range
(
n_frames
):
batch_features
=
torch
.
cat
(
[
batch_features
[:,
:
2
*
i
+
1
,
:],
...
...
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