'Nonetype' object has no attribute 'transpose'

In my dataloader I am providing dataset which is created by using torchdata.Dataset, I am using the following two lines

img = cv2.imread(path_img, 1)       
img = img.transpose(2, 0, 1)

It is working normal for some iteration but then giving error like:

'Nonetype' object has no attribute 'transpose'

I am confused whether it is due to some of the images in the dataset or due to python.
Thanks in advance for help.

Are you sure that all paths are correct??
Try catch the error something like

try:
    img = img.transpose(2, 0, 1)
catch:
    print(path_img)
    

Then manually check the path exists, it should help

1 Like

Thank you for the help. It is due to one image of my dataset. I have replaced it and problem is resolved.