Fastai v2 vision

Note that in v2, metrics are different than in v1, you have to fill the template:

class Metric():
    "Blueprint for defining a metric"
    def reset(self): pass
    def accumulate(self, learn): pass
    @property
    def value(self): raise NotImplementedError

    @property
    def name(self): return class2attr(self, 'Metric')

where reset is like what you to do at on_epoch_begin, accumulate corresponds to on_batch_end and value is like on_epoch_end.

For your specific problem however, there is already a class called AccumMetric that gathers targets and preds then applies any function you like on it. And roc_auc_score from scikit-learn is already wrapped in RocAuc.

2 Likes