Torchvision Normalize "inplace" parameter missing

Both the documentation and the source code show that torch vision.transforms.functional.normalize has an inplace parameter allowing for the passed tensor to not be duplicated.

However, testing this out, I receive the following errors:

TypeError: normalize() takes 3 positional arguments but 4 were given


TypeError: normalize() got an unexpected keyword argument 'inplace'

Here’s the example code which does not work:

import torchvision.transforms.functional as tf
from PIL import Image

# Load image
img = tf.to_tensor(tf.resize([1]), (img_size, img_size)))
# Normalize image
tf.normalize(img, [c.mean() for c in img], [c.std() for c in img], inplace=True)

The source code is easy enough to duplicate, but I’m just wondering if I’m doing something wrong, or this is an issue with the documentation!

Edit: It appears that even with inplace as false, normalize performs the operation in place! This is at odds with what the documentation states. I’m hesitant to use this function and rely on it continuing to be in place, as the documentation states otherwise.


I have tried to add inplace=True parameter to TF.normalize in my custom dataset, it works.
So I think you could check your Pytorch version or others.

Best regrads.

My version is torch-1.0.1.post2 as installed via pip3. Is this not the most recent version?

The latest torchvision version (0.2.1) doesn’t seem to have the inplace parameter either on my machine:

In [1]: import torchvision

In [2]: torchvision.__version__
Out[2]: '0.2.1'

In [3]: torchvision.functional.normalize?
Object `torchvision.functional.normalize` not found.

In [4]: torchvision.transforms.functional.normalize?
Signature: torchvision.transforms.functional.normalize(tensor, mean, std)
Normalize a tensor image with mean and standard deviation.

See ``Normalize`` for more details.

    tensor (Tensor): Tensor image of size (C, H, W) to be normalized.
    mean (sequence): Sequence of means for each channel.
    std (sequence): Sequence of standard deviations for each channely.

    Tensor: Normalized Tensor image.
File:      ~/miniconda3/lib/python3.6/site-packages/torchvision/transforms/
Type:      function

EDIT: I checked that for both the GPU and CPU versions on two separate machines.