SaveModelCallback Error

I’m getting this error when trying to save my best results using the SaveModelCallback.

callbacks = [SaveModelCallback(learn, every='improvement', monitor='valid_loss', name='best')]
/home/h/miniconda3/envs/fastai/lib/python3.7/site-packages/fastai/callbacks/tracker.py:48: UserWarning: <class 'fastai.callbacks.tracker.SaveModelCallback'> conditioned on metric `valid_loss` which is not available. Available metrics are: train_loss, valid_loss, time
  warn(f'{self.__class__} conditioned on metric `{self.monitor}` which is not available. Available metrics are: {", ".join(map(str, self.learn.recorder.names[1:]))}')

So I found a way round this:

  • Create a metric that is just a copy of one fo the losses:
def met(i, t):
    return mse

learn = unet_learner(data, models.resnet50, loss_func=mse, metrics=met)
  • Use the function name to track and record best results in that metric

It seems there is a bug when you try and track valid_loss

cbs = [SaveModelCallback(learn, every='improvement', monitor='smse', name='best')]
learn.fit_one_cycle(50, slice(1e-5, 1e-4), callbacks=cbs)
1 Like

Any idea why this is a problem? I get it on some machines/instances but not others. Seems strange that it only shows up sometime.

Just upgrade fastai. Updating to version ‘1.0.53.post2’ resolved the issue for me