If I instead switch the metrics to use ‘accuracy_multi’ instead of ‘F1ScoreMulti’ everything works fine.
Do I need to do something different when using the Sklearn metrics?
I’d checked out the documentation page, created from the notebook you added the link for, but hadn’t seen it mentioned that an instance was required for the Sklearn derived metrics (although I may well have missed this!)
It does not explicitly state this, the guess was due to your error saying it was the parent object type and not the function itself, as it was trying to grab part of it (I’ve faced this issue quite often to where it’s just a “know” thing)
In general, everything that begins with a capital needs to be instantiated (we are naming functions that needs to be called with a capital too, to help with that).
pred = torch.randint(0,10,(64,))
targ = torch.randint(0,10,(64,))
f1score_ins = F1Score(average="macro")
f1score_ins(pred,targ)
Learn needs a metric function. In this case f1score_ins.
It looks like a function but is actually a class and needs to be
instantiated. F1Score is a class based on the skm_to_fastai
functions which returns a Class object (AccumMetric). AccumMetric
has function __call__ which basically allows you to call the object as a function
So It will be:
f1_score_multi = F1Score(average="macro") ## convert class to functie
learn = cnn_learner(dls,resnet18,metrics=f1_score_multi)
P.S
Depending on your problem you need to choose average or leave it to default binary.