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
d805aeae
Unverified
Commit
d805aeae
authored
Feb 15, 2023
by
vfdev
Committed by
GitHub
Feb 15, 2023
Browse files
Fixed issues in elastic transform (#7257)
Co-authored-by:
Nicolas Hug
<
contact@nicolas-hug.com
>
parent
3080082d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
0 deletions
+17
-0
torchvision/prototype/transforms/functional/_geometry.py
torchvision/prototype/transforms/functional/_geometry.py
+17
-0
No files found.
torchvision/prototype/transforms/functional/_geometry.py
View file @
d805aeae
...
@@ -1538,10 +1538,21 @@ def elastic_image_tensor(
...
@@ -1538,10 +1538,21 @@ def elastic_image_tensor(
device
=
image
.
device
device
=
image
.
device
dtype
=
image
.
dtype
if
torch
.
is_floating_point
(
image
)
else
torch
.
float32
dtype
=
image
.
dtype
if
torch
.
is_floating_point
(
image
)
else
torch
.
float32
# Patch: elastic transform should support (cpu,f16) input
is_cpu_half
=
device
.
type
==
"cpu"
and
dtype
==
torch
.
float16
if
is_cpu_half
:
image
=
image
.
to
(
torch
.
float32
)
dtype
=
torch
.
float32
# We are aware that if input image dtype is uint8 and displacement is float64 then
# We are aware that if input image dtype is uint8 and displacement is float64 then
# displacement will be casted to float32 and all computations will be done with float32
# displacement will be casted to float32 and all computations will be done with float32
# We can fix this later if needed
# We can fix this later if needed
expected_shape
=
(
1
,)
+
shape
[
-
2
:]
+
(
2
,)
if
expected_shape
!=
displacement
.
shape
:
raise
ValueError
(
f
"Argument displacement shape should be
{
expected_shape
}
, but given
{
displacement
.
shape
}
"
)
if
ndim
>
4
:
if
ndim
>
4
:
image
=
image
.
reshape
((
-
1
,)
+
shape
[
-
3
:])
image
=
image
.
reshape
((
-
1
,)
+
shape
[
-
3
:])
needs_unsquash
=
True
needs_unsquash
=
True
...
@@ -1561,6 +1572,9 @@ def elastic_image_tensor(
...
@@ -1561,6 +1572,9 @@ def elastic_image_tensor(
if
needs_unsquash
:
if
needs_unsquash
:
output
=
output
.
reshape
(
shape
)
output
=
output
.
reshape
(
shape
)
if
is_cpu_half
:
output
=
output
.
to
(
torch
.
float16
)
return
output
return
output
...
@@ -1676,6 +1690,9 @@ def elastic(
...
@@ -1676,6 +1690,9 @@ def elastic(
if
not
torch
.
jit
.
is_scripting
():
if
not
torch
.
jit
.
is_scripting
():
_log_api_usage_once
(
elastic
)
_log_api_usage_once
(
elastic
)
if
not
isinstance
(
displacement
,
torch
.
Tensor
):
raise
TypeError
(
"Argument displacement should be a Tensor"
)
if
torch
.
jit
.
is_scripting
()
or
is_simple_tensor
(
inpt
):
if
torch
.
jit
.
is_scripting
()
or
is_simple_tensor
(
inpt
):
return
elastic_image_tensor
(
inpt
,
displacement
,
interpolation
=
interpolation
,
fill
=
fill
)
return
elastic_image_tensor
(
inpt
,
displacement
,
interpolation
=
interpolation
,
fill
=
fill
)
elif
isinstance
(
inpt
,
datapoints
.
_datapoint
.
Datapoint
):
elif
isinstance
(
inpt
,
datapoints
.
_datapoint
.
Datapoint
):
...
...
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