Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
ba64d65b
Unverified
Commit
ba64d65b
authored
Mar 14, 2024
by
Thien Tran
Committed by
GitHub
Mar 13, 2024
Browse files
Fast rotation for right angles (#8295)
Co-authored-by:
Thien Tran
<
thien.tran@parallelchain.io
>
parent
c7bcfada
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
0 deletions
+26
-0
test/test_transforms_v2.py
test/test_transforms_v2.py
+11
-0
torchvision/transforms/v2/functional/_geometry.py
torchvision/transforms/v2/functional/_geometry.py
+15
-0
No files found.
test/test_transforms_v2.py
View file @
ba64d65b
...
@@ -1782,6 +1782,17 @@ class TestRotate:
...
@@ -1782,6 +1782,17 @@ class TestRotate:
with
pytest
.
raises
(
TypeError
,
match
=
"Got inappropriate fill arg"
):
with
pytest
.
raises
(
TypeError
,
match
=
"Got inappropriate fill arg"
):
transforms
.
RandomAffine
(
degrees
=
0
,
fill
=
"fill"
)
transforms
.
RandomAffine
(
degrees
=
0
,
fill
=
"fill"
)
@
pytest
.
mark
.
parametrize
(
"size"
,
[(
11
,
17
),
(
16
,
16
)])
@
pytest
.
mark
.
parametrize
(
"angle"
,
[
0
,
90
,
180
,
270
])
@
pytest
.
mark
.
parametrize
(
"expand"
,
[
False
,
True
])
def
test_functional_image_fast_path_correctness
(
self
,
size
,
angle
,
expand
):
image
=
make_image
(
size
,
dtype
=
torch
.
uint8
,
device
=
"cpu"
)
actual
=
F
.
rotate
(
image
,
angle
=
angle
,
expand
=
expand
)
expected
=
F
.
to_image
(
F
.
rotate
(
F
.
to_pil_image
(
image
),
angle
=
angle
,
expand
=
expand
))
torch
.
testing
.
assert_close
(
actual
,
expected
)
class
TestContainerTransforms
:
class
TestContainerTransforms
:
class
BuiltinTransform
(
transforms
.
Transform
):
class
BuiltinTransform
(
transforms
.
Transform
):
...
...
torchvision/transforms/v2/functional/_geometry.py
View file @
ba64d65b
...
@@ -997,6 +997,21 @@ def rotate_image(
...
@@ -997,6 +997,21 @@ def rotate_image(
center
:
Optional
[
List
[
float
]]
=
None
,
center
:
Optional
[
List
[
float
]]
=
None
,
fill
:
_FillTypeJIT
=
None
,
fill
:
_FillTypeJIT
=
None
,
)
->
torch
.
Tensor
:
)
->
torch
.
Tensor
:
angle
=
angle
%
360
# shift angle to [0, 360) range
# fast path: transpose without affine transform
if
center
is
None
:
if
angle
==
0
:
return
image
.
clone
()
if
angle
==
180
:
return
torch
.
rot90
(
image
,
k
=
2
,
dims
=
(
-
2
,
-
1
))
if
expand
or
image
.
shape
[
-
1
]
==
image
.
shape
[
-
2
]:
if
angle
==
90
:
return
torch
.
rot90
(
image
,
k
=
1
,
dims
=
(
-
2
,
-
1
))
if
angle
==
270
:
return
torch
.
rot90
(
image
,
k
=
3
,
dims
=
(
-
2
,
-
1
))
interpolation
=
_check_interpolation
(
interpolation
)
interpolation
=
_check_interpolation
(
interpolation
)
input_height
,
input_width
=
image
.
shape
[
-
2
:]
input_height
,
input_width
=
image
.
shape
[
-
2
:]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment