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
619e8822
Commit
619e8822
authored
1 year ago
by
Mélodie
Browse files
Options
Downloads
Patches
Plain Diff
Fix padding to bottom-right
parent
66fc27c0
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/utils.py
+12
-16
12 additions, 16 deletions
dan/utils.py
with
12 additions
and
16 deletions
dan/utils.py
+
12
−
16
View file @
619e8822
...
...
@@ -24,27 +24,23 @@ def pad_sequences_1D(data, padding_value):
return
padded_data
def
pad_images
(
data
):
def
pad_images
(
images
):
"""
Pad the images so that they are
in
the
middle
of the large padded image
(tb-lr mode)
.
:param
data
: List of
numpy array
s.
:return padded_
data
: A tensor containing all the padded images.
Pad the images so that they are
at
the
top left
of the large padded image.
:param
images
: List of
images as torch tensor
s.
:return padded_
images
: A tensor containing all the padded images.
"""
longest_x
=
max
([
x
.
shape
[
0
]
for
x
in
data
])
longest_y
=
max
([
x
.
shape
[
1
]
for
x
in
data
])
padded_data
=
np
.
zeros
((
len
(
data
),
longest_x
,
longest_y
,
data
[
0
].
shape
[
2
]))
for
index
,
image
in
enumerate
(
data
):
delta_x
=
longest_x
-
image
.
shape
[
0
]
delta_y
=
longest_y
-
image
.
shape
[
1
]
top
,
bottom
=
delta_x
//
2
,
delta_x
-
(
delta_x
//
2
)
left
,
right
=
delta_y
//
2
,
delta_y
-
(
delta_y
//
2
)
padded_data
[
longest_x
=
max
([
x
.
shape
[
0
]
for
x
in
images
])
longest_y
=
max
([
x
.
shape
[
1
]
for
x
in
images
])
padded_images
=
np
.
zeros
((
len
(
images
),
longest_x
,
longest_y
,
images
[
0
].
shape
[
2
]))
for
index
,
image
in
enumerate
(
images
):
padded_images
[
index
,
top
:
padded_data
.
shape
[
1
]
-
bottom
,
left
:
padded_data
.
shape
[
2
]
-
right
,
0
:
image
.
shape
[
0
]
,
0
:
image
.
shape
[
1
]
,
:,
]
=
image
return
padded_
data
return
padded_
images
def
read_image
(
filename
,
scale
=
1.0
):
...
...
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