Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
Data Generator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
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
Data Generator
Commits
d6cf517d
Commit
d6cf517d
authored
3 years ago
by
Martin Maarand
Browse files
Options
Downloads
Patches
Plain Diff
Raise an exception if multiple transcriptions from the same text_line
parent
9ab6085f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!20
Raise an exception if multiple transcriptions from the same text_line
Pipeline
#74320
passed
3 years ago
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
kaldi_data_generator/image_utils.py
+1
-3
1 addition, 3 deletions
kaldi_data_generator/image_utils.py
kaldi_data_generator/main.py
+26
-0
26 additions, 0 deletions
kaldi_data_generator/main.py
kaldi_data_generator/utils.py
+25
-1
25 additions, 1 deletion
kaldi_data_generator/utils.py
with
52 additions
and
4 deletions
kaldi_data_generator/image_utils.py
+
1
−
3
View file @
d6cf517d
...
...
@@ -169,6 +169,4 @@ def resize_transcription_data(
orig_polygon
,
max_width
,
max_height
,
scale_x
,
scale_y_top
,
scale_y_bottom
)
return
TranscriptionData
(
trans
.
element_id
,
resized_polygon
,
trans
.
text
,
trans
.
rotation_class
)
return
TranscriptionData
.
copy_replace_polygon
(
trans
,
resized_polygon
)
This diff is collapsed.
Click to expand it.
kaldi_data_generator/main.py
+
26
−
0
View file @
d6cf517d
...
...
@@ -4,8 +4,10 @@
import
argparse
import
os
import
random
from
collections
import
Counter
from
enum
import
Enum
from
pathlib
import
Path
from
typing
import
List
import
cv2
import
numpy
as
np
...
...
@@ -188,6 +190,26 @@ class HTRDataGenerator:
)
raise
e
def
_validate_transcriptions
(
self
,
page_id
:
str
,
lines
:
List
[
TranscriptionData
]):
if
not
lines
:
return
line_elem_counter
=
Counter
([
trans
.
element_id
for
trans
in
lines
])
most_common
=
line_elem_counter
.
most_common
(
10
)
if
most_common
[
0
][
-
1
]
>
1
:
logger
.
error
(
"
Line elements have multiple transcriptions! Showing top 10:
"
)
logger
.
error
(
f
"
{
most_common
}
"
)
raise
ValueError
(
f
"
Multiple transcriptions:
{
most_common
[
0
]
}
"
)
worker_version_counter
=
Counter
([
trans
.
worker_version_id
for
trans
in
lines
])
if
len
(
worker_version_counter
)
>
1
:
logger
.
warning
(
f
"
There are transcriptions from multiple worker versions on this page:
{
page_id
}
:
"
)
logger
.
warning
(
f
"
Top 10 worker versions:
{
worker_version_counter
.
most_common
(
10
)
}
"
)
def
get_transcriptions
(
self
,
page_id
:
str
,
accepted_zones
):
lines
=
[]
try
:
...
...
@@ -222,10 +244,14 @@ class HTRDataGenerator:
element_id
=
res
[
"
element
"
][
"
id
"
],
polygon
=
polygon
,
text
=
text
,
trans_id
=
res
[
"
id
"
],
worker_version_id
=
res
[
"
worker_version_id
"
],
)
lines
.
append
(
trans_data
)
self
.
_validate_transcriptions
(
page_id
,
lines
)
if
self
.
should_rotate
:
classes_by_elem
=
self
.
get_children_classes
(
page_id
)
...
...
This diff is collapsed.
Click to expand it.
kaldi_data_generator/utils.py
+
25
−
1
View file @
d6cf517d
...
...
@@ -17,10 +17,20 @@ BoundingBox = NamedTuple(
class
TranscriptionData
:
def
__init__
(
self
,
element_id
,
polygon
,
text
,
rotation_class
=
None
):
def
__init__
(
self
,
element_id
,
polygon
,
text
,
trans_id
,
worker_version_id
,
rotation_class
=
None
,
):
self
.
element_id
=
element_id
self
.
polygon
=
np
.
asarray
(
polygon
).
clip
(
0
)
self
.
text
=
text
self
.
trans_id
=
trans_id
self
.
worker_version_id
=
worker_version_id
self
.
rotation_class
=
rotation_class
self
.
rect
=
BoundingBox
.
_make
(
cv2
.
boundingRect
(
self
.
polygon
))
...
...
@@ -37,6 +47,20 @@ class TranscriptionData:
def
__repr__
(
self
):
return
str
(
vars
(
self
))
@classmethod
def
copy_replace_polygon
(
cls
,
trans
:
"
TranscriptionData
"
,
new_polygon
):
"""
Class method to keep the change logic inside the class - less likely to forget to update.
"""
return
TranscriptionData
(
trans
.
element_id
,
new_polygon
,
trans
.
text
,
trans
.
trans_id
,
trans
.
worker_version_id
,
trans
.
rotation_class
,
)
def
write_file
(
file_name
,
content
):
with
open
(
file_name
,
"
w
"
)
as
f
:
...
...
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