Custom Metric Creation Error in fastai v1.0.61: on_batch_end() missing 2 required positional arguments: 'preds' and 'targs'

Hello everyone!

I have created a databunch using pytorch dataloaders and implemented my own network for forward pass to train an autoencoder. I want to find out several metrics and so I tried to follow the procedure mentioned here.

I haven’t implemented it completely, but look at this code.

class CustMetrics(Callback):
    _order = -20
    def __init__(self, ks = [1, 2, 5, 10, 20], cutoff = len(query)):
        self.ks = ks
        self.cutoff = cutoff
    def on_epoch_begin(self, **kwargs):
        self.embeddings = []
        self.targets    = []
        print("Begun Epoch")

    def on_batch_end(self, preds, targs, **kwargs):
        encodings = preds[2]
    def on_epoch_end(self, last_metrics, **kwargs):
        query_embeds   = self.embeddings[:self.cutoff]
        gallery_embeds = self.embeddings[self.cutoff:]


        return add_metrics(last_metrics)

I just wanted to check if things are working out fine but on fitting my learner I get this error:

FYI, my forward function returns a tuple of 3 items:

Original Image, Reconstructed Image, Encoding of the image

My Dataset class returns

Image, Target class (i.e. a group/cluster to which the image belongs).

Can someone help me to resolve this issue please? Unfortunately, I can’t share the code however I would appreciate if someone looked into this and if you need any more info to solve the problem, let me know.

Warm Regards.