How to implement custom loss function

Hello,I am using a Unet network and need to write a loss function myself, this loss function needs to involve calculations that convert to numpy.

def my_mse_loss(input, target):
    a =[0].numpy().flatten()
    b =[0].numpy().flatten()
    loss = 0
    for i in range(len(a)):
        x = a[i]-b[i]
        loss += abs(x**2)
    return torch.Tensor(loss) /

Or can you write an example for me?More detailed.

Sorry but why do you need the numpy operation
I think you can just use toroch.nn.MSELoss

Or do I misunderstand this topic?

I want to do other operations, here is just an example

What kind of operations do you need from numpy that are not available in Pytorch?
It would make the implementation easier, if it’s possible to use pure Pytorch.