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
drive.mount('/content/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)
print(n_classes)
batch_size = 16
dataloader_train = torch.utils.data.DataLoader(train_data, batch_size, shuffle=True, num_workers=2)
dataloader_test = torch.utils.data.DataLoader(test_data, batch_size, num_workers=2)
images, labels = next(iter(dataloader_train))
imshow_numpy(images[2].numpy())
print(images.shape)
single_loaded_img = images[0]
single_loaded_img = single_loaded_img.to(device)
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.)