I have recently started using the fast.ai library and really enjoy it thus far!
However, I have come across a problem with MixUp at inference time, where when trying to predict the image label for a sports classification task, the prediction does not get decoded properly. So the code I am trying to run is:
mixup = MixUp() learn_mixup = cnn_learner(dls, resnet18, metrics=error_rate, cbs=[mixup]) learn_mixup.fit_one_cycle(1, 3e-3) learn_mixup.predict(get_image_files(data_dir/'test'))
However, instead of getting an output from
('table_tennis', TensorImage(1), TensorImage([ 2.5575, 0.4804, -1.2981, 2.2679, -1.4216]]))
(when not using MixUp during training) , I receive the following output(s) (for a single image):
("['motogp', 'badminton', 'tennis', 'motogp', 'tennis']", TensorImage([ 2.5575, 0.4804, -1.2981, 2.2679, -1.4216]), TensorImage([ 2.5575, 0.4804, -1.2981, 2.2679, -1.4216]))
I have tracked this problem a bit further and the issue seems to arise in
learner.py:get_preds when the
self.loss_func loses its
decodes function when entering the
with ContextManagers(ctx_mgrs): scope. This does not happen when not using MixUp. As
self.loss_func.decodes becomes a
noop function, we fail to decode the
TensorImage([ 2.5575, 0.4804, -1.2981, 2.2679, -1.4216]) to become a
TensorImage(1) , and instead later on just convert those loss terms individually to categories to get the predictions
['motogp', 'badminton', 'tennis', 'motogp', 'tennis'] for the single image.
I am a bit at a loss what happens inside
with ContextManagers(ctx_mgrs): that makes our
self.loss_func lose its
decodes member function. So I’d appreciate any advice or help
Thanks in advance!