I am trying to view the images that my model misclassified without using tensorboard. So far, I have been unable to just get only the misclassified images. Currently this is what I have ;
incorrect_examples = []
model.eval()
for data,target in val_loader:
if train_on_gpu:
data , target = data.cuda(), target.cuda()
output = model(data)
_, pred = torch.max(output,1)
idxs_mask = (pred == target).view(-1)
incorrect_examples.append(data[idxs_mask].numpy())
display 10 images
fig = plt.figure(figsize=(20, 8))
for idx in np.arange(10):
ax = fig.add_subplot(2, 10/2, idx+1, xticks=[], yticks=[])
#std = np.array([0.229, 0.224, 0.225])
#mean = np.array([0.485, 0.456, 0.406])
img = incorrect_examples[idx][idx]
img = img/2 + 0.5
img = np.clip(img, 0, 1)
imshow(img)
ax.set_title(f"{classes[pred[idx]]}: x%\n (label: {classes[target[idx]]})",
color=(“green” if pred[idx]==target[idx].item() else “red”))
and these just give me a batch of the predicted images and not the misclassified ones. I am new to pytorch so it is possible that I am not doing the right thing. Please help