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
ddfbbfc0
Commit
ddfbbfc0
authored
1 year ago
by
Yoann Schneider
Browse files
Options
Downloads
Plain Diff
Merge branch 'ignore-invalid-objects' into 'main'
Ignore invalid objects during inference Closes
#247
See merge request
!337
parents
2f61d377
6f00921d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!337
Ignore invalid objects during inference
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dan/ocr/predict/attention.py
+10
-2
10 additions, 2 deletions
dan/ocr/predict/attention.py
with
10 additions
and
2 deletions
dan/ocr/predict/attention.py
+
10
−
2
View file @
ddfbbfc0
...
...
@@ -253,6 +253,8 @@ def get_predicted_polygons_with_confidence(
size
=
(
width
,
height
),
)
start_index
+=
len
(
text_piece
)
+
offset
if
not
polygon
:
continue
polygon
[
"
text
"
]
=
text_piece
polygon
[
"
text_confidence
"
]
=
confidence
polygons
.
append
(
polygon
)
...
...
@@ -362,7 +364,7 @@ def get_polygon(
weights
:
np
.
ndarray
,
size
:
Tuple
[
int
,
int
]
|
None
=
None
,
max_object_height
:
int
=
50
,
)
->
Tuple
[
dict
,
np
.
ndarray
]:
)
->
Tuple
[
dict
,
np
.
ndarray
|
None
]:
"""
Gets polygon associated with element of current text_piece, indexed by offset
:param text: Text piece selected with offset after splitting DAN prediction
...
...
@@ -382,6 +384,8 @@ def get_polygon(
if
max_object_height
else
get_best_contour
(
coverage_vector
,
bin_mask
)
)
if
not
coord
or
confidence
is
None
:
return
{},
None
# Format for JSON
polygon
=
{
...
...
@@ -400,7 +404,7 @@ def get_best_contour(coverage_vector, bin_mask):
contours
,
_
=
cv2
.
findContours
(
bin_mask
,
cv2
.
RETR_EXTERNAL
,
cv2
.
CHAIN_APPROX_SIMPLE
)
if
not
contours
:
return
{}
,
None
return
[]
,
None
# Select best contour
metrics
=
[
compute_contour_metrics
(
coverage_vector
,
cnt
)
for
cnt
in
contours
]
...
...
@@ -417,6 +421,10 @@ def get_grid_search_contour(coverage_vector, bin_mask, height=50):
"""
# Limit search area based on attention values
roi
=
np
.
argwhere
(
bin_mask
==
255
)
if
not
np
.
any
(
roi
):
return
[],
None
y_min
,
y_max
=
roi
[:,
0
].
min
(),
roi
[:,
0
].
max
()
# Limit bounding box shape
...
...
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