Following is my code:
from torchvision import datasets, models, transforms
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
import torch
data_transforms = transforms.Compose([
transforms.RandomResizedCrop(256),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])
img = mpimg.imread('dataset/train/cats/cat.1.jpg')
print(type(img))
print(len(img))
# img = img.astype(float)
# img = img.float()
print(img)
img = data_transforms(img)
Error Message:
Traceback (most recent call last):
File "Image_Preprocessing.py", line 47, in <module>
img = data_transforms(img)
File "/home/debayon/anaconda3/envs/ENV2/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 61, in __call__
img = t(img)
File "/home/debayon/anaconda3/envs/ENV2/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 676, in __call__
i, j, h, w = self.get_params(img, self.scale, self.ratio)
File "/home/debayon/anaconda3/envs/ENV2/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 638, in get_params
area = img.size[0] * img.size[1]
TypeError: 'int' object is not subscriptable
I am unable to understand why is that occuring and please tell how can I solve it?
Thank You.