Fastai v2 - how to use multi label classification metrics

Hello,

I am trying to use the different metrics proposed by Fastai v2 for multi label classification (https://dev.fast.ai/metrics#Multi-label-classification)

The only metric I can use successfully is accuracy_multi

learner = cnn_learner(dls, arch, metrics=[partial(accuracy_multi)])

Unfortunately, all the other metrics do not work.

learner = cnn_learner(dls, arch, metrics=[partial(FBetaMulti)])

will give me the following error when calling fine_tune()

(#5) [0,0.8701863288879395,0.6779627203941345,None,‘00:50’]

TypeError Traceback (most recent call last)
in ()
----> 1 learner.fine_tune(1, 3e-3)
17 frames
/usr/local/lib/python3.6/dist-packages/fastai2/learner.py in accumulate(self, learn)
335 def accumulate(self, learn):
336 print(self.func.name)
–> 337 bs = find_bs(learn.yb)
338 self.total += to_detach(self.func(learn.pred, *learn.yb))*bs
339 self.count += bs
TypeError: unsupported operand type(s) for *: ‘AccumMetric’ and ‘int’

Would you have any idea what I am doing wrong or examples on how to use these metrics properly ?

Thank you.

Hi!

You need to instantiate your metric, i.e. FBetaMulti() in this case.

1 Like

Okay, thank you very much, it works with that.
Have a nice day.

1 Like

For clarification, you need to instantiate metrics classes (those that start with capital letter) before passing to metrics argument.