Right, you can check the type of the object with type(imagepre) rather than trying to get the type attribute. But since the error message shows the object source location we know it is a PIL image. You can convert that to a tensor via to_tensor which it looks like you have already done.