Closed frankfletcher closed 3 years ago
@jph00 I plan on looking into this over the weekend, just fyi
@jph00 here is a minimal reproducer of the exact cause of this issue. It seems as though despite the callback being run_valid
, some aspects of the Callback that can affect input/output are still being called:
from fastai.vision.all import *
set_seed(99, True)
path = untar_data(URLs.PETS)/'images'
dls = ImageDataLoaders.from_name_func(
path, get_image_files(path), valid_pct=0.2,
label_func=lambda x: x[0].isupper(), item_tfms=Resize(224))
learn = cnn_learner(dls, resnet18, cbs=MixUp())
b = dls[1].one_batch()
p = learn.get_preds(dl=[b], with_decoded=True)
x,y,its = dls.show_batch(b, 9, show=False)
b_out = type(b)(b[:dls.n_inp] + (tuple(p[2]) if is_listy(p[2]) else (p[2],)))
learn.cbs = learn.cbs[:-1]
p = learn.get_preds(dl=[b], with_decoded=True)
x,y,its = dls.show_batch(b, 9, show=False)
b_out_a = type(b)(b[:dls.n_inp] + (tuple(p[2]) if is_listy(p[2]) else (p[2],)))
test_eq(b_out, b_out_a)
(also this was present in the old MixUp implementation too, checked that)
Please confirm you have the latest versions of fastai, fastcore, and nbdev prior to reporting a bug (delete one): YES
Describe the bug Using resnet18 along with the MixUp callback to categorize images on the PETS data results in a post-training error. When using
learn.predict()
,pred
is given as a tensor of n category labels with repeats.pred_idx
is a tensor of dimension n number of categories whose contents are floating points. Actually,pred_idx
is a direct copy ofprob
Current Workarounds
To Reproduce As requested by Zach Mueller, I have made a minimal reproducer to debug with available here: https://github.com/cogsci2/Pets-Minimal/blob/main/MinimalPets_debug_mixup.ipynb
Expected behavior No error message is given, kernel execution is not halted.
Error with full stack trace
Place between these lines with triple backticks:
Error when using plot_confusion_matrix():
Error when using predict() (this is from a different model)
Additional context