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
2694a5d2
Unverified
Commit
2694a5d2
authored
Jun 14, 2019
by
Francisco Massa
Committed by
GitHub
Jun 14, 2019
Browse files
Fix normalize for different dtype than float32 (#1021)
* Fix normalize for different dtype than float32 * Fix lint
parent
f052c53f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
2 deletions
+12
-2
test/test_transforms.py
test/test_transforms.py
+9
-0
torchvision/transforms/functional.py
torchvision/transforms/functional.py
+3
-2
No files found.
test/test_transforms.py
View file @
2694a5d2
...
...
@@ -809,6 +809,15 @@ class Tester(unittest.TestCase):
# Checking if Normalize can be printed as string
transforms
.
Normalize
(
mean
,
std
).
__repr__
()
def
test_normalize_different_dtype
(
self
):
for
dtype1
in
[
torch
.
float32
,
torch
.
float64
]:
img
=
torch
.
rand
(
3
,
10
,
10
,
dtype
=
dtype1
)
for
dtype2
in
[
torch
.
int64
,
torch
.
float32
,
torch
.
float64
]:
mean
=
torch
.
tensor
([
1
,
2
,
3
],
dtype
=
dtype2
)
std
=
torch
.
tensor
([
1
,
2
,
1
],
dtype
=
dtype2
)
# checks that it doesn't crash
transforms
.
functional
.
normalize
(
img
,
mean
,
std
)
def
test_adjust_brightness
(
self
):
x_shape
=
[
2
,
2
,
3
]
x_data
=
[
0
,
5
,
13
,
54
,
135
,
226
,
37
,
8
,
234
,
90
,
255
,
1
]
...
...
torchvision/transforms/functional.py
View file @
2694a5d2
...
...
@@ -203,8 +203,9 @@ def normalize(tensor, mean, std, inplace=False):
if
not
inplace
:
tensor
=
tensor
.
clone
()
mean
=
torch
.
as_tensor
(
mean
,
dtype
=
torch
.
float32
,
device
=
tensor
.
device
)
std
=
torch
.
as_tensor
(
std
,
dtype
=
torch
.
float32
,
device
=
tensor
.
device
)
dtype
=
tensor
.
dtype
mean
=
torch
.
as_tensor
(
mean
,
dtype
=
dtype
,
device
=
tensor
.
device
)
std
=
torch
.
as_tensor
(
std
,
dtype
=
dtype
,
device
=
tensor
.
device
)
tensor
.
sub_
(
mean
[:,
None
,
None
]).
div_
(
std
[:,
None
,
None
])
return
tensor
...
...
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