thanks  it ran without any error.but
I want to learn the kernels given like this

or similar pattern like this

but after optimising i am getting like this.

here is my loss function
def loss(self,x,y):
    x=x.view(x.size(0),-1)
    y=y.view(y.size(0),-1).float()
    sobelx=self.sobelx.weight.squeeze().squeeze()
    sobely=self.sobely.weight.squeeze().squeeze()
    loss_mse=nn.MSELoss()(x,y)
    loss_constrain=torch.matmul(sobelx,sobely.transpose(0,1)).trace()
    w=.8
    total_loss=(1-w)*loss_mse + w*loss_constrain**2
    return total_loss

i want to know  how i can learn my desired filters?