-
Notifications
You must be signed in to change notification settings - Fork 7.2k
normalise updates #699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
normalise updates #699
Changes from 1 commit
1df9548
85b5f6f
c82baa8
3564432
de2f6d9
a9d6b17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -181,11 +181,11 @@ def to_pil_image(pic, mode=None): | |
| return Image.fromarray(npimg, mode=mode) | ||
|
|
||
|
|
||
| def normalize(tensor, mean, std): | ||
| def normalize(tensor, mean, std, inplace=False): | ||
| """Normalize a tensor image with mean and standard deviation. | ||
|
|
||
| .. note:: | ||
| This transform acts in-place, i.e., it mutates the input tensor. | ||
| This transform acts out of place by default, i.e., it does not mutates the input tensor. | ||
|
|
||
| See :class:`~torchvision.transforms.Normalize` for more details. | ||
|
|
||
|
|
@@ -200,10 +200,18 @@ def normalize(tensor, mean, std): | |
| if not _is_tensor_image(tensor): | ||
| raise TypeError('tensor is not a torch image.') | ||
|
|
||
| # This is faster than using broadcasting, don't change without benchmarking | ||
| for t, m, s in zip(tensor, mean, std): | ||
| t.sub_(m).div_(s) | ||
| return tensor | ||
| if not inplace: | ||
| tensor_clone = tensor.clone() | ||
| # This is faster than using broadcasting, don't change without benchmarking | ||
| for t, m, s in zip(tensor_clone, mean, std): | ||
| t.sub_(m).div_(s) | ||
| return tensor_clone | ||
|
|
||
| else: | ||
| # This is faster than using broadcasting, don't change without benchmarking | ||
| for t, m, s in zip(tensor, mean, std): | ||
|
||
| t.sub_(m).div_(s) | ||
| return tensor | ||
|
|
||
|
|
||
| def resize(img, size, interpolation=Image.BILINEAR): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you just do
?