Hello dear programmers,

I am still a beginner in Pytorch. I have found the following function from a repository. I thought that it is aimed to estimate some evaluation metrics such as recall, precision and F-score. However, when I used it in my training model, it gave me some weird values such as a recall of 6.5, precision of 0.08 and F-score of 0.085
def val(model,train_loader):
model.train(False)

overlap,Y_area,X_area,recall,precision = [],[],[],[],[]

for i, data in enumerate(train_loader):

    x, y_true = data

    if y_true.max()>0:

        

        if torch.cuda.is_available():

            x, y_true = x.cuda(), y_true.cuda()

        output = model(x)

        if output.max() > 0.5:

            overlap.append(torch.sum(torch.round(output).mul(y_true)).item())

            Y_area.append(torch.sum(y_true).item())

            X_area.append(torch.sum(torch.round(output)).item())

            recall.append(overlap[-1]/Y_area[-1])

            precision.append(overlap[-1]/X_area[-1])

print(np.mean(overlap),np.mean(Y_area),np.mean(X_area),np.mean(recall),np.mean(precision))

model.train(True)

return np.mean(recall)*np.mean(precision)/(np.mean(recall)+np.mean(precision)+0.00001)

Please, could anyone help with an explanation of this function? I would be very grateful if you could also tell me how to adjust it properly.
Thank you very much for your time and guidance