suraj.pt:

r = torch.randn(5).requires_grad_(True) # ~ model.weight
print("r", r)

a = (r > .5).float().requires_grad_(True) # ~ y_pred
print ("a", a)

b = a.abs().mean()*(torch.sign(a)) # ~ loss
print ("b", b)

b.retain_grad()
b.sum().backward()

print ("a.grad", a.grad)
print ("b.grad", b.grad)

print("r.grad", r.grad) # None, because a is not continuous



So, what will be the way you can train a network on a F Score? I s it possible?