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
526c783d
Verified
Commit
526c783d
authored
1 year ago
by
Yoann Schneider
Browse files
Options
Downloads
Patches
Plain Diff
Add new transformation to resize to FixedSize
parent
721eef7d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!383
Add new transformation to resize to FixedSize
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dan/ocr/transforms.py
+25
-0
25 additions, 0 deletions
dan/ocr/transforms.py
docs/usage/train/config.md
+12
-0
12 additions, 0 deletions
docs/usage/train/config.md
with
37 additions
and
0 deletions
dan/ocr/transforms.py
+
25
−
0
View file @
526c783d
...
...
@@ -44,6 +44,11 @@ class Preprocessing(str, Enum):
Resize the width to a fixed value while keeping the original ratio
"""
FixedResize
=
"
fixed_resize
"
"""
Resize both the width and the height to a fixed value
"""
class
FixedHeightResize
:
"""
...
...
@@ -79,6 +84,19 @@ class FixedWidthResize:
return
round
(
self
.
width
*
aspect_ratio
)
class
FixedResize
:
"""
Resize an image tensor to a fixed width and height
"""
def
__init__
(
self
,
height
:
int
,
width
:
int
)
->
None
:
self
.
height
=
height
self
.
width
=
width
def
__call__
(
self
,
img
:
Tensor
)
->
Tensor
:
return
resize
(
img
,
(
self
.
height
,
self
.
width
),
antialias
=
False
)
class
MaxResize
:
"""
Resize an image tensor if it is bigger than the maximum size
...
...
@@ -179,6 +197,13 @@ def get_preprocessing_transforms(
)
case
Preprocessing
.
FixedWidthResize
:
transforms
.
append
(
FixedWidthResize
(
width
=
preprocessing
[
"
fixed_width
"
]))
case
Preprocessing
.
FixedResize
:
transforms
.
append
(
FixedResize
(
height
=
preprocessing
[
"
fixed_height
"
],
width
=
preprocessing
[
"
fixed_width
"
],
)
)
if
to_pil_image
:
transforms
.
append
(
ToPILImage
())
return
Compose
(
transforms
)
...
...
This diff is collapsed.
Click to expand it.
docs/usage/train/config.md
+
12
−
0
View file @
526c783d
...
...
@@ -169,6 +169,18 @@ Usage:
]
```
-
Resize to a fixed width and a fixed height
```
py
[
{
"
type
"
:
"
fixed_resize
"
,
"
fixed_height
"
:
1900
,
"
fixed_width
"
:
1250
,
}
]
```
-
Resize to a maximum size (only if the image is bigger than the given size)
```
py
...
...
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