Custom Loss In Pytorch

10

I want to implement this loss function to evaluate my network. Can some suggest a way on how to implement this.

I tried this
Cluster_Assignment_Hardening_Loss(torch.nn.Module):

def __init__(self):
    super(Cluster_Assignment_Hardening_Loss,self).__init__()

def forward(self,encode_output, centroids):
    ...........

Can someone suggest some clean way to implement this ?

I am running into errors like
RuntimeError: leaf variable has been moved into the graph interior.

The above math should map nicely into pytorch operations. i.e. you’ll be able to use tensor.norm, tensor.log, and tensor.sum(dim) that should simplify your code.

I’m curious how you’re running into those errors though.