How to predict Images from DataLoader_Test?

Hey, I made an Image Classifier and now I want my model to predict and classify the images of DataLoader_Test. Here is my code -

from google.colab import drive
data = "/content/drive/My Drive/FT-BD"

# choose the training and test datasets
train_data = datasets.ImageFolder(data+"/train", transform=transform_train)
test_data = datasets.ImageFolder(data+"/val", transform = transform_test)
#n_classes = test_data.shape[1]
n_classes = len(test_data.classes)

batch_size = 16

dataloader_train =, batch_size, shuffle=True, num_workers=2)
dataloader_test =, batch_size, num_workers=2)

images, labels = next(iter(dataloader_train))

single_loaded_img = images[0]
single_loaded_img =
single_loaded_img = single_loaded_img[None, None]
single_loaded_img = single_loaded_img.type('torch.FloatTensor') # instead of DoubleTensor

out_predict = model(single_loaded_img)

Result : RuntimeError: Expected 4-dimensional input for 4-dimensional weight 16 3 3 3, but got 5-dimensional input of size [1, 1, 3, 224, 224] instead

In the middle, there is my model, which is a CNN Classifier. I have tried many solutions, but none of them worked for me? How to load those Images from the dataloader_test? (In the val folder in google drive, there are two folders/classes, where the images are located.)

This line of code

unsqueezes the tensor twice, which will most likely create the issue.
Remove one None and rerun your code.

Hi, I very much appreciate your help and it is solved.
Now I want to upload a image from my PC and try to check the image is in which class?
So, for that I have to upload the image and convert it to a tensor, right? then I have to put it through the model and Predict. right?