and what’s wrong with my code please, It works fine with older Pytorch versions but it raises this error with Pytorch 1.9
The code
import numpy as np
import torch
from torchvision import transforms as tf
from PIL import ImageFilter
def get_ap_transforms(cfg):
transforms = [ToPILImage()]
if cfg.cj:
transforms.append(ColorJitter(brightness=cfg.cj_bri,
contrast=cfg.cj_con,
saturation=cfg.cj_sat,
hue=cfg.cj_hue))
if cfg.gblur:
transforms.append(RandomGaussianBlur(0.5, 3))
transforms.append(ToTensor())
if cfg.gamma:
transforms.append(RandomGamma(min_gamma=0.7, max_gamma=1.5, clip_image=True))
return tf.Compose(transforms)
# from https://github.com/visinf/irr/blob/master/datasets/transforms.py
class ToPILImage(tf.ToPILImage):
def __call__(self, imgs):
return [super(ToPILImage, self).__call__(im) for im in imgs]
class ColorJitter(tf.ColorJitter):
def __call__(self, imgs):
transform = self.get_params(self.brightness, self.contrast, self.saturation, self.hue)
return [transform(im) for im in imgs]
the error
return [transform(im) for im in imgs]
TypeError: 'tuple' object is not callable
ColorJitter.get_params returns the order of operations as well as the parameters for each transformation, which you would then have to use in the same manner as in the forward method of the original implementation (i.e. via the functional API).
UserWarning: An output with one or more elements was resized since it had shape [638976, 2], which does not match the required output shape [1277952, 2].This behavior is deprecated, and in a future PyTorch release outputs will not be resized unless they have zero elements. You can explicitly reuse an out tensor t by resizing it, inplace, to zero elements with t.resize_(0). (Triggered internally at /opt/conda/conda-bld/pytorch_1623448265233/work/aten/src/ATen/native/Resize.cpp:23.)
torch.index_select(v_flat, dim=0, index=self._i00.view(-1), out=self._v00)
Could you post an executable code snippet for the new warning, i.e. tensors using random values in the right shapes, so that we could have a look, please?