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
ffd5a567
Unverified
Commit
ffd5a567
authored
Nov 09, 2022
by
Vasilis Vryniotis
Committed by
GitHub
Nov 09, 2022
Browse files
[prototype] Speed up `autocontrast_image_tensor` (#6935)
* Performance optimization for autocontrast * Fixing tests
parent
10d47a66
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
6 deletions
+14
-6
test/test_prototype_transforms_consistency.py
test/test_prototype_transforms_consistency.py
+2
-0
torchvision/prototype/transforms/functional/_color.py
torchvision/prototype/transforms/functional/_color.py
+12
-6
No files found.
test/test_prototype_transforms_consistency.py
View file @
ffd5a567
...
@@ -251,6 +251,8 @@ CONSISTENCY_CONFIGS = [
...
@@ -251,6 +251,8 @@ CONSISTENCY_CONFIGS = [
ArgsKwargs
(
p
=
0
),
ArgsKwargs
(
p
=
0
),
ArgsKwargs
(
p
=
1
),
ArgsKwargs
(
p
=
1
),
],
],
# Use default tolerances of `torch.testing.assert_close`
closeness_kwargs
=
dict
(
rtol
=
None
,
atol
=
None
),
),
),
ConsistencyConfig
(
ConsistencyConfig
(
prototype_transforms
.
RandomAdjustSharpness
,
prototype_transforms
.
RandomAdjustSharpness
,
...
...
torchvision/prototype/transforms/functional/_color.py
View file @
ffd5a567
...
@@ -377,17 +377,23 @@ def autocontrast_image_tensor(image: torch.Tensor) -> torch.Tensor:
...
@@ -377,17 +377,23 @@ def autocontrast_image_tensor(image: torch.Tensor) -> torch.Tensor:
return
image
return
image
bound
=
_FT
.
_max_value
(
image
.
dtype
)
bound
=
_FT
.
_max_value
(
image
.
dtype
)
dtype
=
image
.
dtype
if
torch
.
is_floating_point
(
image
)
else
torch
.
float32
fp
=
image
.
is_floating_point
()
float_image
=
image
if
fp
else
image
.
to
(
torch
.
float32
)
minimum
=
image
.
amin
(
dim
=
(
-
2
,
-
1
),
keepdim
=
True
)
.
to
(
dtype
)
minimum
=
float_
image
.
amin
(
dim
=
(
-
2
,
-
1
),
keepdim
=
True
)
maximum
=
image
.
amax
(
dim
=
(
-
2
,
-
1
),
keepdim
=
True
)
.
to
(
dtype
)
maximum
=
float_
image
.
amax
(
dim
=
(
-
2
,
-
1
),
keepdim
=
True
)
scale
=
bound
/
(
maximum
-
minimum
)
eq_idxs
=
maximum
==
minimum
eq_idxs
=
maximum
==
minimum
inv_scale
=
maximum
.
sub_
(
minimum
).
div_
(
bound
)
minimum
[
eq_idxs
]
=
0.0
minimum
[
eq_idxs
]
=
0.0
scale
[
eq_idxs
]
=
1.0
inv_scale
[
eq_idxs
]
=
1.0
if
fp
:
diff
=
float_image
.
sub
(
minimum
)
else
:
diff
=
float_image
.
sub_
(
minimum
)
return
(
image
-
minimum
).
mul_
(
scale
).
clamp_
(
0
,
bound
).
to
(
image
.
dtype
)
return
diff
.
div_
(
inv_
scale
).
clamp_
(
0
,
bound
).
to
(
image
.
dtype
)
autocontrast_image_pil
=
_FP
.
autocontrast
autocontrast_image_pil
=
_FP
.
autocontrast
...
...
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