It seems your code is unable to read image. Can you make sure you are doing it correctly by printing type of image in this line:



 Cerebrus:

image = cv2.imread(img_path)


By they way, if you are not going to do any specific preprocessing using cv2, I think it is better idea to load your images using Pillow which is the default image processing core of PyTorch, then you can remove first transform layer too:



 Cerebrus:

transforms.ToPILImage(),


You can read image by Pillow using this code:
from PIL import Image
image = Image.open(path)