I was working on ESRGAN implementation and while running the code, the following error occured:-
RuntimeError: number of dims don’t match in permute
The code is given below:- `import torch
from torchvision import transforms
from PIL import Image
from esrgan_model import ESRGAN
print(“imports done”)
#load the pretrained ESRGAN model
model = ESRGAN()
print(‘model imported’)
#define the image preprocessing steps
transform = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
])
print(“preprocessing steps defined”)
#load the image
img = Image.open(“example.jpg”)
print(“loading the image”)
#preprocess the image
img = transform(img).unsqueeze(0)
print(‘Preprocessing the image…’)
#run the image through the model
output = model(img)
print(‘Running the image through the model…’)
#save the output image
print(output.shape)
output = output.squeeze()
print(output.shape)
output = output.permute(1, 2, 0)
output = (output * 0.5) + 0.5
output = transforms.ToPILImage()(output)
output.save(“output.jpg”)
`
The shape before and after squeeze is
torch.Size([1, 1, 28, 28])
torch.Size([28, 28])
If I change the dims, it gives the following error:-
IndexError: Dimension out of range (expected to be in range of [-2, 1],
How can i resolve this error?