Error with transform in pytorch version 1.8


I am trying to use CenterCrop transform in pytorch version 1.8.0

But I am getting the below error. From the error it seems that the line that is causing the error is in transforms/ file “w,h=img.size”. I found that changing this to “w,h=img.size()” solves the error. Is this really the error or its possible I am doing something wrong. Also, I am not sure if it is recommended to change any of the pytorch files.

TypeError: Caught TypeError in DataLoader worker process 0.
Original Traceback (most recent call last):
File “/home/jrstevens/.local/lib/python3.6/site-packages/torch/utils/data/_utils/”, line 202, in _worker_loop
data = fetcher.fetch(index)
File “/home/jrstevens/.local/lib/python3.6/site-packages/torch/utils/data/_utils/”, line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File “/home/jrstevens/.local/lib/python3.6/site-packages/torch/utils/data/_utils/”, line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File “”, line 261, in getitem
transformed_event_repr[bin_idx, pol_idx] = self.transform(event_repr[bin_idx, pol_idx])
File “/home/jrstevens/.local/lib/python3.6/site-packages/torchvision/transforms/”, line 60, in call
img = t(img)
File “/home/jrstevens/.local/lib/python3.6/site-packages/torchvision/transforms/”, line 235, in call
return F.center_crop(img, self.size)
File “/home/jrstevens/.local/lib/python3.6/site-packages/torchvision/transforms/”, line 365, in center_crop
w, h = img.size
TypeError: ‘builtin_function_or_method’ object is not iterable

######### Center crop from pytorch version 1.8.0
def center_crop(img, output_size):
if isinstance(output_size, numbers.Number):
output_size = (int(output_size), int(output_size))
w, h = img.size
th, tw = output_size
i = int(round((h - th) / 2.))
j = int(round((w - tw) / 2.))
return crop(img, i, j, th, tw)


This might be a valid bug but it seems like it may have already been fixed in recent versions of torchvision (e.g., Replace get_image_size/num_channels with get_dimensions (#5487) · pytorch/vision@095437a · GitHub). Could you check if upgrading to a newer version (>= 0.14.1) of torchvision resolves the issue?