Learn.validate gives metrics error unless learn.fit is called?

When deploying or just running my model on inference mode, I use learn.validate(trn_data.train_dl, metrics=[error_rate, m_pre, m_rec, m_f1]), where m_x are custom metrics using the fastai configurable metrics.

I get an error like: AttributeError: ‘Precision’ object has no attribute ‘n_classes’

The only way around this is to train the model using learn.fit before calling learn.validate. Is there a better workaround for this?

1 Like

I’ve found the same issue, and worked out a ugly hack :wink:

learn.fit(0, lr=0.) # hack: init metrics