The first solution gave me the same dimensions as before, also I had to use a different code like so :
image=torch.as_tensor(np.array(image).astype('float'))

when I use the code you posted like so :
from PIL import Image 
  
# open method used to open different extension image file 
im = Image.open(r"cat.jpg")  
image_new = torch.from_numpy(im)

it gives me an error :
TypeError: expected np.ndarray (got JpegImageFile)

So the first solution doesn’t work.
The second solution I got this error when I did permute
AttributeError: 'numpy.ndarray' object has no attribute 'permute'


The code was like so :
image = cv2.imread('cat.jpg',1)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) #transfrom image from BGR to RGB
image = image.permute(2, 0, 1)