Thanks, i forgot it but this time code does not give any result( waited for  long time). I still couldn’t understand how should nn.MSELoss() works for multichannel output and does my function deal with it correctly.
    def custom(self, pred, truth):     
        loss = 0
        for j in range(1,255):
            for i in range(1,255):
                loss += (truth[:,:, i, j] - pred[:,:, i, j])**2
        return loss.mean()