Hi everyone,
I’ve trained a model using CNN like this:
model = nn.Sequential(
nn.Conv2d(in_channels=3,out_channels=16,kernel_size=5,padding_mode = 'zeros'),
nn.Flatten(),
nn.Linear(3701776,256),
nn.ReLU(),
nn.Dropout(0.2),
nn.Linear(256, 128),
nn.ReLU(),
nn.Dropout(0.2),
nn.Linear(128, 64),
nn.ReLU(),
nn.Dropout(0.2),
nn.Linear(64, 5),
nn.LogSoftmax(dim = 1)
)
I can train the model just fine calculating loss / accuracy like this:
with torch.no_grad():
# Set the model to evaluation mode
model.eval()
# Validation pass
for images, labels in test_dataloader:
log_ps = model(images)
test_loss += criterion(log_ps, labels)
ps = torch.exp(log_ps)
top_p, top_class = ps.topk(1, dim = 1)
equals = top_class == labels.view(*top_class.shape)
accuracy += torch.mean(equals.type(torch.FloatTensor))
But I don’t know how to test samples, since when I try to call
ps = torch.exp(model(img))
I get an error:
mat1 and mat2 shapes cannot be multiplied (16x231361 and 3701776x256)
Probably since I’m not passing in batches, but I’m not sure how to fix this. Any help would be greatly appreciated