I use a resnet16 for a binary image classification task with fastai. I use my learner to get predictions on my test set,
test_preds_raw = learn.get_preds(ds_type=DatasetType.Test)
Then I zip these predictions together with the corresponding image filenames,
test_fnames = list(map(lambda path: str(path).split('/')[-1], learn.data.test_ds.items))
unzipped_preds = list(zip(*test_preds_raw))
fnames_and_preds = list(zip(test_fnames, unzipped_preds))
Finally, I filter out entries where the predictions (ie. ‘probabilities’) and class labels do not match.
def is_pred_inconsistent(tpl):
tpl = tpl[1]
return np.argmax(tpl[0]) != tpl[1]
inconsistent_preds = list(filter(is_pred_inconsistent, fnames_and_preds))
Now I get a bunch of entries where the predicted class label and the ‘probabilities’ are inconsistent…
[('01_841_act_l1_n08.jpg', (tensor([0.4679, 0.5321]), tensor(0))),
('01_841_act_l1_k20.jpg', (tensor([0.1810, 0.8190]), tensor(0))),
('05_841_act_l5_m13.jpg', (tensor([0.2760, 0.7240]), tensor(0))),
('02_841_act_l2_i07.jpg', (tensor([0.4829, 0.5171]), tensor(0))),
('05_841_act_l5_h15.jpg', (tensor([0.2376, 0.7624]), tensor(0))),
('05_841_act_l5_f17.jpg', (tensor([0.4292, 0.5708]), tensor(0))),
('05_841_act_l5_c08.jpg', (tensor([0.1060, 0.8940]), tensor(0)))]
Unless I did something stupid in the above snippets, I believe this isn’t supposed to happen. I’m looking for an explanation for this, maybe I misunderstand what learner.get_preds()
is supposed to return…