UserWarning when using SaveModelCallback()

Hello, everyone.

I have a very simple learner created in the following way:

learn = cnn_learner(dls=all_data,arch=resnet18, metrics=[accuracy, mcc, auroc]).to_fp16()

Where all_data is an ImageDataLoaders, mcc is an instance of MatthewsCorrCoef() and auroc an instance of RocAucBinary() (just some metrics). When i use the learn.fine_tune() method, i pass the callback SaveModelCallback() (and some others) in the following way:

learn.fine_tune(2,
base_lr=1e-2,
cbs=[SaveModelCallback(monitor=‘matthews_corrcoef’, comp=np.greater, fname=‘resnet18_3’, with_opt=False, reset_on_fit=True),
EarlyStoppingCallback(monitor=‘matthews_corrcoef’, comp=np.greater, min_delta=0.01, patience=3),
ShowGraphCallback()])

When i do so, the training goes normally, but i keep getting this warning after every epoch:

C:\Users\chris\anaconda3\envs\fastai_env\lib\site-packages\fastai\learner.py:54: UserWarning: Saved filed doesn’t contain an optimizer state.
elif with_opt: warn(“Saved filed doesn’t contain an optimizer state.”)

I know that it is the SaveModelCallback() since the warning disappears once i remove it.
Since it’s just a warning, i’m not exactly sure if i’m doing something wrong here. Can anyone help me? Thanks!!

Looks to be a bug. Specifically here:

I’ll put a PR in and fix this now

2 Likes

Thank you, @muellerzr!

When this PR gets merged the problem will be fixed

Wound up being two-fold, you couldn’t do learn.load() without the optimizer and have it not raise a warning at you (in case anyone has tried to)

1 Like