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
Merge requests
!153
Remove unused utils functions
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Remove unused utils functions
clean-utils
into
main
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
Mélodie Boillet
requested to merge
clean-utils
into
main
1 year ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
Closes
#87 (closed)
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
dc5405f1
1 commit,
1 year ago
1 file
+
0
−
54
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
dan/utils.py
+
0
−
54
Options
@@ -4,16 +4,6 @@ import numpy as np
import
torch
from
torch.distributions.uniform
import
Uniform
# Layout string to token
SEM_MATCHING_TOKENS_STR
=
{
"
INTITULE
"
:
"
ⓘ
"
,
"
DATE
"
:
"
ⓓ
"
,
"
COTE_SERIE
"
:
"
ⓢ
"
,
"
ANALYSE_COMPL
"
:
"
ⓒ
"
,
"
PRECISIONS_SUR_COTE
"
:
"
ⓟ
"
,
"
COTE_ARTICLE
"
:
"
ⓐ
"
,
}
# Layout begin-token to end-token
SEM_MATCHING_TOKENS
=
{
"
ⓘ
"
:
"
Ⓘ
"
,
"
ⓓ
"
:
"
Ⓓ
"
,
"
ⓢ
"
:
"
Ⓢ
"
,
"
ⓒ
"
:
"
Ⓒ
"
,
"
ⓟ
"
:
"
Ⓟ
"
,
"
ⓐ
"
:
"
Ⓐ
"
}
@@ -57,20 +47,6 @@ def pad_sequences_1D(data, padding_value):
return
padded_data
def
resize_max
(
img
,
max_width
=
None
,
max_height
=
None
):
if
max_width
is
not
None
and
img
.
shape
[
1
]
>
max_width
:
ratio
=
max_width
/
img
.
shape
[
1
]
new_h
=
int
(
np
.
floor
(
ratio
*
img
.
shape
[
0
]))
new_w
=
int
(
np
.
floor
(
ratio
*
img
.
shape
[
1
]))
img
=
cv2
.
resize
(
img
,
(
new_w
,
new_h
),
interpolation
=
cv2
.
INTER_LINEAR
)
if
max_height
is
not
None
and
img
.
shape
[
0
]
>
max_height
:
ratio
=
max_height
/
img
.
shape
[
0
]
new_h
=
int
(
np
.
floor
(
ratio
*
img
.
shape
[
0
]))
new_w
=
int
(
np
.
floor
(
ratio
*
img
.
shape
[
1
]))
img
=
cv2
.
resize
(
img
,
(
new_w
,
new_h
),
interpolation
=
cv2
.
INTER_LINEAR
)
return
img
def
pad_images
(
data
,
padding_value
,
padding_mode
=
"
br
"
):
"""
data: list of numpy array
@@ -157,36 +133,6 @@ def pad_image(
return
output
def
pad_image_width_right
(
img
,
new_width
,
padding_value
):
"""
Pad img to right side with padding value to reach new_width as width
"""
h
,
w
,
c
=
img
.
shape
pad_width
=
max
((
new_width
-
w
),
0
)
pad_right
=
np
.
ones
((
h
,
pad_width
,
c
),
dtype
=
img
.
dtype
)
*
padding_value
img
=
np
.
concatenate
([
img
,
pad_right
],
axis
=
1
)
return
img
def
pad_image_width_random
(
img
,
new_width
,
padding_value
,
max_pad_left_ratio
=
1
):
"""
Randomly pad img to left and right sides with padding value to reach new_width as width
"""
h
,
w
,
c
=
img
.
shape
pad_width
=
max
((
new_width
-
w
),
0
)
max_pad_left
=
int
(
max_pad_left_ratio
*
pad_width
)
pad_left
=
(
randint
(
0
,
min
(
pad_width
,
max_pad_left
))
if
pad_width
!=
0
and
max_pad_left
>
0
else
0
)
pad_right
=
pad_width
-
pad_left
pad_left
=
np
.
ones
((
h
,
pad_left
,
c
),
dtype
=
img
.
dtype
)
*
padding_value
pad_right
=
np
.
ones
((
h
,
pad_right
,
c
),
dtype
=
img
.
dtype
)
*
padding_value
img
=
np
.
concatenate
([
pad_left
,
img
,
pad_right
],
axis
=
1
)
return
img
def
read_image
(
filename
,
scale
=
1.0
):
"""
Read image and rescale it
Loading