Custom Loss In Pytorch


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

I tried this

def __init__(self):

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.